Desktop/Mobile Website Browser/Mobile App - Affirm
Step 1. Initialize a Payment Intent
Create a Payment Intent with the Create a Payment IntentAPI API.
Affirm requires the shipping address to be passed in the order.shipping object when creating the Payment Intent. Affirm also encourages passing the billing address in the order.billing object to improve the success rate of Affirm payments.
1curl -X POST https://api.sandbox.airwallex.com/api/v1/pa/payment_intents/create \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer {{ACCESS_TOKEN}}' \4 -d '{5 "request_id": "d917ad44-6ae4-447e-a534-cce4ceebfd2e",6 "amount": 100,7 "currency": "USD",8 "order": {9 "shipping": {10 "first_name": "John",11 "last_name": "Doe",12 "address": {13 "country_code": "US",14 "city": "New York",15 "state": "NY",16 "postcode": "10001",17 "street": "123 Main Street"18 }19 },20 "billing": {21 "first_name": "John",22 "last_name": "Doe",23 "address": {24 "country_code": "US",25 "city": "New York",26 "state": "NY",27 "postcode": "10001",28 "street": "123 Main Street"29 }30 }31 },32 "merchant_order_id": "85d7b0e0-7235-11ea-862e-9f6aa1adfca6",33 "return_url": "https://www.airwallex.com"34 }'
Step 2. Confirm the Payment Intent to obtain the redirect link
When a shopper selects to pay with Affirm on your desktop or mobile browser, call the Confirm a Payment IntentAPI API to get a redirect URL.
1curl -X POST https://api.sandbox.airwallex.com/api/v1/pa/payment_intents/{{PAYMENT_INTENT_ID}}/confirm \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer {{ACCESS_TOKEN}}' \4 -d '{5 "request_id": "d917ad44-6ae4-447e-a534-cce4ceebfd2e",6 "payment_method": {7 "type": "affirm",8 "affirm": {9 "shopper_email": "[email protected]",10 "flow": "qrcode"11 }12 }13 }'
You will get a response similar to the following.
1{2 // ... other fields omitted.3 "next_action": {4 "type": "redirect",5 "method": "GET",6 "url": "https://api.sandbox.airwallex.com/pa/redirect/hk/hkpdxjqhmgsyvijy6hz_bwvqvc?checksum=1c11d21315c1"7 }8}
Step 2a. (Optional) Set Affirm payments to be manually captured later
By default, Affirm payments are automatically captured. If you want to capture payments at a later date, pass auto_capture as false when calling the Confirm a Payment IntentAPI API.
1curl -X POST https://api.sandbox.airwallex.com/api/v1/pa/payment_intents/{{PAYMENT_INTENT_ID}}/confirm \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer {{ACCESS_TOKEN}}' \4 -d '{5 // ...other fields omitted.6 "payment_method_options": {7 "affirm": {8 "auto_capture": false9 }10 }11 }'
Step 2b. Manually capture Affirm payments
You must manually capture Affirm payments within 7 days after authorization. You can call the Capture a PaymentIntentAPI API to capture the payments. Partial captures are supported. If you perform a partial capture, the remaining amount is returned to the shopper.
1curl -X POST https://api.sandbox.airwallex.com/api/v1/pa/payment_intents/{{PAYMENT_INTENT_ID}}/capture \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer {{ACCESS_TOKEN}}' \4 -d '{5 "request_id": "2c53861f-ce66-4054-880e-6c0901a15d29",6 "amount": 107 }'
Alternatively, you can manually capture payments from your Airwallex web app under the manual capture section.

Step 3. Query the payment result status
To get the payment result, we suggest you poll the status of the Payment Intent via the Retrieve a Payment IntentAPI API. You may start polling the Payment Intent status after the shopper is redirected back to your website or mobile app, i.e., the return_url passed when creating the Payment Intent.
GET /api/v1/pa/payment_intents/{id}
In addition, Airwallex will notify you of the payment result asynchronously via the webhooks. Please refer to the webhook documentation to set up your webhook accordingly. Although subscribing to webhook events is optional, it is recommended to subscribe to the payment_intent.succeeded webhook which indicates that the shopper has paid the order.