Adyen Gift Cards Integration Demo
This repository includes examples of PCI-compliant UI integrations for online payments with Adyen. Within this demo app, you'll find a simplified version of an e-commerce website, complete with commented code to highlight key features and concepts of Adyen's API. Check out the underlying code to see how you can integrate Adyen to give your shoppers the option to pay with their preferred payment methods, all in a seamless checkout experience.
This demo leverages Adyen's API Library for Node.js (GitHub | Docs).
Run integration on Gitpod
-
Open your Adyen Test Account and create a set of API keys.
-
Go to Gitpod Environmental Variables and set the following variables:
ADYEN_API_KEY
,ADYEN_CLIENT_KEY
andADYEN_MERCHANT_ACCOUNT
with a scope of*/*
. -
To allow the Adyen Drop-In and Components to load, add
https://*.gitpod.io
as allowed origin by going to yourADYEN_MERCHANT_ACCOUNT
in the Customer Area:Developers
→API credentials
→ Find yourws_user
→Client settings
→Add Allowed origins
.
Warning You should only allow wild card (*) domains in the test environment. In a live environment, you should specify the exact URL of the application.
This demo provides a simple webhook integration at /api/webhooks/notifications
. For it to work, you need to provide a way for Adyen's servers to reach your running application on Gitpod and add a standard webhook in the Customer Area.
-
To receive notifications asynchronously, add a webhook:
- In the Customer Area go to
Developers
→Webhooks
and add a newStandard notification webhook
- Define username and password (Basic Authentication) to protect your endpoint - Basic authentication only guarantees that the notification was sent by Adyen, not that it wasn't modified during transmission
- Generate the HMAC Key and set the
ADYEN_HMAC_KEY
in your Gitpod Environment Variables - This key is used to verify whether the HMAC signature that is included in the notification, was sent by Adyen and not modified during transmission - For the URL, enter
https://gitpod.io
for now - We will need to update this webhook URL in step 7 - Make sure the webhook is Enabled to send notifications
- In the Customer Area go to
-
In the Customer Area, go to
Developers
→Additional Settings
→ UnderAcquirer
enablePayment Account Reference
to receive the Payment Account Reference. -
Click the button below to launch the application in Gitpod.
- Update your webhook in the Customer Area with the public url that is generated by Gitpod
- In the Customer Area, go to
Developers
→Webhooks
→ Select yourWebhook
that is created in step 4 →Server Configuration
- Update the URL of your application/endpoint (e.g.
https://8080-myorg-myrepo-y8ad7pso0w5.ws-eu75.gitpod.io/api/webhooks/notifications/
) - Hit
Apply
→Save changes
and Gitpod should be able to receive notifications
- In the Customer Area, go to
Note When exiting Gitpod a new URL is generated, make sure to update the Webhook URL in the Customer Area as described in the final step. You can find more information about webhooks in this detailed blog post.
You will need Node.js 20+ to run this application locally.
- Clone this repository
git clone https://github.com/adyen-examples/adyen-node-online-payments.git
-
Open your Adyen Test Account and create a set of API keys.
-
To allow the Adyen Drop-In and Components to load, add
https://localhost:5001
as allowed origin by going to yourADYEN_MERCHANT_ACCOUNT
in the Customer Area:Developers
→API credentials
→ Find yourws_user
→Client settings
→Add Allowed origins
.
Warning You should only allow wild card (*) domains in the test environment. In a live environment, you should specify the exact URL of the application.
This demo provides a simple webhook integration at /api/webhooks/notifications
. For it to work, you need to provide a way for Adyen's servers to reach your running application and add a standard webhook in the Customer Area.
To expose this endpoint you can use a tunneling software (i.e. ngrok).
- Expose your localhost with tunneling software (i.e. ngrok).
- Add
https://*.ngrok.io
to your allowed origins
- Add
If you use a tunneling service like ngrok, the webhook URL will be the generated URL (i.e. https://c991-80-113-16-28.ngrok.io/api/webhooks/notifications/
).
$ ngrok http 8080
Session Status online
Account ############
Version #########
Region United States (us)
Forwarding http://c991-80-113-16-28.ngrok.io -> http://localhost:8080
Forwarding https://c991-80-113-16-28.ngrok.io -> http://localhost:8080
-
To receive notifications asynchronously, add a webhook:
- In the Customer Area go to
Developers
→Webhooks
and add a newStandard notification webhook
- Define username and password (Basic Authentication) to protect your endpoint - Basic authentication only guarantees that the notification was sent by Adyen, not that it wasn't modified during transmission
- Generate the HMAC Key - This key is used to verify whether the HMAC signature that is included in the notification, was sent by Adyen and not modified during transmission
- See script below that allows you to easily set your environmental variables
- For the URL, enter
https://ngrok.io
for now - We will need to update this webhook URL in step 10 - Make sure the webhook is Enabled to send notifications
- In the Customer Area go to
-
Set the following environment variables in your terminal environment:
ADYEN_API_KEY
,ADYEN_CLIENT_KEY
,ADYEN_MERCHANT_ACCOUNT
andADYEN_HMAC_KEY
. Note that some IDEs will have to be restarted for environmental variables to be injected properly.
export ADYEN_API_KEY=yourAdyenApiKey
export ADYEN_MERCHANT_ACCOUNT=yourAdyenMerchantAccount
export ADYEN_CLIENT_KEY=yourAdyenClientKey
export ADYEN_HMAC_KEY=yourAdyenHmacKey
On Windows CMD you can use this command instead.
set ADYEN_API_KEY=yourAdyenApiKey
set ADYEN_MERCHANT_ACCOUNT=yourAdyenMerchantAccount
set ADYEN_CLIENT_KEY=yourAdyenClientKey
set ADYEN_HMAC_KEY=yourAdyenHmacKey
-
In the Customer Area, go to
Developers
→Additional Settings
→ UnderAcquirer
enablePayment Account Reference
to receive the Payment Account Reference. -
Start the application and visit localhost.
cd giftcard-example
npm install
nom run dev
- Update your webhook in your Customer Area with the public url that is generated.
- In the Customer Area go to
Developers
→Webhooks
→ Select yourWebhook
that is created in step 6 →Server Configuration
- Update the URL of your application/endpoint (e.g.
https://c991-80-113-16-28.ngrok.io/api/webhooks/notifications/
orhttps://xd1r2txt-5001.euw.devtunnels.ms
) - Hit
Apply
→Save changes
and Gitpod should be able to receive notifications
Note When exiting ngrok or Visual Studio a new URL is generated, make sure to update the Webhook URL in the Customer Area as described in the final step. You can find more information about webhooks in this detailed blog post.
Before testing, please make sure to add the gift card payment method(s) to your Adyen Account.
To try out this application with test card numbers, visit Gift card numbers and Test card numbers. We recommend saving some test cards in your browser so you can test your integration faster in the future.
-
Visit the main page, pick the Drop-in or Gift Card component integration, follow the instructions by entering the gift card number, followed by finalizing the payment.
-
Visit the Customer Area
Developers
→API logs
to view your logs.