Registered user checkout
Drop-in Element allows you to save payment details for future payments. When Airwallex receives the payment details from your embedded checkout page after the shopper clicks 'submit', it processes the payment and returns a payment method identifier, which you can use to reference the saved payment information in subsequent payments.
Saved payment method details may be used to trigger different payment scenarios:
-
Customer-initiated subsequent payments (CIT): This is useful for recurring shoppers who can make payments by selecting the saved payment method. For saved cards, the shopper will need to enter their security code (CVC) for verification to complete the payment. Note: CVC can be skipped when a card is converted to a network token. For more information, see Network tokenization.
-
Merchant-initiated subsequent payments (MIT): You as a merchant can initiate scheduled (recurring) or unscheduled (one-time) payments without the shopper involved.
Merchant-initiated transactions (MIT payments) inherently carry a higher risk of fraud. This is because merchants trigger these transactions without direct shopper involvement at the time of purchase. For effective management of MITs, refer to our best practices guide.
You can handle the following payment scenarios via Drop-in Element integration:
- Save payment details without a payment
- Save payment details during payment
- Subsequent payment collection using saved payment details
- Reuse saved payment details to set up a new payment agreement with your customer
Before you begin
Before you implement the integration, consider the following:
-
Ensure your Airwallex account has been activated for online payments.
-
Obtain your access token API by authenticating to Airwallex using your unique Client ID and API key. You will need the access token to make API calls.
-
Review the Drop-in Element JS documentation to familiarize yourself with the Drop-in Element methods, parameters, and properties.
-
Install Airwallex.js JS. If your integration currently uses Airwallex Payment Elements , refer to our upgrade guide for information on migrating to Airwallex.js.
-
Download the working sample code to reference as you work through the integration guide.
Save payment details without a payment
You have the option to save a customer's card details without an upfront payment, allowing you to charge them at a later time. This is beneficial for onboarding customers and storing their payment information for future recurring or one-time payments, either initiated by you or by the customer themselves.
Step 1: Create a Customer
To set a card up for future payments, you must first create a Customer object to which the payment details will be linked. Create a Customer object using Create a Customer API API when your shopper creates an account with your business. You can also store name, email, and other details on the Customer. The response will contain a unique id for the Customer and also the client_secret. Save the customer id for later.
Step 2: Create a zero-amount PaymentIntent
To capture the payment card details from your customer, you need to initiate a PaymentIntent by calling Create a PaymentIntent API API. Include the customer_id returned in Step 1—this allows you to link the payment details to already registered customers. Set the amount to 0 and save the client_secret received in the response.
Example request:
Shell1curl --request POST \2--url 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create' \3--header 'Authorization: Bearer <your_access_token>' \4--header 'Content-Type: application/json' \5--data '{6 "amount": 0,7 "currency": "USD",8 "merchant_order_id": "D202503210001",9 "customer_id": "cus_sgdv77ldrh3orm9rlp2",10 "request_id": "b01737e5-c5ab-4765-8834-cbd92dfeaf81",11 "descriptor": "Airwallex - Test Descriptor",12 "return_url": "https://www.airwallex.com",13 "metadata": {14 "foo": "bar"15 }16}'
Step 3: Confirm the payment method details to be saved
Create a checkout page with Drop-in Element JS to collect payment details by passing the following fields in createElement():
intent_id: The PaymentIntent ID from Step 2.client_secret: The client secret from Step 2.currency: The currency code.country_code: The country code.payment_consent: An object containing the intended usage details of the agreement.
Include the intended usage details of the agreement to register it. This helps Airwallex understand if the subsequent payment will be initiated by your shopper or yourself. Query the payment intent or subscribe to payment_intent.succeeded webhook to receive the payment_consent_id, to be used for subsequent payments.
For customer-initiated subsequent (CIT) payments:
Set payment_consent.next_triggered_by to customer.
Example:
JavaScript1import { init } from '@airwallex/components-sdk';23const { payments } = await init({4 env: 'demo',5 enabledElements: ['payments'],6});7payments.createElement('dropIn', {8 intent_id: 'replace-with-your-intent-id',9 client_secret: 'replace-with-your-client-secret',10 currency: 'replace-with-your-currency',11 country_code: 'replace-with-your-country-code',12 payment_consent: {13 next_triggered_by: 'customer'14 }15});
For merchant-initiated subsequent (MIT) payments:
Set payment_consent.next_triggered_by to merchant. In this case, you should also include payment_consent.merchant_trigger_reason with one of the following values:
scheduled: Used when payments are collected at fixed, recurring intervals.unscheduled: Used when payments do not follow a fixed schedule, such as one-off charges made without the customer being in session.installments: Used when the total amount is collected from the customer over multiple installment payments. For this option, you must provide additional installment details underpayment_consent.terms_of_useobject.
Example:
JavaScript1import { init } from '@airwallex/components-sdk';23const { payments } = await init({4 env: 'demo',5 enabledElements: ['payments'],6});7payments.createElement('dropIn', {8 intent_id: 'replace-with-your-intent-id',9 client_secret: 'replace-with-your-client-secret',10 currency: 'replace-with-your-currency',11 country_code: 'replace-with-your-country-code',12 payment_consent: {13 next_triggered_by: 'merchant',14 merchant_trigger_reason: 'scheduled'1516 }17});
Save payment details during payment
You can save a customer's card details during a payment to collect the immediate amount. This allows you to reuse the saved card for future payments, whether initiated by the customer or by you.
Follow the same integration steps as Save payment details without a payment, but in Step 2, when creating the PaymentIntent, provide the pending payment amount instead of setting the amount to 0.
Subsequent payment collection using saved payment details
To collect a subsequent payment using the stored payment details, you need to call Create a PaymentIntent with the customer_id field. The next steps depend on whether the payment is driven by the shopper or by yourself.
Step 1: Create a PaymentIntent
Initiate a payment request by calling Create a PaymentIntent API. Include the customer_id generated by Airwallex when you registered your Customer. Save the returned intent id and client_secret.
Step 2: Confirm the PaymentIntent
The confirmation method depends on whether the payment is customer-initiated or merchant-initiated:
Customer-initiated payment:
Create a checkout page with the Drop-in Element JS to collect payment details. The list of saved payment methods associated with your Customer will be displayed on the checkout page for selection. This allows the shopper to choose their preferred payment method for the payment. For a saved card, the shopper will be prompted to enter their CVC of the card as an additional fraud measure to verify the shopper.
Call createElement() with the following fields when the shopper pays with a saved payment method:
intent_id: Theidof the PaymentIntent you want to confirm and complete.client_secret: Theclient_secretof the PaymentIntent you want to confirm and complete.currency: The currency code.
Example:
JavaScript1import { createElement } from '@airwallex/components-sdk';23const element = createElement('dropIn', {4 intent_id: 'replace-with-your-intent-id',5 client_secret: 'replace-with-your-client-secret',6 currency: 'replace-with-your-currency'7});
A payment may succeed even with a failed CVC check. To prevent this, configure your Risk management rules to block payments when CVC verification fails.
Merchant-initiated payment:
Call Confirm a PaymentIntent API API with the following parameters to charge the shopper:
Required fields:
intent_id: Theidof the PaymentIntent you want to confirm and complete, included as a URL parameter.customer_id: Theidof the Customer associated with the saved payment method.payment_method.id: The PaymentMethodidgenerated when initial MIT was set up.
Example request:
JSON1{2 "customer_id": "cus_sgdv77ldrh3orm9rlp2",3 "payment_method":4 {5 "id": "mtd_sgdv8bwxbh3ol8y67nx",6 "type": "card"7 },8 "triggered_by": "merchant",9 "payment_method_options":10 {11 "card":12 {13 "authorization_type": "final_auth",14 "auto_capture": true15 }16 },17 "request_id": "ee939540-3203-4a2c-9172-89a566485dd9",18 "return_url": "https://www.airwallex.com/"19}
Reuse saved payment details to set up a new agreement
You can reuse the payment details your customer has saved with you to set up a new payment agreement with your shopper. Scenarios include:
-
Customers setting up a new Merchant-Initiated Transaction (MIT) payment have the option to use an existing card number or payment method. This can be one already associated with a Customer-Initiated Transaction (CIT) agreement or another previously established MIT agreement.
-
When making a one-time payment, customers can choose to reuse a card number which is associated with a MIT agreement.
Set up a new MIT using existing payment details
Follow these steps to set up a new MIT agreement using existing payment details:
-
Create a PaymentIntent using the
customer_idthat has been created. -
Configure the
createElement()function with the new intended usage details. You can use the same code sample as detailed in the Save payment details without a payment section for MIT payments. -
Your shopper will be shown a selection of all the cards that are linked to the
customer_idregardless of whether they are stored for CITs or MITs. -
Airwallex generates a new
payment_consent_idafter the completion of the payment. Save thepayment_consent_idto process subsequent payments.
As this is a new Merchant Initiated Transaction (MIT) setup, shoppers might still need to complete 3DS authentication. This can occur due to fraud risk assessments or PSD2 Strong Customer Authentication (SCA) requirements, and it applies regardless of whether the card is pre-existing or not.
Make a one-time payment using payment details stored for MIT
You can reuse saved card details for customer-initiated payments with no further integration, as described in the Subsequent payment collection using saved payment details section under the Customer-initiated payment subsection.
Test your integration
Use test card numbers and the test and go-live checklist to test your integration for various success and error scenarios in the sandbox environment and then go live in the production environment.