Edit in GitHubLog an issue

Payment use cases

This page explores different use cases and scenarios for implementing payment methods using the Adobe Commerce checkout starter kit.

For more general use cases, refer to use-cases.

Get order details from Adobe Commerce using the masked cart ID

The following steps demonstrate the payment flow:

  1. The payment flow starts at the frontend. When checkout is completed, the frontend sends the masked cart ID to the payment gateway.

  2. The payment gateway then sends a request to the App Builder application with the masked cart ID, as this is the only information it has about the order. This request could be a webhook or an event.

  3. The App Builder application uses the Adobe Commerce HTTP Client to retrieve the order details using the masked cart ID. To facilitate this, the starter kit provides the method getOrderByMaskedCartId in the Adobe Commerce HTTP Client.

sequence.png

Validate payment info

To perform a headless checkout and payment, the Commerce instance must ensure that the payment has succeeded and the order can be placed.

Set payment method additional data

To ingest payment gateway specific information in the payment process, the checkout process must use the setPaymentMethodOnCart mutation in combination with the payment_method.additional_data field to persist the information required to validate the payment once the order is placed.

Copied to your clipboard
setPaymentMethodOnCart(
input: {
cart_id: $cartId
payment_method: {
code: $code
additional_data: [
{
key: 'sessionId',
value: '12A34B56-1A23-1234-A123-123456A78901',
},
{
key: 'status',
value: 'DONE',
},
]
}
}
) {
cart {
selected_payment_method {
code
title
}
}
}

Validate the payment with a webhook

With this additional information saved, you can configure an Adobe Commerce Webhook to validate the payment during order placement. This webhook triggers a synchronous call to your App Builder application, which is responsible for verifying payment details before the order is finalized.

The following example demonstrates how to add a webhook to the observer.sales_order_place_before method:

PaaS only To register a webhook, modify the webhooks.xml file and create a new webhook with the following configuration:

Copied to your clipboard
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_AdobeCommerceWebhooks:etc/webhooks.xsd">
<method name="observer.sales_order_place_before" type="before">
<hooks>
<batch name="out_of_process_payment_methods">
<hook name="validate_payment"
url="https://<your_app_builder>.adobeioruntime.net/api/v1/web/commerce-checkout-starter-kit/validate-payment"
method="POST" timeout="20000" softTimeout="0" priority="100" required="true"
fallbackErrorMessage="Error on validation">
<fields>
<field name="payment_method" source="data.order.payment.method" />
<field name="payment_additional_information" source="data.order.payment.additional_information" />
</fields>
<rules>
<rule field="data.order.payment.method" operator="equal" value="<your_payment_method_code>" />
</rules>
</hook>
</batch>
</hooks>
</method>
</config>

SaaS only For Adobe Commerce as a Cloud Service, you can create webhooks in the Admin.

Copied to your clipboard
Hook Settings
Webhook Method: observer.sales_order_place_before
Webhook Type: before
Batch Name: validate_payment
Hook Name: oope_payment_methods_sales_order_place_before
URL: https://<your_app_builder>.runtime.adobe.io/api/v1/web/commerce-checkout-starter-kit/validate-payment
Active: Yes
Method: POST
Hook Fields
Name: payment_method
Source: data.order.payment.method
Name: payment_additional_information
Source: data.order.payment.additional_information
Hook Rules
Name: data.order.payment.method
Value: <your_payment_method_code>
Operator: equal

To enhance security, enable webhook signature generation by following the webhooks signature verification instructions.

Refer to actions/validate-payment.js for an example of how to validate the payment according to the payment gateway needs.

Filter out payment method

In some cases, you may want to filter out a payment method based on the cart details or the customer's information. For example, you may want to disable a payment method based on customer group or product attributes in the cart.

You can use the plugin.magento.out_of_process_payment_methods.api.payment_method_filter.get_list webhook to filter out a payment method. This webhook is triggered every time the list of available payment methods is requested, allowing you to filter out the payment methods based on the cart details or customer information.

PaaS only The following example demonstrates how to add a webhook to the plugin.magento.out_of_process_payment_methods.api.payment_method_filter.get_list method:

Copied to your clipboard
<method name="plugin.magento.out_of_process_payment_methods.api.payment_method_filter.get_list" type="after">
<hooks>
<batch name="out_of_process_payment_methods">
<hook name="payment_method_filter" url="https://<your_app_builder>.runtime.adobe.io/api/v1/web/commerce-checkout-starter-kit/filter-payment" method="POST" timeout="20000" softTimeout="0">
<fields>
<field name="payload" />
</fields>
</hook>
</batch>
</hooks>
</method>

Payload example:

Copied to your clipboard
{
"payload": {
"cart": {
"entity_id": "1",
"store_id": 1,
"converted_at": null,
"is_active": "1",
...
"items": [
{
"item_id": "4",
"quote_id": "1",
"product_id": "10",
"store_id": 1,
"weight": "124.000000",
"qty": 2,
"price": "600.0000",
"base_price": "600.0000",
...
"product": {
"entity_id": "10",
...
"attributes": {
"manufacturer": "Two",
"color": "Yellow",
"country_origin": "France",
...
}
},
},
...
],
},
"customer": {
"entity_id": "1",
"website_id": "1",
"email": "test@example.com",
"group_id": "1",
...
}
}
}

You can find examples of how to filter out payment methods using customer data or product attributes in your App Builder application in actions/filter-payment.js.

  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2025 Adobe. All rights reserved.