Accept Recurring Payments - Alipay HK
Set up recurring payments with Alipay HK by first linking with the shopper's account through payment consent, then using that consent for future payments without requiring the shopper to re-authenticate each time.
Linking with the shopper's Alipay HK account for the first time
Step 1: Create a Customer (Optional)
Create a customer with the Create a Customer API API if the customer is new. Otherwise, this step is optional.
1curl -X POST https://api-demo.airwallex.com/api/v1/pa/customers/create \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer {{ACCESS_TOKEN}}' \4 -d '{5 "request_id": "2ed2d823-f8b3-416e-86db-ced8770ce217",6 "merchant_customer_id": "9fafc2fb-4262-4ff8-a205-d60fb4781cb0",7 "first_name": "John",8 "last_name": "Doe",9 "email": "[email protected]",10 "phone_number": "+85298765432"11 }'
Example response:
1{2 // ... other fields omitted.3 "id": "cus_uspd6m9zph9g2fjvn1r",4 "request_id": "2ed2d823-f8b3-416e-86db-ced8770ce217",5 "merchant_customer_id": "c9fafc2fb-4262-4ff8-a205-d60fb4781cb0",6 "first_name": "John",7 "last_name": "Doe",8 "email": "[email protected]",9 "phone_number": "+85298765432",10 "created_at": "2024-01-15T10:30:00Z"11}
Step 2: Create a Payment Consent
Create a Payment Consent with the Create a Payment Consent API API.
1curl -X POST https://api-demo.airwallex.com/api/v1/pa/payment_consents/create \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer {{ACCESS_TOKEN}}' \4 -d '{5 "request_id": "ed11e38a-7234-11ea-aa94-7fd44ffd1b89",6 "customer_id": "cus_uspd6m9zph9g2fjvn1r",7 "next_triggered_by": "merchant",8 "merchant_trigger_reason": "unscheduled"9 }'
Example response:
1{2 // ... other fields omitted.3 "id": "cst_sgstjgzhsh7hhmj8hr0",4 "request_id": "ed11e38a-7234-11ea-aa94-7fd44ffd1b89",5 "customer_id": "cus_uspd6m9zph9g2fjvn1r",6 "next_triggered_by": "merchant",7 "merchant_trigger_reason": "unscheduled",8 "created_at": "2024-01-15T10:35:00Z"9}
Step 3: Verify the Payment Consent
Verify the Payment Consent with the Verify a Payment Consent API API to authorize the shopper's Alipay HK account for future payments.
1curl -X POST https://api-demo.airwallex.com/api/v1/pa/payment_consents/{{PAYMENT_CONSENT_ID}}/verify \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer {{ACCESS_TOKEN}}' \4 -d '{5 "request_id": "139b8ee8-e306-47d6-8d6a-fa586967e5a9",6 "payment_method": {7 "type": "alipayhk"8 },9 "return_url": "https://www.airwallex.com"10 }'
Example response:
1{2 // ... other fields omitted.3 "id": "cst_sgstjgzhsh7hhmj8hr0",4 "request_id": "139b8ee8-e306-47d6-8d6a-fa586967e5a9",5 "status": "REQUIRES_PAYMENT_METHOD",6 "next_action": {7 "type": "redirect",8 "method": "GET",9 "url": "https://render.alipay.hk/p/h5..."10 }11}
Redirect the shopper to the URL provided in the next_action field to complete authorization in their Alipay HK app. Once the shopper completes authorization, the Payment Consent will be verified automatically, and Airwallex will notify you of the Payment Consent status asynchronously via webhook. Please refer to the webhook documentation to set up your webhook accordingly.
Initiating future payments
Step 1: Create a Payment Intent
When you are ready to process a recurring payment, create a Payment Intent with the Create a Payment Intent API API.
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": "2c343609-5561-4c39-b055-bdaf89176555",6 "amount": 20,7 "currency": "HKD",8 "merchant_order_id": "order_67890",9 "return_url": "https://www.airwallex.com"10 }'
Example response:
1{2 // ... other fields omitted.3 "id": "int_hkdmr7v9rg1j58ky8re",4 "request_id": "2c343609-5561-4c39-b055-bdaf89176555",5 "amount": 20,6 "currency": "HKD",7 "merchant_order_id": "order_67890",8 "status": "REQUIRES_PAYMENT_METHOD",9 "created_at": "2024-01-15T11:00:00Z"10}
Step 2: Confirm the Payment Intent with the Payment Consent
Confirm the payment with the verified Payment Consent by calling the Confirm a Payment Intent API API. This allows you to charge the shopper using their previously authorized Alipay HK account without requiring them to re-authenticate.
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 "payment_consent_id": "cst_sgstjgzhsh7hhmj8hr0",6 "request_id": "a7f3e2d1-9c4b-4e8a-b5f6-3d2c1a0e9f8b"7 }'