Mobile App - ShopeePay
Accept ShopeePay from your mobile app on your shopper's Android or iOS phone.
Step 1. Initialize a Payment Intent
Create a Payment Intent with the Create a Payment Intent API API.
The currency field must be one of: IDR, MYR, SGD, THB, PHP, or VND.
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": "ed11e38a-7234-11ea-aa94-7fd44ffd1b89",6 "amount": 10,7 "currency": "IDR",8 "merchant_order_id": "85d7b0e0-7235-11ea-862e-9f6aa1adfca6",9 "return_url": "{{YOUR_APP_SCHEME}}://callback"10 }'
Step 2. Confirm the intent to obtain the payment URL
When a shopper selects to pay with ShopeePay on their mobile app, call the Confirm a Payment Intent API to get a payment URL, which you can redirect the shopper to the ShopeePay app (or Shopee app in SG and VN) to complete the payment.
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": "ed11e38a-7234-11ea-aa94-7fd44ffd1b89",6 "payment_method": {7 "type": "shopeepay",8 "shopeepay": {9 "flow": "mobile_app"10 }11 }12 }'
Example response:
1{2 // ... other fields omitted.3 "next_action": {4 "type": "redirect",5 "method": "GET",6 "url": "https://api-demo.airwallex.com/pa/redirect/sg/sgstzhcbchcxzwiuvd8_w9a1j6?checksum=724f920e47be"7 }8}
Step 3. Redirect to ShopeePay/Shopee App to complete payment
You can use the url returned in the confirm Payment Intent response to redirect the shopper to the ShopeePay app (or Shopee app in SG and VN). Shoppers will complete payment in the ShopeePay mobile app. The following app schemes should be whitelisted:
| ID | MY | PH | SG | TH | VN | |
|---|---|---|---|---|---|---|
| Shopee App | shopeeid:// | shopeemy:// | shopeeph:// | shopeesg:// | shopeeth:// | shopeevn:// |
| ShopeePay App | shopeepayid:// | shopeepaymy:// | - | - | shopeepayth:// | shopeepayvn:// |
We recommend using the native method to check if the ShopeePay app (or Shopee app in SG and VN) is installed. On success, try invoking it natively. If invocation fails or if ShopeePay is not installed, switch to a WebView client to open the URL. The logic is illustrated by the following code sample:
Android
To redirect to ShopeePay or Shopee App on Android, you will need to use the package names com.shopeepay.id (Indonesia), com.beeasy.airpay (Thailand), com.beeasy.toppay (Vietnam), and com.shopeepay.my (Malaysia). Singapore and Philippines do not have the ShopeePay app and will return the package com.shopee.sg (Singapore) and com.shopee.ph (Philippines).
Specify the package name in the <queries> tags of AndroidManifest.xml to enable access to the corresponding app.
1<?xml version="1.0" encoding="utf-8"?>2<manifest xmlns:android="http://schemas.android.com/apk/res/android"3 xmlns:tools="http://schemas.android.com/tools"4 package="com.llw.scandemo">5 ...6 <queries>7 <package android:name="com.shopeepay.id" />8 </queries>9 ...10</manifest>
Redirect shoppers to the wallet app.
1val intent = Intent(Intent.ACTION_VIEW, url)2intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)3intent.setPackage("com.shopeepay.id")4val activities = activity.packageManager.queryIntentActivities(intent, 0)5// Check if the package is installed6if (activities.size > 0) {7 // Installed, launch the app in Android native way8 try {9 startActivity(intent)10 } catch (e: Exception) {11 // Exception is caught, launch the app within the WebView12 startWebviewActivity(url)13 }14} else {15 // Uninstalled, open the URL in the WebView16 // Note: If the redirection occurs in the WebView, no further action is needed, simply load the url i.e, webView.loadUrl(url)17 startWebviewActivity(url)18}19fun startWebviewActivity(url: Uri) {20 val webviewIntent = Intent(activity, WebviewActivity::class.java)21 webviewIntent.data = url22 startActivity(webviewIntent)23}
iOS
Redirect shoppers to the app.
1// Check if the app is installed2if UIApplication.shared.canOpenURL(url) {3 // Installed, launch the app in iOS native way4 UIApplication.shared.open(url)5} else {6 // Uninstalled, open the applink URL in the WebView7 // Note: If the redirection occurs in the WebView, no further action is needed, simply load the applink url i.e, webView.load(url)8 let safariVC = SFSafariViewController.init(url: url)9 safariVC.delegate = self10 self.navigationController?.present(safariVC, animated: true)11}
After the customer completes payment, ShopeePay (or Shopee app) will redirect the customer to your app, as dictated by the scheme URL specified in your return URL in the Create a Payment Intent API request.
Step 4. 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 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.