Plugin icon

Headless integration

Integrate an Adobe Commerce headless storefront with the Adyen platform.

This page describes the headless setup for v9.0.1 or later. If you are using an earlier version, see the older documentation.

Implementation examples
  Try it out on GitHub!

On this page we provide Adyen-specific information for building a Progressive Web Application (PWA) storefront. The PWA storefront works with a headless Adobe Commerce back-end that has the Adyen plugin installed and configured.

Two web APIs can be used to utilize the Adyen functionality:

  • REST - This is the most widely used web API. All of the functionalities provided by the Adyen plugin can be accessed using this method.
  • GraphQL - This is an alternative way to interact with web APIs. The Adyen plugin utilizes the /graphql endpoint exposed by the Adobe Commerce back-end and adds the functionality that is related to the plugin. All functionalities provided by the Adyen plugin can be accessed using this method. For more information, checkout the Adobe Commerce GraphQL documentation.
    GraphQL is only available with plugin v8.2.0 or later.

Ecommerce checkout flow

With a headless Adobe Commerce back end, you build your own payment form for the Adobe Commerce PWA storefront. In the checkout flow, data passes from the PWA storefront through the Adobe Commerce back end to the Adyen API. Then, data passes back from the Adyen API through the Adobe Commerce back end to the PWA storefront. In the checkout flow, you need to do the following steps:

  1. Get the payment methods that are available on the Adyen platform, and for each of them determine the data that you need to collect.
  2. Collect shopper details by presenting the payment methods on your payment form. Then, when the shopper selects a payment method, present the fields to fill out or the options to choose from, and collect these details.
  3. Place the order.
  4. Check the payment status to see if you need to perform any extra steps before redirecting the user to the success page or showing an error message.
  5. Handle additional actions like redirecting the customer to the issue page for additional authentication, or presenting a QR code to complete the payment. If the payment fails, the following attempts will need to handle the additional actions as well

Before you begin

Before you start integrating a Adobe Commerce PWA storefront with the Adyen platform:

  1. Make sure you have completed the steps to configure the Adobe Commerce back end:

    Setting up in-person payments is not required for a PWA storefront.

  2. The plugin uses Adobe Commerce’s recommended authentication methods to authenticate requests coming from the front-end application. The endpoints use self resources for logged-in shoppers and anonymous resources for guest shoppers.
    Therefore, an integration token is no longer required. Customer token needs to be used as Bearer Token for logged-in shoppers. For guest shoppers, no token is required because a masked card_id is used to authenticate requests.

For more information on resource access, refer to Adobe Commerce documentation.

Step 1: Get available payment methods

In this step, the Adobe Commerce back end retrieves the available payment methods from the /paymentMethods API endpoint and adds some extra information that you will need for rendering the components on the front end.

To get the available payment methods and extra information:

  1. Make an API request to get the payment methods and data that you need to collect.
  2. Parse the API response to get a JSON object that contains the Adyen /paymentMethods response and required extra information.

1. Make an API request

If you are using REST, the endpoint differs per use case. If you are using GraphQL, the endpoint is /graphql.

The /payment-information and /shipping-information responses include extension_attributes. This field contains available payment methods and required extra information as adyen_payment_methods_response. The required extra information is relevant when collecting shopper details in Step 2.

The payment_methods object in the response of /payment-information or /shipping-information endpoints is filtered and sorted according to the response of /paymentMethods endpoint.

2. Parse the API response

The Adobe Commerce back end receives a response from Adyen containing all available payment methods for the current session filtered by currency, amount, country, etc. For each payment method, the /paymentMethods response includes:

  • name: Name of the payment method, which you can show to your shopper in your payments form.
  • type: Unique payment method code. Pass this back to indicate the shopper's selected payment method when you place an order.

The plugin also collects some extra information other than the /paymentMethods response. This data is included in the response as the following fields:

  • icon {url, width, height}: Payment method icon details.
  • configuration: Includes any extra payment method specific configuration that the checkout component should get on the front end which is not accessible from the /paymentMethods details response.
  • isOpenInvoice (boolean): Indicates if the payment method is an open invoice payment method. Note that this field is deprecated and will be removed later.

The following is an example API response for the REST flow, a GraphQL query retrieves data similarly to a REST GET request. To learn more about the similarities and differences between REST and GraphQL, refer to Adobe Commerce GraphQL documentation.

  • The response contains payment methods as a JSON encoded string. Parse this string to get a JSON object. For example, using JSON.parse();.

After parsing the response, you get two root objects:

  1. paymentMethodsResponse: Includes the full and unmodified response object from the Adyen /paymentMethods API endpoint.
  2. paymentMethodsExtraDetails: Holds the extra information that the plugin gathered for each payment method that is available in the paymentMethodsResponse.
{
    "paymentMethodsExtraDetails": {
        "applepay": {
            "icon": {
                "url": "full url for icon",
                "width": 1,
                "height": 1
            },
            "configuration": {
                "amount": {
                    "value": 1,
                    "currency": "currency ISO code like EUR"
                }
            }
        },
        "klarna": {...},
        "ideal": {...},
        "klarna_paynow": {...}
    },
    "paymentMethodsResponse": {
        "paymentMethods": [
            {
                "name": "iDEAL",
                "type": "ideal"
            },
            {
                "brands": [
                    "mc",
                    "visa",
                    "maestro"
                ],
                "name": "Cards",
                "type": "scheme"
            },
            {
                "configuration": {
                    "intent": "capture",
                    "merchantId": "Merchant id"
                },
                "name": "PayPal",
                "type": "paypal"
            },
            {
                "name": "Pay later with Klarna.",
                "type": "klarna"
            },
            {
                "name": "SEPA Direct Debit",
                "type": "sepadirectdebit"
            },
            {
                "configuration": {
                    "merchantId": "Merchant id",
                    "merchantName": "Merchant name"
                },
                "name": "Apple Pay",
                "type": "applepay"
            }
        ]
    }
}

Step 2: Collect shopper details

Next, present the available payment methods on your front end, and collect the shopper details that are required for the payment method selected by the shopper.

  1. Use the name values from the /paymentMethods response to show all available payment methods to your shopper.

    If you need payment methods and issuer logos for your payment form, use the paymentMethodsExtraDetails.icon from the /payment-information response as described in the previous step.

  2. After the shopper selects a payment method, render the input fields to get the required payment details. You can do this by rendering the input fields with Adyen Components.

Render the input fields with Adyen Components

You can use our Web Components to render individual payment methods anywhere on your website with our customizable UI components.

We recommend to pass the full paymentMethodsResponse object to the Web Component configuration when implementing multiple payment methods in your PWA storefront. After creating the new AdyenCheckout object, you can loop through the methods and generate the components instead of creating components manually for each payment method. This also ensures that your integration can handle new payment methods when enabled in your Customer Area.

Step 3: Place the order

After the customer has filled in their data, you can place the order. In this step, the storefront makes a request to the Adobe Commerce back end which then makes a payment request to the /payments endpoint.

To start the payment process, place the order from your front end in the way the default Adobe Commerce checkout flow requires:

  1. Create a data object to send in the Adobe Commerce API request.
  2. Place the order with the created object.

1. Create a data object

First, create a data object that you can send in the Adobe Commerce 2 REST API /payment-information request.

To get the necessary details for this object, you can do either of the two:

  • Use state.data from the Web component.

  • Replicate the request object based on the documentation for the /payments endpoint, with the following parameters.

    Parameter Required Description
    method -white_check_mark- Payment method name in Adobe Commerce. For example, adyen_cc, adyen_ideal, or adyen_googlepay.
    cc_type If method is adyen_cc Card type.
    Get the card type available in Adobe Commerce based on the state.data.paymentMethod.brand or state.brand. See example.
    If you implement the onBrand callback for the Web Component, then you can find it as state.brand. See example.
    brand_code If method is an alternative payment method The value of state.data.paymentMethod.type field.
    recurringProcessingModel -x- The recurring processing model for the request, overwrites the default value in the plugin configuration. Set to Subscription, CardOnFile, UnscheduledCardOnFile depending on the recurring payment type you are making the request for.
    stateData -white_check_mark- Use the JSON.stringify() function on the state.data object that you get from the Web Component. See example.
    The state.data object can be set in a separate request to accommodate special checkout flows.
  • When replicating the object for a card payment method, follow this structure:

  • When replicating the object for an alternative payment method, follow this structure:

2. Place an order

Place the order with the /payment-information endpoint from the Adobe Commerce REST API. Use the object created in the previous step.

If you cannot use the /payment-information endpoint to set state.data, see setting the payment state.data in a separate request.

Plugin v7.2.0 and later support setting the payment's state.data by using the /V1/adyen/carts/mine/state-data or /V1/adyen/guest-carts/:cartId/state-data endpoint. This is useful for checkout flows where this information can't be sent using the /payment-information Adobe Commerce REST API endpoint.

The /state-data endpoint receives the following parameters:

Parameter Description
state_data state.data from the Web Component.
quote_id The ID of the Adobe Commerce quote related to state.data.

state.data saved with this endpoint is used in the payment request if no state.data was supplied in the /payment-information request.

Using this endpoint will persist payment data which can be useful for complex checkout flows, but could have implications for your integration's PCI scope. Reach out to our Support team for questions.

For more information, refer to the Adobe Commerce API documentation.

The response contains the orderId field with an integer value that you need for the next step.

Step 4: Check payment status

To see if there are any additional steps required after placing the order, call the payment status endpoint:

  1. Make a POST request:

    • For logged-in shoppers, use the /V1/adyen/orders/carts/mine/payment-status endpoint.
    • For guest shoppers, use the /V1/adyen/orders/guest-carts/{cartId}/payment-status endpoint.

    In the request body, include orderId that you received in the response from the /payment-information endpoint in the previous step. See an example from our plugin's credit card method renderer.

  1. Parse the JSON response and evaluate it. There are two paths that you can follow based on the isFinal response field.
    • The isFinal field is true:
      • If the resultCode field is Authorised or Received, the payment was successful and you can redirect the customer to the success page.
      • If the resultCode field is PresentToShopper, present the voucher or QR code to the shopper so they can complete the payment.
      • If the resultCode field is Refused, Error or unhandled, you receive a response containing an HTTP 400 result code and a default Adobe Commerce localized error response.
      • If the action field is present and is not empty, then handle the additional action using the Web Component.
    • The isFinal field is false:

Step 5: Handle additional actions

This step is only needed if the action field is present and not empty in the response of the previous step.

Some payment methods require additional action from the shopper. For example, to scan a QR code, to authenticate a payment with 3D Secure, or to log in to their bank's website to complete the payment. To handle these additional front-end actions, follow the Web Components documentation or find specific documentation for each payment method in this list.

All payment methods use the createFromAction method, except for PayPal. The PayPal Component uses the handleAction method to process additional action from the PayPal pop-up window.

Create your request to handle the additional action with the following fields:

  • payload: JSON.stringify() the object that you get from the action component in the state.data field.
  • orderId: The orderId you received in the response when you placed the order.

Optional: Validate the state.data from the action component

In case the shopper is already redirected to the success page, you don't need to validate anything because the Component presents a QR code or additional information to the customer, and no additional steps are required from you. Adyen is going to send a notification to your system as soon as the customer finishes the payment.

The plugin handles webhooks on its own.

In case the shopper is still in the checkout process, you need to perform additional checks of the state.data that you get back from the Component. To do this, implement the onAdditionalDetails callback when creating the new AdyenCheckout component.

To validate the state.data:

  • Use the /V1/adyen/carts/mine/payments-details endpoint for logged-in shoppers.
  • Use the /V1/adyen/guest-carts/:cartId/payments-details endpoint for guest shoppers.

Gift card payments

After you have followed the steps to get the available payment methods and present them in your front end, you can offer your shoppers to pay with gift cards.

For GraphQL integrations, the additional setup steps below are required to process gift card payments.

Step 1: Mount the component

After a shopper selects the option to pay with a gift card, mount the Adyen Web Component for gift cards and check the balance:

  1. Follow the steps to configure the Component.
    When creating an instance of the Component, in the onBalanceCheck event, call the adyenPaymentMethodsBalance GraphQL mutation that returns the available balance of a gift card.
  2. Use the JSON.stringify() function on the data object you get from the event. This is the payload for the adyenPaymentMethodsBalance mutation.


    This mutation returns the balance of a gift card, and additional details like the currency and value. For example:

Step 2: Save gift card state data

To redeem gift cards when making a payment, save the state data associated with the Adyen payment method.

Use the adyenSaveStateData GraphQL mutation to save the state data after you have checked the balance of a gift card. For multiple gift cards payments, save the state data for each gift card after checking their balances.

  • stateData: The JSON string that contains state data to save.
  • cart_id: Use the cart ID of your shopper's cart.

This mutation makes a request to save the state data:

You get a stateDataId object that you can use to remove the saved state data later.

You may no longer need the saved state data if your shopper deletes the gift card number in the checkout form, for example if they decide to pay with another gift card.

To remove the saved state data, use the adyenRemoveStateData GraphQL mutation:

  • stateDataId: The ID that you received in the response when you saved state data.
  • cart_id: Use the cart ID of your shopper's cart.

    You get a response containing the stateDataId for removed state data.

Step 3: Redeem gift cards

  1. Use the adyenRedeemedGiftCards GraphQL mutation that returns an array of the gift cards, including identifiers and remaining balances to fetch redeemed gift cards. This allows you to present the gift cards and the deducted amounts in your front end.


  2. Compare the amount of the shopper's cart to the balance available on the gift card. The way you place the order depends on the outcome of the comparison:

    • If the balance of the gift card is equal or higher than the order amount, place the order with adyen_giftcard for the code field.
    • If the balance of the gift card is lower than the order amount, place the order with the payment method that is used to cover the remaining amount. The plugin handles the gift card redemption automatically using the state data you have saved.

After you have followed the above steps, check the payment status as you would for other payment methods.

Tokenization

With your headless integration, you can securely store the payment details of shoppers and offer returning customers a faster checkout experience.

Tokenization in a headless integration works similarly to tokenization in the standard plugin setup, using the Adobe Commerce Vault.

Tokenize shopper payment details

Follow the steps to set up the vault in Adobe Commerce.

After you have enabled tokenization in your Adobe Commerce admin panel, a Save for my next payment checkbox will appear when making a payment. If the checkbox is selected, the shopper payment details will be stored in the vault_payment_token database table.

Remove a shopper token

For each token, the vault_payment_token database table includes:

  • shopperReference: Stored in Adobe Commerce as the customer_id.
  • storedPaymentMethodId: Stored in Adobe Commerce as the gateway_token.

To remove an existing shopper token, make a POST /token/deactivate request from your server. In your request, include the customerId parameter. This must match the customer_id value for the token in the database table.

Troubleshooting

When you get unexpected results, you can:

  • Check the endpoints on Adyen's GitHub as a starting point to see if there are any changes. In addition, check your /swagger where all the endpoints are listed.

  • Use our API Explorer to try out calls to the Adyen API endpoints and for example see what kind of errors you might get. Make sure you select the API version that the Adobe Commerce plugin uses. Check the library and API versions you are using.

Checking library and API versions

The Adobe Commerce plugin uses a specific version of the Adyen PHP library, which uses specific versions of the Adyen APIs. You can try out calls to the Adyen APIs in our API Explorer. The API Explorer is versioned, and you need to select the API version that your Adobe Commerce plugin version is using before trying calls.

To look up which PHP library and Adyen API versions you are using, refer to the release notes.

Alternatively:

  1. Go to the Adyen Adobe Commerce (formerly Magento 2) plugin on GitHub.
  2. In the Branch dropdown, on the Tags tab, select the version of your Adobe Commerce plugin.
  3. At adyen/php-api-library, find the version of the Adyen PHP library that the plugin uses. For example, "adyen/php-api-library": "~2.1".
  4. Go to the Adyen PHP library.
  5. In the Branch dropdown, on the Tags tab, select the library version you've just found.
  6. Refer to the API constants to find the versions of the Adyen APIs that the PHP library uses, for example const API_CHECKOUT_VERSION = "v41".

See also