Airwallex logo

Desktop Website Browser

Copy for LLMView as Markdown

Accept UPI payments on desktop, where the shopper scans a QR code with their UPI app to complete payment. UPI has different requirements depending on the goods you sell: for both physical and digital goods you must pass an invoice for every transaction, and for physical goods you must also pass an hs_code for each line item in order.products. For details on submitting and uploading invoices, see Invoices for UPI transactions.

Step 0. Create a customer (optional)

If the shopper is new, create a customer with the Create a Customer APIAPI and reuse the returned id (a cus_... value) as customer_id when you create the Payment Intent. This step is optional. If you already have a customer, or you prefer to pass the customer details inline, skip to Step 1.

Shell
1curl -X POST https://api.sandbox.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": "Aarav",
8 "last_name": "Sharma",
9 "email": "[email protected]",
10 "phone_number": "+919876501234"
11 }'

Response:

JSON
1{
2 // ... other fields omitted.
3 "id": "cus_hkdmr9ye6cxbmv8b8vg",
4 "request_id": "2ed2d823-f8b3-416e-86db-ced8770ce217",
5 "merchant_customer_id": "9fafc2fb-4262-4ff8-a205-d60fb4781cb0",
6 "first_name": "Aarav",
7 "last_name": "Sharma",
8 "email": "[email protected]",
9 "phone_number": "+919876501234"
10}

Step 1. Initialize a Payment Intent

Create a Payment Intent with the Create a Payment Intent APIAPI. The invoice number (order.invoice.number) is mandatory: UPI payments cannot be completed without it. If the invoice has already been uploaded with the file service, also include its file_id.

Note the following UPI-specific requirements:

  • Customer: pass the customer_id returned in Step 0, or pass the customer details inline as a customer object. If you do not provide the shopper's name, email, and phone number here, you must pass them at confirm as shopper_name, shopper_email, and shopper_phone. See Step 2.
  • Invoice: order.invoice.number is required for both physical and digital goods.
  • HS code: for merchants dealing in physical goods, you must pass an hs_code for each line item in order.products, and each hs_code must reflect the corresponding product. hs_code is not required for digital goods.
  • Shipping: for merchants dealing in physical goods, the shipping address is required, including street, city, state, postcode, and country_code. The shipping country_code must be IN.
Shell
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": "INR",
8 "customer_id": "cus_hkdmr9ye6cxbmv8b8vg",
9 "merchant_order_id": "85d7b0e0-7235-11ea-862e-9f6aa1adfca6",
10 "return_url": "https://www.airwallex.com",
11 "order": {
12 "invoice": {
13 "number": "INV-123456",
14 "file_id": "{{FILE_ID}}"
15 },
16 "products": [
17 {
18 "name": "trousers",
19 "hs_code": "123456"
20 },
21 {
22 "name": "t-shirt",
23 "hs_code": "456789"
24 }
25 ],
26 "shipping": {
27 "address": {
28 "street": "Mantri Apartment, Koramangala",
29 "city": "Bengaluru",
30 "state": "Karnataka",
31 "postcode": "560032",
32 "country_code": "IN"
33 }
34 }
35 }
36 }'

Alternatively, if you did not create a customer in Step 0, replace customer_id with an inline customer object:

JSON
1{
2 // ... other fields omitted.
3 "customer": {
4 "first_name": "Aarav",
5 "last_name": "Sharma",
6 "email": "[email protected]",
7 "phone_number": "+919876501234"
8 }
9 // ... other fields omitted.
10}

Step 2. Confirm the Payment Intent

When a shopper selects to pay with UPI on desktop, call the Confirm a Payment Intent APIAPI with the qrcode flow. Airwallex returns a QR code string and a fallback URL. Render the QR code for the shopper to scan with their UPI app.

If you did not provide the shopper's details when you created the Payment Intent, either through customer_id or an inline customer object, pass shopper_name, shopper_email, and shopper_phone in payment_method.upi at confirm. These fields are required when the equivalent customer details are not already on the Payment Intent, and can be omitted when they are.

Request:

Shell
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": "upi",
8 "upi": {
9 "flow": "qrcode",
10 "shopper_name": "Aarav Sharma",
11 "shopper_email": "[email protected]",
12 "shopper_phone": "+919876501234"
13 }
14 }
15 }'

Response:

JSON
1{
2 // ... other fields omitted.
3 "next_action": {
4 "type": "render_qrcode",
5 "qrcode": "281666040092rp7y8X52w1kpSE1k6VI2rqvj",
6 "url": "https://api.sandbox.airwallex.com/pa/redirect/in/instzhcbchcxzwiuvd8_w9a1j6?checksum=724f920e47be"
7 }
8}

Render the QR code image from next_action.qrcode and present it to the shopper, who completes payment by scanning it with their UPI app. If the QR code cannot be displayed, redirect the shopper to next_action.url instead. The QR code and the URL expire in 12 minutes.

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 APIAPI. You may start polling the Payment Intent status after the shopper is redirected back to your website, that is, the return_url passed when creating the Payment Intent.

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.

Was this page helpful?