Search

Are you looking for test card numbers?

Would you like to contact support?

Payment-method icon

Card Component

Add card payments to an existing Components integration.

Our Card Component renders the available cards in your payment form, and securely collects any sensitive card information, so it doesn't touch your server.

If you want more UI freedom for building your card input fields, use our Custom Card Component.

Before you begin

This page explains how to add card payments to your existing Web Components integration. The Web Components integration works the same way for all payment methods. If you haven't done this integration yet, refer to our Components integration guide.

Before starting your integration:

  1. Make sure that you have set up your back end implementation, and created an instance of AdyenCheckout.
  2. Add the cards that you want to accept in your test Customer Area.

Show the available cards in your payment form

For information about the supported countries and currencies for each card, refer to Payment methods.

To show the Card Component in your payment form:

  1. Specify in your /paymentMethods request a combination of countryCode and amount.currency. This is used to determine which cards are available to the shopper.

    When the shopper is entering their card details, Card Component tries to recognize the card brand. When successful, the Component renders the brand icon and the corresponding input field for the card security code (CVC, CVV, or CID).

  2. Add the Card Component:

    a. Create a DOM element for cards, placing it where you want the card form to be rendered:

    <div id="card-container"></div>

    b. Create an instance of the Card Component, and mount it. You can also include optional configuration:

Field Description Default
enableStoreDetails Set to true to show the check box for saving the card details for recurring payments. false
hasHolderName Set to true to show the input field for the card holder name. false
holderNameRequired Set to true to make the card holder name a required field. To show the field, you additionally need to set hasHolderName to true. false
holderName String that is used to prefill the card holder name field. Empty
name String that is used to display the payment method name to the shopper. Depends on the shopperLocale specified in /paymentMethods request.
brands Array of card brands that will be recognized by Drop-in. For a list of possible values, refer to Supported card types. ['mc','visa','amex']
showBrandIcon Set to false to have Drop-in not show the brand logo when the card brand has been recognized. true
styles Set a style object to customize the card input fields. For a list of supported properties, refer to Styling card input fields.
     const card = checkout.create("card", {
         // Optional configuration
         enableStoreDetails: true,
         hasHolderName: true,
         holderNameRequired: true,
         holderName: 'S. Hopper',
         brands: ["visa", "amex"]
     }).mount("#card-container");

You can also customize your shopper's experience when specific events occur. For more information, refer to Events.

Make a payment

When the shopper selects to pay, the Component calls the onChange event, which contains a state.data.

  1. If state.isValid is true, collect the state.data and pass this to your server.
  2. From your server, make a /payments request, specifying:

    • paymentMethod: The state.data.paymentMethod from the onChange event.

curl https://checkout-test.adyen.com/v50/payments \
-H "X-API-key: [Your API Key here]" \
-H "Content-Type: application/json" \
-d '{
  "amount":{
    "currency":"USD",
    "value":1000
  },
  "reference":"YOUR_ORDER_NUMBER",
  "{hint:state.data.paymentMethod from onChange or onSubmit}paymentMethod{/hint}": {
    "type": "scheme",
     "encryptedCardNumber": "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
     "encryptedExpiryMonth": "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
     "encryptedExpiryYear": "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
     "encryptedSecurityCode": "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
     "holderName": "S. Hopper"
  },
  "returnUrl": "https://your-company.com/...",
  "merchantAccount":"YOUR_MERCHANT_ACCOUNT"
}'
# Set your X-API-KEY with the API key from the Customer Area.
adyen = Adyen::Client.new
adyen.api_key = "YOUR_X-API-KEY"
 
response = adyen.checkout.payments({
  :amount => {
    :currency => "USD",
    :value => 1000
  },
  :reference => "YOUR_ORDER_NUMBER",
  :paymentMethod => {
    :type => "scheme",
    :encryptedCardNumber => "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
    :encryptedExpiryMonth => "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
    :encryptedExpiryYear => "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
    :encryptedSecurityCode => "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
    :holderName => "S. Hopper"
  },
  :returnUrl => "https://your-company.com/...",
  :merchantAccount => "YOUR_MERCHANT_ACCOUNT"
})
// Set your X-API-KEY with the API key from the Customer Area.
Client client = new Client(xApiKey,Environment.TEST);
 
Checkout checkout = new Checkout(client);
PaymentsRequest paymentsRequest = new PaymentsRequest();
paymentsRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT");
Amount amount = new Amount();
amount.setCurrency("USD");
amount.setValue(1000L);
paymentsRequest.setAmount(amount);
String encryptedCardNumber = "adyenjs_0_1_18$...encryptedCardNumber";
String encryptedExpiryMonth = "adyenjs_0_1_18$...encryptedExpiryMonth";
String encryptedExpiryYear = "adyenjs_0_1_18$...encryptedExpiryYear";
String encryptedSecurityCode = "adyenjs_0_1_18$...encryptedSecurityCode";
paymentsRequest.setReference("YOUR_ORDER_NUMBER");
paymentsRequest.addEncryptedCardData(encryptedCardNumber,encryptedExpiryMonth, encryptedExpiryYear, encryptedSecurityCode, "S. Hopper");
paymentsRequest.setReturnUrl("https://your-company.com/...");
PaymentsResponse paymentsResponse = checkout.payments(paymentsRequest);
// Set your X-API-KEY with the API key from the Customer Area.
$client = new \Adyen\Client();
$client->setXApiKey("YOUR_X-API-KEY");
$service = new \Adyen\Service\Checkout($client);

$params = array(
  "amount" => array(
    "currency" => "USD",
    "value" => 1000
  ),
  "reference" => "YOUR_ORDER_NUMBER",
  "paymentMethod" => array(
    "type" => "scheme",
    "encryptedCardNumber" => "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
    "encryptedExpiryMonth" => "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
    "encryptedExpiryYear" => "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
    "encryptedSecurityCode" => "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
    "holderName" => "S. Hopper"
  ),
  "returnUrl" => "https://your-company.com/...",
  "merchantAccount" => "YOUR_MERCHANT_ACCOUNT"
);
$result = $service->payments($params);
#Set your X-API-KEY with the API key from the Customer Area.
adyen = Adyen.Adyen()
adyen.client.xapikey = 'YOUR_X-API-KEY'

result = adyen.checkout.payments({
   'amount': {
      'value': 1000,
      'currency': 'USD'
   },
   'reference': 'YOUR_ORDER_NUMBER',
   'paymentMethod': {
      'type': 'scheme',
      'encryptedCardNumber': 'adyenjs_0_1_18$MT6ppy0FAMVMLH...',
      'encryptedExpiryMonth': 'adyenjs_0_1_18$MT6ppy0FAMVMLH...',
      'encryptedExpiryYear': 'adyenjs_0_1_18$MT6ppy0FAMVMLH...',
      'encryptedSecurityCode': 'adyenjs_0_1_18$MT6ppy0FAMVMLH...',
      'holderName': 'S. Hopper'
   },
   'returnUrl': 'https://your-company.com/...',
   'merchantAccount': 'YOUR_MERCHANT_ACCOUNT'
})
// Set your X-API-KEY with the API key from the Customer Area.
var client = new Client ("YOUR_X-API-KEY", Environment.Test);
var checkout = new Checkout(client);

var amount = new Model.Checkout.Amount("USD", 1000);
var details = new Model.Checkout.DefaultPaymentMethodDetails{
  Type = "scheme",
  EncryptedCardNumber = "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
  EncryptedExpiryMonth = "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
  EncryptedExpiryYear = "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
  EncryptedSecurityCode = "adyenjs_0_1_18$MT6ppy0FAMVMLH..."
};
var paymentsRequest = new Model.Checkout.PaymentRequest
{
  Reference = "YOUR_ORDER_NUMBER",
  Amount = amount,
  ReturnUrl = @"https://your-company.com/...",
  MerchantAccount = "YOUR_MERCHANT_ACCOUNT",
  PaymentMethod = details
};

var paymentResponse = checkout.Payments(paymentsRequest);
// Set your X-API-KEY with the API key from the Customer Area.
const {Client, Config, CheckoutAPI} = require('@adyen/api-library');
const config = new Config();
// Set your X-API-KEY with the API key from the Customer Area.
config.apiKey = '[API_KEY]';
config.merchantAccount = '[YOUR_MERCHANT_ACCOUNT]';
const client = new Client({ config });
client.setEnvironment("TEST");
const checkout = new CheckoutAPI(client);
checkout.payments({
    amount: { currency: "USD", value: 1000 },
    paymentMethod: {
        type: 'scheme',
        encryptedSecurityCode: "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
        encryptedExpiryMonth: "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
        encryptedExpiryYear: "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
        holderName: "S. Hopper",
        encryptedCardNumber: "adyenjs_0_1_18$MT6ppy0FAMVMLH..."
    },
    reference: "YOUR_ORDER_NUMBER",
    merchantAccount: config.merchantAccount,
    returnUrl: "https://your-company.com/..."
}).then(res => res);

The /payments response contains:

  • pspReference: Our unique identifier for the transaction.
  • resultCode: Use this to present the payment result to your shopper.
  • merchantReference: The reference from the /payments request.
  • additionalData: Additional information about the transaction.
    To specify the fields that you want to receive in additionalData, log in to your Customer Area, and go to Account > API URLs > Additional data settings.

{
  "additionalData": {
    "cardSummary": "1111"
  },
  "pspReference": "851572424333194G",
  "resultCode": "Authorised",
  "merchantReference": "YOUR_ORDER_NUMBER"
}

Present the payment result

Use the resultCode from the /payments response to present the payment result to your shopper. You will also receive the outcome of the payment asynchronously in a notification webhook.

For card payments, you can receive the following resultCode values:

resultCode Description Action to take
Authorised The payment was successful. Inform the shopper that the payment has been successful.
If you are using manual capture, you also need to capture the payment.
Cancelled The shopper cancelled the payment. Ask the shopper whether they want to continue with the order, or request that they select a different payment method.
Error There was an error when the payment was being processed. For more information, check the refusalReason field. Inform the shopper that there was an error processing their payment.
Refused The payment was refused. For more information, check the refusalReason field. Ask the shopper to try the payment again using a different payment method.
Additional resultCode values are possible in case of the 3D Secure authentication flow. For more information, refer to Result codes.

Recurring payments

Adyen's tokenization service allows you to securely store shopper's card details for recurring payments. To make recurring payments, you first need to create a shopper token, and then use the token to make future payments for the shopper.

Create a token

To store shopper's card details, set enableStoreDetails to true when adding the Card Component. This will show a check box to your shopper for saving their card details for future payments.

If the shopper chooses to save their card details when making a payment, the onChange (or onSubmit) method from the Component will include a state.data.storePaymentMethod. Pass this to your server.

To create a token, include in your /payments request:

  • storePaymentMethod: The state.data.storePaymentMethod from your front end.
  • shopperReference: Your unique identifier for the shopper.

Show a stored card in your payment form

To show a stored card payment in your payment form:

  1. Include in your /paymentMethods request:
  • shopperReference: The unique shopper identifier that you specified when creating the token.

The /paymentMethods response includes a storedPaymentMethods array containing the stored payment methods for this shopper.

         {
         ...
         "storedPaymentMethods":[
             {
                "brand":"visa",
                "expiryMonth":"10",
                "expiryYear":"2020",
                "holderName":"John Smith",
                "id":"8415718415172204",
                "lastFour":"1111",
                "name":"VISA",
                "supportedShopperInteractions":[
                   "Ecommerce",
                   "ContAuth"
                ],
                "type":"scheme"
             },
             {
                "brand":"visa",
                "expiryMonth":"12",
                "expiryYear":"2020",
                "holderName":"John Smith",
                "id":"8315720121476805",
                "lastFour":"0008",
                "name":"VISA",
                "supportedShopperInteractions":[
                   "ContAuth",
                   "Ecommerce"
                ],
                "type":"scheme"
             }
]
         ...
         }

When creating an instance of the AdyenCheckout, pass the full /paymentMethods response to the paymentMethodsResponse object .

  1. Add stored cards to your payment form:
    a. Create a a DOM element for stored payment methods, placing it where you want the form to be rendered:
    <div id="stored-card"></div>
    b. Get the stored payment method that you want to display from the checkout.paymentMethodsResponse object, and pass this when creating an instance of the Card Component:
    const storedPaymentMethod = checkout.paymentMethodsResponse.storedPaymentMethods[0];
    const card = checkout.create("card", storedPaymentMethod).mount("#stored-card");
To configure how the stored card renders in your payment form, refer to Configuring the Component.

When the shopper selects to pay, the Component calls the onChange event, which contains a state.data. If state.isValid is true, collect the state.data and pass this to your server. You'll need this to make a payment.

Make a payment with a token

To make a payment with a token, include in your /payments request:

  • paymentMethod: The state.data.paymentMethod from the onSubmit event. This includes the security code that the shopper needed to enter to complete the payment.
  • shopperReference: Your unique identifier for the shopper.

You can also use tokens to make shopper-not-present payments for subscriptions or contracts. For more information, refer to Making a payment for a subscription or contract.

Test and go live

Before making live card payments:

  1. Test your integration using our test card numbers.
    You can check the status of test payments in your Customer Area > Transactions > Payments.
  2. Add the cards that you wish to accept in your live Customer Area.

See also