Adyen integration in The Good Store
Adyen is a payment provider that allows merchants to accept payments from customers worldwide. The Good Store comes with an out-of-the-box API-only Adyen integration.
The Good Store also comes with a checkout
Frontend Component that is integrated with the Adyen API. Unlike the implementation of the Adyen integration described here, which uses Adyen's pre-built UI components, The Good Store uses its own UI component to maintain complete control over the checkout UX/UI design.
The Good Store's Adyen integration includes 3-D Secure 2.0 authentication. The Good Store does not include any solution for storing and processing raw credit card data in the frontend. For more information on storing and processing credit card data according to PCI DSS, see the Adyen documentation
commercetools also offers an open-source integration between commercetools Composable Commerce and Adyen, which can be used with or without The Good Store's Adyen integration. The integration between commercetools Composable Commerce and Adyen can be used to implement notifications, manage refunds, and handle payment updates.
Prerequisites
Get started
To start using the Adyen integration, follow these steps:
Open the
project.yml
file at the following path<root>/thegoodstore_home/config/project.yml
.Add your Adyen credentials in the
configuration
section as follows.Add your Adyen credentialsymladyen:baseUrl: https://checkout-test.adyen.com/v70 # Remove -test on production environmentsmerchantAccount: <your-merchant-account-name>apiKey: <your-api-key>password: <your-api-key-password> # Not requiredclientKey: <your-client-key> # Not requiredhmacKey: <your-hmac-key>Set up a webhook that will be called to update the OrderState in commercetools Composable Commerce after successful payment. Set up the webhook by entering the following configuration values.
- In the Server configuration field, enter the URL of the endpoint that will receive the webhook notifications. This should be
<your-host>/frontastic/action/adyen/notify
. - In the HMAC Key field, either enter the key that you added in the
project.yml
file or generate a new key and update yourproject.yml
file accordingly.
Once you have created the webhook, Adyen will send a test notification to your webhook endpoint to ensure that it is properly configured. You can then use the Adyen API to test your webhook by triggering payment events and verifying that your server or application receives the corresponding webhook notifications.
- In the Server configuration field, enter the URL of the endpoint that will receive the webhook notifications. This should be
Create a
cardSummary
Custom Field for the commercetools Composable CommercePayment
type as follows. When the webhook is triggered upon successful payment, the last four digits of the credit card are stored in thecardSummary
field.curl --location --request POST '<commercetools-host>/<project-key>/types' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer <access-token>' \--data-raw '{"key" : "paymenttype","name" : {"en" : "Payment"},"description" : {"en" : "Payment custom type."},"resourceTypeIds" : [ "payment" ],"fieldDefinitions" : [ {"name" : "cardSummary","label" : {"en" : "Card Summary"},"required" : false,"type" : {"name" : "String"},"inputHint" : "SingleLine"} ]}'Configure your environments to be PCI DSS compliant, as required by Adyen.
- On the client side, in the
.env
file of your commercetools Frontend project, set your Adyen client key as the value of theNEXT_PUBLIC_ADYEN_CLIENT_KEY
variable. If you are working locally, set the value of theNEXT_PUBLIC_ADYEN_CLIENT_KEY
variable only in the.env.local
file. - On production, set your Adyen client key as the value of the environment variable on Netlify or any other provider.
For test environments, you can contact Adyen support to allow payments without being PCI DSS compliant.
- On the client side, in the
Payment logic
In the index.ts
file at the following path components/commercetools-ui/organisms/checkout/provider/payment/types/index.ts
, you can find the PaymentProvider
interface. The Adyen payment provider at the following path components/commercetools-ui/organisms/checkout/provider/payment/adyen
implements the interface.
All payment logic lives in the payment provider. Hence, all of Adyen's payment logic is under components/commercetools-ui/organisms/checkout/provider/payment/adyen
, which is a Context Provider that provides values and callbacks used by the checkout
component. The checkout
component is responsible for the interaction between the user and Adyen integration.
If you need to add a payment provider other than Adyen, add it at the following path components/commercetools-ui/organisms/checkout/provider/payment
. The provider should be a Context Provider that provides a value of type PaymentProvider
.