Implementation examples Java Spring
.NET
Node.js
To tokenize your shoppers payment details, you need to include additional fields when you make a /payments request. If your request is successful, you receive a webhook containing the token that can be used subsequent payments. You can use the token when making a payment request to offer returning customers a faster checkout experience. You can also use tokens to charge your customers for subscription, or automatic top-up payments.
If you are implementing 3D Secure for PSD2 SCA compliance, use our self-service guide to find out about the PSD2 SCA compliance rules that apply to your business when tokenizing shopper payment details.
Set parameters to flag transactions
When you make a /payments request to create a token or pay with a token, you must include:
Parameter | Description |
---|---|
recurringProcessingModel | When you first create a token, indicates what type of recurring payment the token is intended for. For subsequent payments, indicates the type of recurring payment. Possible values:
|
shopperInteraction | Indicates the sales channel through which the shopper gives their card details, for online transactions, this is Ecommerce. For subsequent payments, indicates whether the shopper is a returning customer (ContAuth). |
shopperReference | Your unique reference for the shopper. Minimum length: three characters. Note that the value is case-sensitive. Do not include personally identifiable information (PII), such as name or email address. |
storePaymentMethod | When you first create a token, set to true to store the shopper's payment details. For subsequent payments, this parameter is not required. |
When creating a token that you want to use for more than one type of recurring payment (for example, initially Subscription but in future also CardOnFile), use the recurringProcessingModel
that is most appropriate at the time of token creation. In subsequent transactions you can then specify the applicable recurringProcessingModel
.
Enable the webhook
When you store a shopper's payment details, you receive a RECURRING_CONTRACT webhook. You must enable it on the Standard webhook page and the Webhooks settings page.
The webhook includes the token that you use for payments with the shopper's stored payment details:
Field | Description |
---|---|
originalReference |
The pspReference for the payment made to store the shopper's payment details. |
additionalData.recurring.recurringDetailReference |
The token for the stored payment details. You must contact our Support Team to enable this parameter in your response. |
additionalData.recurring.shopperReference |
Your unique shopper reference. Use this to associate the shopper with the token. |
pspReference |
The token for the stored payment details. This is the same as recurringDetailReference . |
{ "live" : "false", "notificationItems" : [ { "NotificationRequestItem" : { "additionalData" : { "recurring.shopperReference" : "YOUR_SHOPPER_REFERENCE", "recurring.recurringDetailReference" : "M5N7TQ4TG5PFWR50", "hmacSignature" : "YOUR_HMAC_SIGNATURE", "shopperReference" : "YOUR_SHOPPER_REFERENCE", "checkoutSessionId" : "******************" }, "amount" : { "currency" : "US", "value" : 0 }, "eventCode" : "RECURRING_CONTRACT", "eventDate" : "2023-06-20T16:09:48+02:00", "merchantAccountCode" : "YOUR_MERCHANT_ACCOUNT", "merchantReference" : "YOUR_PAYMENT_REFERENCE", "originalReference" : "DZ4DPSHB4WD2WN82", "paymentMethod" : "mc", "pspReferenceThis is a duplicate of recurringDetailReference." : "M5N7TQ4TG5PFWR50", "reasonWhen success = false, this field includes an explanation for the refusal." : "", "success" : "true" } } ] }
Store the token with the shopper reference to associate the token with the shopper.
Create a token
Select the tab that fits your business model and follow the integration steps:
We strongly recommend that you ask explicit permission from the shopper if you intend to make future recurring payments. Being transparent about the payment schedule and the charged amount reduces the risk of chargebacks.
Let your shoppers set up subscriptions with you. Subscriptions are a series of transactions with fixed or variable amounts, charged at a fixed time interval.
SCA is required for the initial payment.
PSD2 regulations may have additional requirements for processing recurring transactions.
Save payment details for subscriptions
From your server, make a POST /payments request including:
Parameter | Description |
---|---|
paymentMethod | Contains the shopper's payment details. |
shopperReference | Your unique identifier for the shopper. Minimum length: three characters. Note that the value is case-sensitive. Do not include personally identifiable information (PII), such as name or email address. |
shopperInteraction | Ecommerce |
recurringProcessingModel | Subscription |
storePaymentMethod Checkout API v49 or later |
true |
amount | Contains the value to pay. You can set amount.value to 0 to validate the payment details with a zero-auth transaction before processing payments. |
curl https://checkout-test.adyen.com/checkout/v70/payments \ -H 'x-api-key: ADYEN_API_KEY' \ -H 'content-type: application/json' \ -d '{ "amount":{ "value":0, "currency":"USD" }, "paymentMethod":{ "type":"scheme", "number":"4111111111111111", "expiryMonth":"03", "expiryYear":"2030", "cvc":"737", "holderName":"John Smith" }, "reference":"YOUR_ORDER_REFERENCE", "shopperInteraction": "Ecommerce", "recurringProcessingModel": "Subscription", "storePaymentMethod": "true", "merchantAccount":"YOUR_MERCHANT_ACCOUNT", "shopperReference":"YOUR_SHOPPER_REFERENCE", "returnUrl":"https://your-company.com/..." }'
The token is created after a successful payment authorization to ensure that the payment details the shopper provided are linked to an active, chargeable account.
Result codes
The outcome of the tokenization request depends on the resultCode
you get.
Result code | Description | Action |
---|---|---|
Authorised | The payment was successful, and the payment details were tokenized. | Save the token from the RECURRING_CONTRACT webhook. |
Pending | The payment is pending, and the payment details haven not been tokenized yet. | Wait for the RECURRING_CONTRACT webhook that you get when the payment reaches the Authorised status. |
Refused | The payment was refused, and the payment details were not tokenized. | Make another payment request to try tokenizing again. |
When you get the token, store it with your shopper reference so that you and the shopper can use it for recurring payments.
Authorised API response
For some API responses with resultCode
: Authorised, the token is included. You can enable the feature to get the token in the API response, when available, in the additionalData.recurring.recurringDetailReference
. For example:
{ "additionalData": { "recurring.recurringDetailReference": "M5N7TQ4TG5PFWR50", "recurring.shopperReference":"YOUR_SHOPPER_REFERENCE" }, "pspReference": "DZ4DPSHB4WD2WN82", "resultCode": "Authorised", "amount": { "currency": "USD", "value": 0 }, "merchantReference": "YOUR_ORDER_REFERENCE" }
Because the API response does not always include the token, we recommend always getting it from the RECURRING_CONTRACT webhook.
Pay with a token
Select the type of recurring payment to make:
Make a one-off payment
-
Present the shopper's saved payment method in your payment form.
If you are using one of our client-side solutions (Drop-in, Components, or Pay by Link), you can present a shopper's stored cards in the payment form. For more information on how to do this, refer to the Cards documentation for Drop-in (Web, iOS, Android), the Card Component documentation (Web, iOS, Android), or our Pay by Link documentation.
If you are using an API-only integration, you will need to build the UI for this yourself.
-
From your server, make a POST /payments request including:
Parameter Required Description paymentMethod.storedPaymentMethodId
Checkout API v49 or laterThe token for the shopper's stored payment details. This is the recurringDetailReference
from the response when you created the token.shopperReference Your unique identifier for the shopper. Must be the same one you included with the request to create the token. shopperInteraction ContAuth recurringProcessingModel CardOnFile paymentMethod.encryptedSecurityCode
The encrypted card verification code (CVC).
If you do not want to require the CVC for one-off payments using stored details, you must contact our Support Team to activate theskipCvcForOneClick
in your Customer Area.Do not store the CVC. Storing it violates PCI compliance rules.paymentMethod.brand
Only required for co-badged cards; optional for single branded cards. The secondary brand of the card.
If you use 3D Secure for PSD2 SCA compliance, some issuing banks require SCA for ContAuth with CardOnFile transactions. See the PSD2 SCA compliance guide for more information.
curl https://checkout-test.adyen.com/checkout/v70/payments \ -H 'x-api-key: ADYEN_API_KEY' \ -H 'content-type: application/json' \ -d '{ "amount":{ "value":2000, "currency":"USD" }, "paymentMethod":{ "type":"scheme", "storedPaymentMethodIdPreviously known as recurringDetailReference":"M5N7TQ4TG5PFWR50", "encryptedSecurityCode": "adyenjs_0_1_18$MT6ppy0FAMVMLH..." }, "reference":"YOUR_ORDER_REFERENCE", "shopperInteraction": "ContAuth", "recurringProcessingModel": "CardOnFile", "merchantAccount":"YOUR_MERCHANT_ACCOUNT", "shopperReference":"YOUR_SHOPPER_REFERENCE", "returnUrl":"https://your-company.com/..." }'
If the payment is successful, you receive resultCode
: Authorised.
{ "pspReference": "VK9DRSLLRCQ2WN82", "resultCode": "Authorised" }
Test and go live
To receive the recurringDetailReference
in the /payments response when it is available:
- In your Customer Area, go to Developers > Additional data.
- Select Recurring details.
- Select Save.
In your test environment:
- Test that you get the RECURRING_CONTRACT webhook.
- Store a test token.
- Make a test payment with the token.
Before going live:
Enable the RECURRING_CONTRACT webhook in your live Customer Area.