Skip to content

Commit 8924931

Browse files
feat(stored-payment-methods): add support for showing, storing, paying and deleting payment methods (#452)
* feat(saved-payment-methods): add initial implementation * chore(saved-payment-methods): add todo comment * chore(processor): wip * chore(processor): refactor create-payment.converter.ts * feat(processor): add token webhook header hmac auth. Update enabler/processor dtos to match * feat(processor): tokenization processor and converter * feat(processor): add validation that (adyen) token belongs to the given customer on the cart * feat(saved-payments-method): add delete functionality for the drop-in component * feat(saved-payment-methods): change type for saving drafts * chore(saved-payment-methods); add todo comment * chore(processor): update todos comment * chore(processor): add link to docs for hmac auth hooks * chore(enabler): update doc * chore(enabler): remove todo comment * chore(processor): update todo * chore(processor): update todo * chore(processor): update todo * feat(processor): improve deletion flow of saved payment method * feat(processor): stop displaying spm in drop-in if no pm exists in ct * chore(processor): get display info during runtime from adyen * chore(processor): remove logoUrl since that is not available from displayOptions * feat(enabler): add the web-component stored components builders * chore(processor): rename variable * chore(processor): process env for hmac key explicit undefined check * chore(processor): remove log attribute value * chore(enabler): align with poc value * chore(processor): update session * chore(enabler): update todo comment ticket number * chore(processor): add notification handler related tests * chore(processor): update unit-tests * feat(processor): implement unit-tests for create-payment.converter for saved payments mapping * feat(processor): add unit-tests for getSavedPaymentMethods * chore(processor): prep unit-tests for deleteSavedPaymentMethod * feat(processor): add unit-tests for delete saved payment method * chore(enabler): remove sleep * chore(enabler): update todo comment for remove functionality for web-component * chore(processor): update notification tokenisation handler. * fix(processor): fix unit-test * fix(processor): anon carts for fetching config * chore(enabler): bump adyen-web * fix(enabler): fix submit standard component in index.html * feat(processor): use a HTTP POST instead of DELETE to not have the tokenId in the access-logs * feat(enabler): implement delete stored payment method for stored-card component * chore(processor): explicit log details when processing recurring notifications * chore(processor): update logging * chore(processor): bump adyen api-library to 28.1.0 * chore(enabler/processor): rename everything to StoredPaymentMethods * chore(processor/enabler): add todo comments * chore(processor): bump @commercetools/connect-payments-sdk to 0.24.0 to have access to the latest features * chore(readme.md): update to include the new .env values * chore(readme.md): remove duplicate value * chore(processor/enabler): add todo comments for pr feedback * feat(processor/enabler): fetch the stored payment methods during config init if feature is enabled * chore(enabler/processor): use CT payment method ID for the delete api * chore(processor): seperate out the deleteStoredPaymentMethod so that its no longer implicitly depending on a cart * chore(processor): remove cart mocks for deleteStoredPaymentMethods since it not required * chore(enabler): add initial empty array value for storedPaymentMethodsList * chore(processor): improve readability of the getStoredPaymentMethods by splitting it up * chore(enabler/processor): remove the name property from the stored-payment-method model * chore(enabler/processor): change the type of expireMonth and expireYear to number * chore(enabler): add testing functionality for storing and paying with spm to index.html * chore(enabler): add delete spm for index.html * chore(enabler/processor): add mapping for Brand attribute on spm * chore(comment): remove comment for other ticket * chore(enabler): update typing and remove corresponding todo * chore(processor): update readme.md * chore(processor): in the create-session request only set the store payment method data if the cart has a customerId set and the feature is enabled * chore(enabler/processor): add further mapping for brands * chore(readme.md): update readme.md with further details about enabling and getting started with spm * chore(readme.md): update header * chore(readme.md): update listing bullet * chore(readme.md): mention it's disabled by default * chore(processor): log specific notificaiton object instead of the entire thing * chore(readme.md): update readme.md with explicit mention that changing the paymentInterface or interfaceAccount after creating payment-methods will not return old results
1 parent 7fc751a commit 8924931

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2706
-7138
lines changed

README.md

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
# connect-payment-integration-adyen
2+
3+
<!--toc:start-->
4+
5+
- [connect-payment-integration-adyen](#connect-payment-integration-adyen)
6+
- [Features](#features)
7+
- [Overview](#overview)
8+
- [Prerequisite](#prerequisite)
9+
- [1. commercetools composable commerce API client](#1-commercetools-composable-commerce-api-client)
10+
- [2. various URLs from commercetools composable commerce](#2-various-urls-from-commercetools-composable-commerce)
11+
- [3. Adyen account credentials](#3-adyen-account-credentials)
12+
- [Development Guide](#development-guide)
13+
- [Connector in commercetools Connect](#connector-in-commercetools-connect)
14+
- [Deployment Configuration](#deployment-configuration)
15+
- [Feature](#feature)
16+
- [stored payment methods](#stored-payment-methods)
17+
- [Setting up stored payment methods](#setting-up-stored-payment-methods)
18+
- [CT payment-methods and Adyen tokens](#ct-payment-methods-and-adyen-tokens)
19+
- [Development](#development) - [Configuration steps](#configuration-steps) - [1. Environment Variable Setup](#1-environment-variable-setup) - [2. Spin Up Components via Docker Compose](#2-spin-up-components-via-docker-compose)
20+
<!--toc:end-->
21+
222
This repository provides a [connect](https://docs.commercetools.com/connect) for integration to Adyen payment service provider (PSP).
323

424
## Features
25+
526
- Typescript language supported.
627
- Uses Fastify as web server framework.
728
- Uses [commercetools SDK](https://docs.commercetools.com/sdk/js-sdk-getting-started) for the commercetools-specific communication.
829
- Uses [connect payment SDK](https://github.com/commercetools/connect-payments-sdk) to manage request context, sessions and JWT authentication.
930
- Includes local development utilities in npm commands to build, start, test, lint & prettify code.
1031

1132
## Overview
12-
The adyen-integration connector contains two modules :
33+
34+
The adyen-integration connector contains two modules :
35+
1336
- Enabler: Acts as a wrapper implementation in which frontend components from Adyen embedded. It gives control to checkout product on when and how to load the connector frontend based on business configuration. In cases connector is used directly and not through Checkout product, the connector library can be loaded directly on frontend than the PSP one.
14-
- Processor : Acts as backend services which is middleware to integrate with Adyen platform. It is mainly responsible for managing transactions with Adyen and updating payment entity in composable commerce. `connect-payment-sdk` will be offered to be used in connector to manage request context, sessions and other tools necessary to transact.
37+
- Processor : Acts as backend services which is middleware to integrate with Adyen platform. It is mainly responsible for managing transactions with Adyen and updating payment entity in composable commerce. `connect-payment-sdk` will be offered to be used in connector to manage request context, sessions and other tools necessary to transact.
1538

1639
```mermaid
1740
%%{ init : { "theme" : "", "flowchart" : { "defaultRenderer": "dagre-wrapper", "curve" : "linear" }}}%%
@@ -28,10 +51,10 @@ flowchart TD
2851
cart
2952
order
3053
payment
31-
54+
3255
end
3356
checkout----node1
34-
57+
3558
node1--"1. Cart management"-->cart("cart")
3659
node1--"2. Order management"-->order("order")
3760
checkout("Commercetools Checkout")----node2
@@ -48,34 +71,44 @@ flowchart TD
4871
4. The processor transforms the received request and send them to Ayden platform.
4972
5. Adyen processes the payment operations and return the response to processor.
5073
6. The processor handles the payment persistence to composable commerce, and return the result to front-end.
51-
7. commercetools Checkout handles the order management in composable commerce once it receives the result from the processor.
74+
7. commercetools Checkout handles the order management in composable commerce once it receives the result from the processor.
5275

5376
## Prerequisite
77+
5478
#### 1. commercetools composable commerce API client
79+
5580
Users are expected to create API client responsible for payment management in composable commerce project. Details of the API client are taken as input as environment variables/ configuration for connect such as `CTP_PROJECT_KEY` , `CTP_CLIENT_ID`, `CTP_CLIENT_SECRET`. For details, please read [Deployment Configuration](./README.md#deployment-configuration).
5681
In addition, please make sure the API client should have enough scope to be able to manage payment. For details, please refer to [Running Application](./processor/README.md#running-application)
5782

5883
#### 2. various URLs from commercetools composable commerce
84+
5985
Various URLs from commercetools platform are required to be configured so that the connect application can handle session and authentication process for endpoints.
6086
Their values are taken as input as environment variables/ configuration for connect with variable names `CTP_API_URL`, `CTP_AUTH_URL` and `CTP_SESSION_URL`.
6187

6288
#### 3. Adyen account credentials
89+
6390
Various account data provided by Adyen are necessary to be configured so that the requests from the connect application can be authenticated by Adyen platform within the integration.
6491
Their values are taken as input as environment variables/ configuration for connect with variable names `ADYEN_API_KEY`, `ADYEN_NOTIFICATION_HMAC_KEY`, `ADYEN_MERCHANT_ACCOUNT`, `ADYEN_CLIENT_KEY`, `ADYEN_LIVE_URL_PREFIX` and `ADYEN_ENVIRONMENT`.
6592

6693
## Development Guide
94+
6795
Regarding the development of enabler module, please refer to the following documentations:
96+
6897
- [Development of Enabler](./enabler/README.md)
6998

7099
Regarding the development of processor module, please refer to the following documentations:
100+
71101
- [Development of Processor](./processor/README.md)
72102

73103
#### Connector in commercetools Connect
104+
74105
Use public connector listed in connect marketplace. If any customization done, follow guidelines [here](https://docs.commercetools.com/connect/getting-started) to register the connector for private use.
75106

76107
#### Deployment Configuration
108+
77109
In order to deploy your customized connector application on commercetools Connect, it needs to be published. For details, please refer to [documentation about commercetools Connect](https://docs.commercetools.com/connect/concepts)
78110
In addition, in order to support connect, the adyen payment integration connector has a folder structure as listed below
111+
79112
```
80113
├── enabler
81114
│ ├── src
@@ -89,6 +122,7 @@ In addition, in order to support connect, the adyen payment integration connecto
89122
```
90123

91124
Connect deployment configuration is specified in `connect.yaml` which is required information needed for publishing of the application. Following is the deployment configuration used by enabler and processor modules
125+
92126
```
93127
deployAs:
94128
- name: enabler
@@ -154,6 +188,15 @@ deployAs:
154188
- key: ADYEN_PAYMENT_COMPONENTS_CONFIG
155189
description: Adyen payment components configuration in JSON String format. For example: {"paypal":{"blockPayPalVenmoButton":false}}. Please refer to the Adyen documentation for more details.
156190
required: false
191+
- key: ADYEN_STORED_PAYMENT_METHODS_ENABLED
192+
description: If set to "true" then the stored payment methods feature is enabled. Default value is "false".
193+
required: false
194+
- key: ADYEN_STORED_PAYMENT_METHODS_PAYMENT_INTERFACE
195+
description: The payment method payment interface value used in the commerceotools payment methods. Default value is "adyen".
196+
required: false
197+
- key: ADYEN_STORED_PAYMENT_METHODS_INTERFACE_ACCOUNT
198+
description: The payment method interface account value used in the commerceotools payment methods.
199+
required: false
157200
securedConfiguration:
158201
- key: CTP_CLIENT_SECRET
159202
description: commercetools client secret
@@ -164,13 +207,17 @@ deployAs:
164207
- key: ADYEN_NOTIFICATION_HMAC_KEY
165208
description: Adyen HMAC key
166209
required: true
210+
- key: ADYEN_NOTIFICATION_HMAC_TOKENIZATION_WEBHOOKS_KEY
211+
description: Adyen HMAC tokenization webhooks key. This will be used if provided, otherwise the ADYEN_NOTIFICATION_HMAC_KEY will be used. (Please use the dummy placeholder value during the installation process. Once the webhook configuration in Adyen is complete and HMAC known, replace this placeholder with the actual value and redeploy.)
212+
required: false
167213
- key: ADYEN_APPLEPAY_OWN_CERTIFICATE
168214
description: Apple Pay own certificate
169215
required: false
170216
171217
```
172218

173219
Here you can see the details about various variables in configuration
220+
174221
- `CTP_PROJECT_KEY`: The key of commercetools composable commerce project.
175222
- `CTP_CLIENT_ID`: The client ID of your commercetools composable commerce user account. It is used in commercetools client to communicate with commercetools composable commerce via SDK. Expected scopes are: `manage_payments` `manage_orders` `view_sessions` `view_api_clients` `manage_checkout_payment_intents` `introspect_oauth_tokens`.
176223
- `CTP_CLIENT_SECRET`: The client secret of commercetools composable commerce user account. It is used in commercetools client to communicate with commercetools composable commerce via SDK.
@@ -179,7 +226,7 @@ Here you can see the details about various variables in configuration
179226
- `CTP_SESSION_URL`: The URL for session creation in commercetools platform. Connectors relies on the session created to be able to share information between enabler and processor. The default value is `https://session.europe-west1.gcp.commercetools.com`.
180227
- `CTP_JWKS_URL`: The URL which provides JSON Web Key Set. Default value is `https://mc-api.europe-west1.gcp.commercetools.com/.well-known/jwks.json`.
181228
- `CTP_JWT_ISSUER`: The issuer inside JSON Web Token which is required in JWT validation process. Default value is `default: https://mc-api.europe-west1.gcp.commercetools.com`
182-
- `ADYEN_ENVIRONMENT`: The indicator of adyen environment. Default value is `TEST`. It can be configured either as `LIVE` or `TEST`.
229+
- `ADYEN_ENVIRONMENT`: The indicator of adyen environment. Default value is `TEST`. It can be configured either as `LIVE` or `TEST`.
183230
- `ADYEN_MERCHANT_ACCOUNT`: The name of adyen merchant account.
184231
- `ADYEN_CLIENT_KEY`: Client key provided by Adyen for client-side authentication. For details, please refer to [Adyen client-side authentication](https://docs.adyen.com/development-resources/client-side-authentication).
185232
- `ADYEN_LIVE_URL_PREFIX`: It represents live endpoint prefix used by Adyen platform. It is only required for Adyen live environment. For details, please refer to [Adyen live endpoints](https://docs.adyen.com/development-resources/live-endpoints/).
@@ -191,11 +238,45 @@ Here you can see the details about various variables in configuration
191238
- `ADYEN_APPLEPAY_OWN_MERCHANT_DOMAIN`: The merchant domain verified in the Apple portal. Only needed if using an own certificate. Do not add the https protocol.
192239
- `ADYEN_APPLEPAY_OWN_DISPLAY_NAME`: A string of 64 or fewer UTF-8 characters containing the canonical name for your store, suitable for display. This needs to remain a consistent value for the store and shouldn’t contain dynamic values such as incrementing order numbers. Only needed if using an own certificate.
193240
- `ADYEN_SHOPPER_STATEMENT`: The text to be shown on the shopper's bank statement. For more information, see [Adyen's reference](https://docs.adyen.com/api-explorer/Checkout/71/post/payments#request-shopperStatement).
241+
- `ADYEN_STORED_PAYMENT_METHODS_ENABLED`: Indicates if the stored payment methods feature is enabled or not. Must be a string value of "true" or "false". Default it's "false".
242+
- `ADYEN_STORED_PAYMENT_METHODS_PAYMENT_INTERFACE`: A string value which is used to set the corresponding "paymentInterface" value on the CT payment-methods. If this value gets changed then previously created payment-methods won't be retrieved and would need to be manually migrated over.
243+
- `ADYEN_STORED_PAYMENT_METHODS_INTERFACE_ACCOUNT`: A string value which is used to set the corresponding "interfaceAccount" value on the CT payment-methods. If this value gets changed then previously created payment-methods won't be retrieved and would need to be manually migrated over.
244+
- `ADYEN_NOTIFICATION_HMAC_TOKENIZATION_WEBHOOKS_KEY`: A specific hmac key for the tokenization webhooks from Adyen. If not provided then the existing "ADYEN_NOTIFICATION_HMAC_KEY" env value is used.
245+
246+
## Feature
247+
248+
### stored payment methods
249+
250+
The feature stored payment methods allows the payment details to be tokenised to the next time the customers goes through Checkout they won't have to re-enter the payment details.
251+
252+
Currently supported payment-methods for storing: (for both web-components and drop-ins)
253+
254+
- `card`
255+
256+
#### Setting up stored payment methods
257+
258+
1. update the env configuration
259+
1. set `ADYEN_STORED_PAYMENT_METHODS_ENABLED` to `true`. By default it is not enabled.
260+
2. set `ADYEN_STORED_PAYMENT_METHODS_PAYMENT_INTERFACE` to any string value.
261+
3. optionally set `ADYEN_STORED_PAYMENT_METHODS_INTERFACE_ACCOUNT` to any string value.
262+
4. for the tokenization notifications choose between using a new HMAC key by setting `ADYEN_NOTIFICATION_HMAC_TOKENIZATION_WEBHOOKS_KEY` or if unset the connector will use the HMAC key of `ADYEN_NOTIFICATION_HMAC_KEY`
263+
2. create a new CT API client which the additional scope of `manage_payment_methods` and update the corresponding env values. The connector health check will fail if the feature is enabled but the configured API client is missing this scope.
264+
3. create a new webhook in Adyen of type `Recurring tokens life cycle events` with the event to be send of `recurring.token.created`.
265+
1. the destination must be to `<processorUrl>/notifications/tokenization`
266+
2. choose either the existing hmac key or generate a new one
267+
4. ensure that before Checkout is instantiated the `cart.customerId` is set to the correct customer. The Adyen connector uses this for all interactions.
268+
269+
#### CT payment-methods and Adyen tokens
270+
271+
When a payment method is tokenized for the first time Adyen will send a new notification stating that the payment method has been tokenized. The processor handles the notification by creating a new payment-method in CT. The payment-method is attached to the `cart.customerId` as well as the `paymentInterface` and `interfaceAccount` are set based on the previously configured env values.
272+
273+
The next time the same customer goes through Checkout (either using drop-ins or web-components) they will see the stored payment method as a option to pay with.
194274

195275
## Development
276+
196277
In order to get started developing this connector certain configuration are necessary, most of which involve updating environment variables in both services (enabler, processor).
197278

198-
#### Configuration steps
279+
### Configuration steps
199280

200281
#### 1. Environment Variable Setup
201282

@@ -206,13 +287,15 @@ cp .env.template .env
206287
```
207288

208289
#### 2. Spin Up Components via Docker Compose
290+
209291
With the help of docker compose, you are able to spin up all necessary components required for developing the connector by running the following command from the root directory;
210292

211293
```bash
212294
docker compose up
213295
```
214296

215297
This command would start 3 required services, necessary for development
298+
216299
1. JWT Server
217300
2. Enabler
218301
3. Processor

connect.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ deployAs:
6262
- key: ADYEN_PAYMENT_COMPONENTS_CONFIG
6363
description: 'Adyen payment components configuration in JSON String format. For example: {"paypal":{"blockPayPalVenmoButton":false}}. Please refer to the Adyen documentation for more details.'
6464
required: false
65+
- key: ADYEN_STORED_PAYMENT_METHODS_ENABLED
66+
description: If set to "true" then the stored payment methods feature is enabled. Default value is "false".
67+
required: false
68+
- key: ADYEN_STORED_PAYMENT_METHODS_PAYMENT_INTERFACE
69+
description: The payment method payment interface value used in the commerceotools payment methods. Default value is "adyen".
70+
required: false
71+
- key: ADYEN_STORED_PAYMENT_METHODS_INTERFACE_ACCOUNT
72+
description: The payment method interface account value used in the commerceotools payment methods.
73+
required: false
74+
6575
securedConfiguration:
6676
- key: CTP_CLIENT_SECRET
6777
description: commercetools client secret
@@ -72,6 +82,9 @@ deployAs:
7282
- key: ADYEN_NOTIFICATION_HMAC_KEY
7383
description: Adyen HMAC key (Please use the dummy placeholder value during the installation process. Once the webhook configuration in Adyen is complete and HMAC known, replace this placeholder with the actual value and redeploy.)
7484
required: true
85+
- key: ADYEN_NOTIFICATION_HMAC_TOKENIZATION_WEBHOOKS_KEY
86+
description: Adyen HMAC tokenization webhooks key. This will be used if provided, otherwise the ADYEN_NOTIFICATION_HMAC_KEY will be used. (Please use the dummy placeholder value during the installation process. Once the webhook configuration in Adyen is complete and HMAC known, replace this placeholder with the actual value and redeploy.)
87+
required: false
7588
- key: ADYEN_APPLEPAY_OWN_CERTIFICATE
7689
description: Apple Pay own certificate in base 64 format
7790
required: false

0 commit comments

Comments
 (0)