Airwallex logo
Airwallex logo

Mobile App - TrueMoney

Accept TrueMoney 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.

POST /api/v1/pa/payment_intents/create

JSON
1{
2 "request_id": "ed11e38a-7234-11ea-aa94-7fd44ffd1b89",
3 "amount": 100,
4 "currency": "THB",
5 "merchant_order_id": "85d7b0e0-7235-11ea-862e-9f6aa1adfca6",
6 "return_url": "your_app_scheme://api/paymentId=...&status=..."
7}

Step 2. Obtain the payment URL

When a shopper selects to pay with TrueMoney on their mobile app, call the Confirm a Payment Intent API API to get a payment URL, which you can redirect the shopper to the TrueMoney app to complete the payment.

POST /api/v1/pa/payment_intents/{id}/confirm

JSON
1{
2 "request_id": "ed11e38a-7234-11ea-aa94-7fd44ffd1b89",
3 "payment_method": {
4 "type": "truemoney",
5 "TrueMoneycn": {
6 "flow": "mobile_app",
7 "os_type": "android"
8 }
9 }
10}

You will get a response similar to the following (package_name is only available for Android).

JSON
1{
2 // ... other fields omitted.
3 "next_action": {
4 "type": "redirect",
5 "method": "GET",
6 "url": "https://tmn.app.link/...",
7 "package_name": "th.co.truemoney.wallet"
8}

Step 3. Redirect to TrueMoney App to complete payment

You can use the url returned in the confirm Payment Intent response to redirect the shopper to the TrueMoney app. Shoppers will complete payment in the TrueMoney mobile app.

We recommend using the native method to check if the TrueMoney app is installed. On success, try invoking it natively. If invocation fails or if TrueMoney is not installed, switch to a WebView client to open the fallback URL. The logic is illustrated by the following code sample:

Andriod

Specify the package name in the <queries> tags of AndroidManifest.xml to enable access to the corresponding wallet app.

Kotlin
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="th.co.truemoney.wallet" />
8 </queries>
9 ...
10</manifest>

Redirect shoppers to the wallet app.

Kotlin
1val intent = Intent(Intent.ACTION_VIEW, url)
2intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
3intent.setPackage("th.co.truemoney.wallet")
4val activities = activity.packageManager.queryIntentActivities(intent, 0)
5
6// Check if the package is installed
7if (activities.size > 0) {
8 // Installed, launch the app in Android native way
9 try {
10 startActivity(intent)
11 } catch (e: Exception) {
12 // Exception is caught,launch the app within the Webview
13 startWebviewActivity(url)
14 }
15} else {
16 // Uninstalled, open the URL in the WebView
17 // Note: If the redirection occurs in the WebView, no further action is needed, simply load the url i.e, webView.loadUrl(url)
18 startWebviewActivity(url)
19}
20
21fun startWebviewActivity(url: Uri) {
22 val webviewIntent = Intent(activity, WebviewActivity::class.java)
23 webviewIntent.data = url
24 startActivity(webviewIntent)
25}

iOS

Redirect shoppers to the wallet app.

Swift
1// Check if the app is installed
2if UIApplication.shared.canOpenURL(url) {
3 // Installed, launch the app in IOS native way
4 UIApplication.shared.open(url)
5} else {
6 // Uninstalled, open the fallback URL in the WebView
7 // Note: If the redirection occurs in the WebView, no further action is needed, simply load the fallback url i.e, webView.load(url)
8 let safariVC = SFSafariViewController.init(url: url)
9 safariVC.delegate = self
10 self.navigationController?.present(safariVC, animated: true)
11}

After the customer completes payment, TrueMoney 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.

Was this page helpful?