Skip to content

Commit

Permalink
Merge pull request #121 from Adyen/release/1.0.0
Browse files Browse the repository at this point in the history
Release/1.0.0
  • Loading branch information
amihajlovski authored Feb 26, 2024
2 parents 8da1a5c + 49be7d0 commit eb06855
Show file tree
Hide file tree
Showing 23 changed files with 399 additions and 174 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,30 @@ This integration provides the opportunity to use Adyen as a payment service prov
[Download the NPM package of Adyen integration here](https://www.npmjs.com/package/@adyen/adyen-salesforce-pwa?activeTab=readme)

In this GitHub repo there are two packages:
* `Adyen retail react app`: Reference application how to integrate the Adyen Payments Integration into your PWA application. This reference applicaiton should not be used in production projects.
* `Adyen salesforce pwa`: source code for the Adyen PWA NPM package. This code is published to the [NPM](https://www.npmjs.com/package/@adyen/adyen-salesforce-pwa?activeTab=readm).
* `Adyen-salesforce-pwa`: source code for the Adyen PWA NPM package, that contains the default payments integration. This code is published to the [NPM](https://www.npmjs.com/package/@adyen/adyen-salesforce-pwa?activeTab=readme).
* `Adyen-retail-react-app`: a reference application that can be used for a demo of how to integrate the Adyen Payments Integration (NPM package) into your PWA Retail application. This reference application should not be used in production projects and we do not provide support on this implementaiotn.

## Prerequisites

* [Adyen test account](https://www.adyen.com/signup)
* [API key](https://docs.adyen.com/development-resources/how-to-get-the-api-key)
* [Client key](https://docs.adyen.com/development-resources/client-side-authentication#get-your-client-key)
* See the NPM package [Readme](https://www.npmjs.com/package/@adyen/adyen-salesforce-pwa?activeTab=readme) for installation instructions.

## Support & Maintenance
## Installation and Configuration
* Refer to [Adyen Docs](https://docs.adyen.com/plugins/salesforce-commerce-cloud/composable-storefront) for NPM set-up, installation and Go-Live instructions.
* Refer to [Adyen Docs](https://docs.adyen.com/plugins/salesforce-commerce-cloud/composable-storefront/customization-guide) for customisation instructions.
* Available Payment methods and features can be found on [Adyen Docs](https://docs.adyen.com/plugins/salesforce-commerce-cloud).

The NPM package version is in beta and may not be suitable for production use. We anticipate the General Availability solution to be ready by Q1 2024.
## Support & Maintenance

Please be aware, that the NPM package in Beta and 'Adyen retail react app` are not supported by Adyen Support.
We provide specialized integration support for major versions of the NPM package following the [SFCC B2C Support policy](https://docs.adyen.com/plugins/salesforce-commerce-cloud/#support-levels), along with permanent Adyen support.
Migration from SFRA/SG and Upgrade Guide can be found on [Adyen Docs](https://docs.adyen.com/plugins/salesforce-commerce-cloud/composable-storefront).
For other questions, contact our [support team](https://www.adyen.help).

To request a feature, report a bug, or report a security vulnerability, [create a GitHub issue](https://github.com/Adyen/adyen-salesforce-headless-commerce-pwa/issues/new/choose).
## Upgrade

For other questions, contact our [support team](https://www.adyen.help).
We recommend that you upgrade when we have a major release, such as v**2**.x.x.
You can find the latest version on our [NPM](https://www.npmjs.com/package/@adyen/adyen-salesforce-pwa?activeTab=readme) repository.

## License

Expand Down
4 changes: 3 additions & 1 deletion packages/adyen-retail-react-app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RefArch_ADYEN_WEBHOOK_USER=""
RefArch_ADYEN_WEBHOOK_PASSWORD=""
RefArch_ADYEN_HMAC_KEY=""
RefArch_SYSTEM_INTEGRATOR_NAME=""
RefArch_ADYEN_APPLE_DOMAIN_ASSOCIATION=""

COMMERCE_API_CLIENT_ID=""
COMMERCE_API_ORG_ID=""
Expand All @@ -20,4 +21,5 @@ COMMERCE_API_CLIENT_ID_PRIVATE=""
COMMERCE_API_CLIENT_SECRET=""
SFCC_REALM_ID=""
SFCC_INSTANCE_ID=""
SFCC_OAUTH_SCOPES=""
SFCC_OAUTH_SCOPES=""

2 changes: 1 addition & 1 deletion packages/adyen-retail-react-app/overrides/app/ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const {handler} = runtime.createHandler(options, (app) => {
'*.amazon.com',
'https://www.sandbox.paypal.com/xoplatform/logger/api/logger?disableSetCookie=true'
],
'frame-src': ["'self'", '*.adyen.com', '*.paypal.com'],
'frame-src': ["'self'", '*.adyen.com', '*.paypal.com', '*.google.com'],
/* -----------------Adyen End ------------------------ */
// Do not upgrade insecure requests for local development
'upgrade-insecure-requests': isRemote() ? [] : null
Expand Down
2 changes: 1 addition & 1 deletion packages/adyen-retail-react-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/adyen-retail-react-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adyen-retail-react-app",
"version": "1.0.0-beta.6",
"version": "1.0.0",
"license": "See license in LICENSE",
"engines": {
"node": "^16.0.0 || ^18.0.0",
Expand Down
73 changes: 8 additions & 65 deletions packages/adyen-salesforce-pwa/README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,26 @@
# Adyen Salesforce PWA

This npm package provides the opportunity to use Adyen as a payment service provider when building your Salesforce PWA
application.
This NPM package enables you to go live fast with payments with Adyen as a payment service provider when building your Salesforce PWA
Retail application.

---
**NOTE**

This version is in beta and may not be suitable for production use.
We anticipate the general availability solution to be ready by Q1 2024.

Please be aware that the beta version is not supported by Adyen until general availability, will not be providing
technical support for this specific beta release.

We encourage users to explore the package, provide feedback, and report any issues via
our [GitHub repository](https://github.com/Adyen/adyen-salesforce-headless-commerce-pwa.git).

---
To request a feature, report a bug, or report a security
vulnerability, [create a GitHub issue](https://github.com/Adyen/adyen-salesforce-headless-commerce-pwa/issues/new/choose).

## Dependencies & Requirements

Adyen Payments Composable Storefront Integration for B2C Commerce depends on:

1. PWA v3.1.1
2. [Adyen Web v5.51.0](https://www.npmjs.com/package/@adyen/adyen-web)
3. [Adyen API Library for Node.js v14.3.0](https://www.npmjs.com/package/@adyen/api-library)
3. [Adyen API Library for Node.js v16.0.1](https://www.npmjs.com/package/@adyen/api-library)
4. Node v18 or later
5. NPM v9 or later
6. Salesforce Managed Runtime

## Installation

1. Install the npm package using the following command
```shell
npm install @adyen/adyen-salesforce-pwa
```
2. Import the Adyen endpoints function in the `ssr.js` file:
```ecmascript 6
import {registerAdyenEndpoints} from '@adyen/adyen-salesforce-pwa/dist/ssr/index.js'
```
3. Include it as part of the server handler callback in the `ssr.js` file before last `app.get()` handler:
```ecmascript 6
const {handler} = runtime.createHandler(options, (app) => {
// ...

registerAdyenEndpoints(app, runtime)

app.get('*', runtime.render)
})
```
4. Include Adyen checkout pages in the `routes.jsx` of your `retail-react-app`.
Check [routes.jsx](../adyen-retail-react-app/overrides/app/routes.jsx) file for reference.

5. In your `retail-react-app` you would need to create a .env file. Check
the [example file](../adyen-retail-react-app/.env.example) in our reference application.

6. Import `countrylist` in `constants.js` of your `retail-react-app` and export it as `SHIPPING_COUNTRY_CODES`:

```ecmascript 6
import {countryList} from '@adyen/adyen-salesforce-pwa'
export const SHIPPING_COUNTRY_CODES = countryList
```
7. To run the app locally with env variables execute the following command:
```shell
npm run start:env
```
8. To push your env variables to the MRT environment execute the following command:
```shell
npm run upload-env
```

9. To see which env variables are present in the MRT environment execute the following command:
```shell
npm run get-env
```
For set-up, installation, and Go-Live instructions, refer to [Adyen Docs](https://docs.adyen.com/plugins/salesforce-commerce-cloud/composable-storefront).
Available payment methods and features can be found on [Adyen Docs](https://docs.adyen.com/plugins/salesforce-commerce-cloud).

## Prerequisites

Expand All @@ -84,11 +30,8 @@ Adyen Payments Composable Storefront Integration for B2C Commerce depends on:

## Support

To request a feature, report a bug, or report a security
vulnerability, [create a GitHub issue](https://github.com/Adyen/adyen-salesforce-headless-commerce-pwa/issues/new/choose).

For other questions, contact our [support team](https://www.adyen.help).

## License

This repository is available under the [MIT license](LICENSE).
This repository is available under the [MIT license](LICENSE).
1 change: 1 addition & 0 deletions packages/adyen-salesforce-pwa/__mocks__/mockEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ process.env.COMMERCE_API_CLIENT_SECRET = 'mock_COMMERCE_API_CLIENT_SECRET'
process.env.SFCC_REALM_ID = 'mock_SFCC_REALM_ID'
process.env.SFCC_INSTANCE_ID = 'mock_SFCC_INSTANCE_ID'
process.env.SFCC_OAUTH_SCOPES = 'sfcc.orders sfcc.orders.rw sfcc.customerlists.rw'
process.env.ADYEN_APPLE_DOMAIN_ASSOCIATION = 'test'
8 changes: 4 additions & 4 deletions packages/adyen-salesforce-pwa/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ module.exports = {
moduleFileExtensions: ['js', 'jsx', 'mjs', 'cjs'],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
branches: 85,
functions: 85,
lines: 85,
statements: 85
}
},
collectCoverageFrom: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Logger from './logger'
import {getAdyenConfigForCurrentSite} from '../../utils/getAdyenConfigForCurrentSite.mjs'

function appleDomainAssociation(req, res, next) {
try {
const adyenConfig = getAdyenConfigForCurrentSite()
res.setHeader('content-type', 'text/plain')
Logger.info('AppleDomainAssociation')
res.send(`${adyenConfig.appleDomainAssociation}\n`)
} catch (err) {
return next(err)
}
}

export {appleDomainAssociation}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export class OrderApiClient {
scope: `SALESFORCE_COMMERCE_API:${process.env.SFCC_REALM_ID}_${process.env.SFCC_INSTANCE_ID} ${process.env.SFCC_OAUTH_SCOPES}`
})
})

if (!token.ok) {
const error = await token.text()
throw new Error(`${token.status} ${token.statusText}`, {
cause: error
})
}
return token.json()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {appleDomainAssociation} from '../apple-domain-association'

describe('appleDomainAssociation Controller', () => {
let req, res, next, consoleInfoSpy

beforeEach(() => {
req = {}
res = {
send: jest.fn(),
setHeader: jest.fn()
}
next = jest.fn()
consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(() => {})
})
it('update order when success notification is received', async () => {
await appleDomainAssociation(req, res, next)
expect(res.send).toHaveBeenCalledWith('test\n')
expect(res.setHeader).toHaveBeenCalledWith('content-type', 'text/plain')
expect(consoleInfoSpy).toHaveBeenCalledTimes(1)
expect(consoleInfoSpy.mock.calls[0][0]).toContain('AppleDomainAssociation')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jest.mock('../checkout-config', () => {
})
describe('payment methods controller', () => {
let req, res, next, consoleInfoSpy, consoleErrorSpy
let blockedPaymentMethods = ['giftcard', 'wechatpayMiniProgram', 'wechatpayQR', 'wechatpaySDK']

beforeEach(() => {
req = {
Expand Down Expand Up @@ -99,7 +100,7 @@ describe('payment methods controller', () => {
expect(mockPaymentMethods).toHaveBeenCalledWith(
{
amount: {currency: 'USD', value: 10000},
blockedPaymentMethods: ['giftcard'],
blockedPaymentMethods,
countryCode: 'US',
merchantAccount: 'mock_ADYEN_MERCHANT_ACCOUNT',
shopperLocale: 'en-US',
Expand Down Expand Up @@ -153,7 +154,7 @@ describe('payment methods controller', () => {
expect(mockPaymentMethods).toHaveBeenCalledWith(
{
amount: {currency: 'USD', value: 10000},
blockedPaymentMethods: ['giftcard'],
blockedPaymentMethods,
countryCode: 'US',
merchantAccount: 'mock_ADYEN_MERCHANT_ACCOUNT',
shopperLocale: 'en-US',
Expand Down Expand Up @@ -223,7 +224,7 @@ describe('payment methods controller', () => {
await PaymentMethodsController(req, res, next)
expect(mockPaymentMethods).toHaveBeenCalledWith(
{
blockedPaymentMethods: ['giftcard'],
blockedPaymentMethods,
countryCode: 'US',
merchantAccount: 'mock_ADYEN_MERCHANT_ACCOUNT',
shopperLocale: 'en-US',
Expand Down
9 changes: 9 additions & 0 deletions packages/adyen-salesforce-pwa/lib/api/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {authenticate, parseNotification, validateHmac} from '../controllers/webh
import {authorizationWebhookHandler} from '../controllers/authorization-webhook-handler'
import {createErrorResponse} from '../../utils/createErrorResponse.mjs'
import Logger from '../controllers/logger'
import {appleDomainAssociation} from '../controllers/apple-domain-association'

function SuccessHandler(req, res) {
Logger.info('Success')
Expand Down Expand Up @@ -37,6 +38,10 @@ function registerAdyenEndpoints(app, runtime, overrides) {
SuccessHandler
]

const appleDomainAssociationHandler = overrides?.appleDomainAssociation || [
appleDomainAssociation
]

app.get(
'*/checkout/redirect',
query('redirectResult').optional().escape(),
Expand All @@ -53,6 +58,10 @@ function registerAdyenEndpoints(app, runtime, overrides) {
app.post('/api/adyen/payments/details', ...paymentsDetailsHandler)
app.post('/api/adyen/payments', ...paymentsHandler)
app.post('/api/adyen/webhook', ...webhookHandler)
app.get(
'/.well-known/apple-developer-merchantid-domain-association',
...appleDomainAssociationHandler
)
app.use(overrides?.ErrorHandler || ErrorHandler)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {registerAdyenEndpoints, SuccessHandler, ErrorHandler} from '../index'
import {ErrorHandler, registerAdyenEndpoints, SuccessHandler} from '../index'
import Logger from '../../controllers/logger'

jest.mock('../../controllers/logger', () => ({
Expand Down Expand Up @@ -30,7 +30,7 @@ describe('Adyen Endpoints', () => {
const overrides = {}

registerAdyenEndpoints(app, runtime, overrides)
expect(app.get).toHaveBeenCalledTimes(4)
expect(app.get).toHaveBeenCalledTimes(5)
expect(app.post).toHaveBeenCalledTimes(3)
expect(app.use).toHaveBeenCalledTimes(1)
})
Expand Down
Loading

0 comments on commit eb06855

Please sign in to comment.