Desktop/Mobile Website Browser/Mobile App - Affirm
Step 1. Initialize a Payment Intent
Create a Payment Intent with the Create a Payment Intent API API.
Affirm requires the shipping and billing addresses to be passed in the order.shipping and order.billing objects when creating the Payment Intent.
1curl -X POST https://api-demo.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 Intent API API to get a redirect URL.
1curl -X POST https://api-demo.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-demo.airwallex.com/pa/redirect/hk/hkpdxjqhmgsyvijy6hz_bwvqvc?checksum=1c11d21315c1"7 }8}
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 Intent API 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.