Prepare Payment Session
This page covers the required and optional setup steps for integrating the Airwallex Android SDK.
Environment
When your app starts, configure the SDK with the appropriate environment in your Application class.
1import com.airwallex.android.Airwallex2import com.airwallex.android.core.AirwallexConfiguration3import com.airwallex.android.core.Environment45Airwallex.initialize(6 AirwallexConfiguration.Builder()7 .setEnvironment(Environment.DEMO) // .DEMO, .STAGING, .PRODUCTION8 .enableLogging(true)9 .build()10)
If you are using Hosted Payment Page, use AirwallexStarter.initialize() instead. For Embedded Payment Elements and Low-level API integration, use Airwallex.initialize() as shown above.
Create a customer
Generate or retrieve a customer ID for your user on your server-side. Refer to the Airwallex API documentation API for more details.
Optional if you only support guest checkout.
Create PaymentIntent
Your client app will need a PaymentIntent to form a payment session for Airwallex SDK to present payment flow.
From your server, access Airwallex API to Create Payment Intent API and pass the PaymentIntent returned to client app.
Create payment session object
The Airwallex Android SDK supports three types of payment sessions depending on your use case:
One-off payment session
Use this for single, non-recurring transactions where the payment amount and details are predetermined.
Option 1: Initialize with a pre-created payment intent
1import com.airwallex.android.core.AirwallexPaymentSession23val session = AirwallexPaymentSession.Builder(4 paymentIntent = paymentIntent, // Created on your server5 countryCode = "US"6)7 .setAutoCapture(true) // Optional: auto-capture after authorization (card only)8 .setReturnUrl("myapp://payment/return") // Optional: app return URL9 .build()
Option 2: Initialize with a payment intent provider (Express Checkout)
Using a PaymentIntentProvider allows the SDK to delay payment intent creation until just before payment confirmation or when clientSecret is required to request some Airwallex API.
1// 1. Implement PaymentIntentProvider2class MyPaymentIntentProvider : PaymentIntentProvider {3 override suspend fun createPaymentIntent(): PaymentIntent {4 // Call your backend to create the payment intent5 val response = MyBackendAPI.createPaymentIntent(6 amount = 99.99,7 currency = "USD"8 )9 return response.paymentIntent10 }11}1213// 2. Create session with the provider14val provider = MyPaymentIntentProvider()15val session = AirwallexPaymentSession.Builder(16 paymentIntentProvider = provider, // Payment intent will be created when needed17 countryCode = "US"18)19 .setAutoCapture(true)20 .build()
Recurring payment session
Use this for subscription-based or recurring charge scenarios where you manage the billing cycle.
Option 1: Initialize with customer details
1import com.airwallex.android.core.AirwallexRecurringSession23val session = AirwallexRecurringSession.Builder(4 customerId = customerId,5 clientSecret = clientSecret,6 currency = "USD",7 amount = 99.99,8 countryCode = "US",9 nextTriggerBy = nextTriggerBy // Next billing trigger type10)11 .setMerchantTriggerReason(MerchantTriggerReason.SCHEDULED) // Optional12 .setReturnUrl("myapp://payment/return") // Optional: app return URL13 .build()
Key parameters:
customerId: Customer ID from your backendclientSecret: Client secret from customer creationnextTriggerBy: Next billing trigger type (.CUSTOMERor.MERCHANT)
Option 2: Initialize with a payment intent provider (Express Checkout)
1class MyRecurringIntentProvider : PaymentIntentProvider {2 override suspend fun createPaymentIntent(): PaymentIntent {3 val response = MyBackendAPI.createRecurringPaymentIntent(4 customerId = customerId,5 amount = 99.99,6 currency = "USD"7 )8 return response.paymentIntent9 }10}1112val provider = MyRecurringIntentProvider()13val session = AirwallexRecurringSession.Builder(14 paymentIntentProvider = provider,15 customerId = customerId,16 clientSecret = clientSecret,17 currency = "USD",18 amount = 99.99,19 countryCode = "US",20 nextTriggerBy = NextTriggerBy.MERCHANT/CUSTOMER21).build()
Recurring payment with intent session
Use this to combine recurring billing with an explicit payment intent, useful for initial setup transactions in subscription flows.
Option 1: Initialize with a pre-created payment intent
1import com.airwallex.android.core.AirwallexRecurringWithIntentSession23val session = AirwallexRecurringWithIntentSession.Builder(4 paymentIntent = paymentIntent,5 customerId = customerId,6 clientSecret = clientSecret,7 currency = "USD",8 amount = 99.99,9 countryCode = "US",10 nextTriggerBy = nextTriggerBy11)12 .setMerchantTriggerReason(MerchantTriggerReason.SCHEDULED) // Optional13 .setReturnUrl("myapp://payment/return") // Optional: app return URL14 .build()
This variant links a specific payment intent to recurring payment arrangements, allowing you to capture an initial charge while establishing future billing authorization.
Option 2: Initialize with a payment intent provider (Express Checkout)
1class MyRecurringWithIntentProvider : PaymentIntentProvider {2 override suspend fun createPaymentIntent(): PaymentIntent {3 val response = MyBackendAPI.createRecurringWithIntentPayment(4 customerId = customerId,5 amount = 99.99,6 currency = "USD"7 )8 return response.paymentIntent9 }10}1112val provider = MyRecurringWithIntentProvider()13val session = AirwallexRecurringWithIntentSession.Builder(14 paymentIntentProvider = provider,15 customerId = customerId,16 clientSecret = clientSecret,17 currency = "USD",18 amount = 99.99,19 countryCode = "US",20 nextTriggerBy = NextTriggerBy.MERCHANT/CUSTOMER21).build()
WeChat Pay
To enable WeChat Pay:
- Make sure you add dependency for
payment-wechatmodule - Register your app at WeChat Pay to get a WeChat app ID
- Configure the WeChat app ID in your Airwallex account
During SDK initialization, ensure WeChatComponent.PROVIDER is added:
1import com.airwallex.android.Airwallex2import com.airwallex.android.core.AirwallexConfiguration34Airwallex.initialize(5 AirwallexConfiguration.Builder()6 .setEnvironment(Environment.DEMO)7 .setSupportComponentProviders(8 listOf(9 CardComponent.PROVIDER,10 WeChatComponent.PROVIDER, // Enable WeChat Pay11 RedirectComponent.PROVIDER12 )13 )14 .build()15)
After completing payment, WeChat will redirect to your app. The SDK handles the callback automatically and you will receive the payment result through the payment completion callbacks (onPaymentResult or PaymentResultListener).
Google Pay
To enable Google Pay:
- Make sure you add dependency for
payment-googlepaymodule - Set up Google Pay in your app. For more information, refer to Google's official documentation .
- Make sure Google Pay is enabled on your Airwallex account.
- Configure
googlePayOptionson the payment session object.
During SDK initialization, ensure GooglePayComponent.PROVIDER is added:
1import com.airwallex.android.Airwallex2import com.airwallex.android.core.AirwallexConfiguration34Airwallex.initialize(5 AirwallexConfiguration.Builder()6 .setEnvironment(Environment.DEMO)7 .setSupportComponentProviders(8 listOf(9 CardComponent.PROVIDER,10 GooglePayComponent.PROVIDER, // Enable Google Pay11 RedirectComponent.PROVIDER12 )13 )14 .build()15)
You can customize the Google Pay options and configure them on the payment session:
1import com.airwallex.android.googlepay.GooglePayOptions23val googlePayOptions = GooglePayOptions(4 allowedCardAuthMethods = listOf("PAN_ONLY", "CRYPTOGRAM_3DS"),5 merchantName = "Your Merchant Name",6 billingAddressRequired = true,7 billingAddressParameters = GooglePayOptions.BillingAddressParameters(8 format = GooglePayOptions.BillingAddressFormat.FULL,9 phoneNumberRequired = true10 )11)1213val session = AirwallexPaymentSession.Builder(14 paymentIntent = paymentIntent,15 countryCode = "US"16)17 .setGooglePayOptions(googlePayOptions) // Configure Google Pay options18 .build()
When setting up your Google Pay registration, use the following Airwallex details when you are requested to provide your gateway information to tokenize card details: gateway: airwallex gatewayMerchantId: Your merchant name as registered with Airwallex
We currently support the following payment networks for Google Pay: Visa, MasterCard, ChinaUnionPay, Maestro, Amex, Discover, and JCB. Coupon is not supported at this stage.
Redirect
For payment methods that require browser redirects (for example, Alipay, PayPal), you need to configure a return URL and handle the redirect flow.
Configure return URL
Set the return URL on your payment session. This URL is where the shopper will be redirected after completing the payment on the external payment provider's page:
1val session = AirwallexPaymentSession.Builder(2 paymentIntent = paymentIntent,3 countryCode = "US"4)5 .setReturnUrl("myapp://payment/return") // Configure your app's deep link6 .build()
Handle payment result
The SDK automatically handles the redirect flow. After the shopper completes the payment and is redirected back to your app, you will receive the payment result through the payment completion callbacks (onPaymentResult or PaymentResultListener).
A completed flow does NOT imply a successful transaction. You need to query the payment result afterwards through your server to confirm whether the payment was successful. From your server, retrieve the Payment Intent API, get the payment result within it and return it to client app.