Airwallex logo

Low-level API integration

Allows you to build your own custom UI on top of our low-level APIs.

Copy for LLMView as Markdown

Step 1: (Optional) Create a Customer

Create a Customer object and pass it to your server if you want to save your customer's details and attach payment information to this object. Note that this step is compulsory when you process recurring payments for a new customer.

From your server, access Airwallex API to Create a Customer API.

Step 2: Create a PaymentIntent

Your client app will need a PaymentIntent to create a Session for Airwallex SDK to present a payment flow.

From your server, access Airwallex API to Create a PaymentIntent API and pass the returned PaymentIntent to the client app.

Step 3: Configuration and create Session

After setting up the SDK, configure it with the required parameters.

Configuration

Initialize the SDK in your Application class:

Kotlin
1Airwallex.initialize(
2 this,
3 AirwallexConfiguration.Builder()
4 .enableLogging(true) // Enable log in SDK, best set to false in release version
5 .saveLogToLocal(false) // Save logs locally
6 .setEnvironment(environment)
7 .setSupportComponentProviders(
8 listOf(
9 CardComponent.PROVIDER,
10 WeChatComponent.PROVIDER,
11 RedirectComponent.PROVIDER,
12 GooglePayComponent.PROVIDER
13 )
14 )
15 .build()
16)

Create Session

Create a Session with all the order related information:

Kotlin
1import com.airwallex.android.core.Session
2
3val session = Session.Builder(
4 paymentIntent = paymentIntent, // PaymentIntent created for this order
5 countryCode = "Your country code"
6)
7 .setReturnUrl("App return url")
8 .build()

For recurring transactions, set PaymentConsentOptions and ensure customerId is provided. See Prepare Session object for the full flow matrix.

For Google Pay, you need to add GooglePayOptions to the session. See Prepare Session object.

Kotlin
1val googlePayOptions = GooglePayOptions(
2 billingAddressRequired = true,
3 billingAddressParameters = BillingAddressParameters(
4 format = BillingAddressParameters.Format.FULL
5 ),
6 merchantId = "Your Google Pay Merchant ID"
7)
8
9val session = Session.Builder(
10 paymentIntent = paymentIntent,
11 countryCode = "Your country code",
12 googlePayOptions = googlePayOptions
13)
14 .setReturnUrl("App return url")
15 .build()

Step 4: Collect payment information using custom UI

For native UI integration, this step is handled by the Airwallex-provided UI. For low-level API integration, you must implement your own UI to collect all the information required for payment.

PCI-DSS compliance

For card payment, your app must be PCI-DSS compliant if using Confirm card payment with card and billing details flow. Provide a PCI-DSS AOC and renew it regularly.

For redirect payments, make sure you collect all the required information (e.g. shopper phone number, email) specified in the response from Get available payment method types API.

Step 5: Create Airwallex object and confirm payments

Create Airwallex object

Kotlin
1val airwallex = Airwallex(activity)

airwallex.confirmPaymentIntent(...) is deprecated. Use airwallex.checkout(...) for all card and consent-based payments, and airwallex.startGooglePay(...) for Google Pay.

Checkout with card and billing details

low-level-api-card

Kotlin
1import com.airwallex.android.core.Airwallex
2import com.airwallex.android.core.AirwallexPaymentStatus
3import com.airwallex.android.core.model.PaymentMethod
4import com.airwallex.android.core.model.PaymentMethodType
5
6val paymentMethod = PaymentMethod.Builder()
7 .setType(PaymentMethodType.CARD.value)
8 .setCard(
9 PaymentMethod.Card.Builder()
10 .setNumber("4012000300000021") // Card number collected by your custom UI
11 .setName("John Citizen")
12 .setExpiryMonth("12")
13 .setExpiryYear("2029")
14 .setCvc("737")
15 .build()
16 )
17 .setBilling(null) // Optional billing information
18 .build()
19
20airwallex.checkout(
21 session = session,
22 paymentMethod = paymentMethod,
23 cvc = "737",
24 saveCard = false, // Set to true to save the card as a consent while making the payment
25 listener = object : Airwallex.PaymentResultListener {
26 override fun onCompleted(status: AirwallexPaymentStatus) {
27 // Handle different payment statuses and perform UI actions accordingly
28 when (status) {
29 is AirwallexPaymentStatus.Success -> {
30 // Payment successful
31 }
32 is AirwallexPaymentStatus.InProgress -> {
33 // Payment in progress
34 }
35 is AirwallexPaymentStatus.Failure -> {
36 // Payment failed
37 }
38 is AirwallexPaymentStatus.Cancel -> {
39 // Payment cancelled
40 }
41 }
42 }
43 }
44)

Pass a PaymentConsent containing at least id and nextTriggeredBy to checkout(...).

Kotlin
1import com.airwallex.android.core.Airwallex
2import com.airwallex.android.core.AirwallexPaymentStatus
3import com.airwallex.android.core.model.PaymentConsent
4
5airwallex.checkout(
6 session = session,
7 paymentMethod = paymentMethod, // can be retrieved from other existing variable or paymentConsent.paymentMethod
8 paymentConsent = paymentConsent,
9 listener = object : Airwallex.PaymentResultListener {
10 override fun onCompleted(status: AirwallexPaymentStatus) {
11 // Handle different payment statuses and perform UI actions accordingly
12 }
13 }
14)

The paymentConsentId: String? parameter on airwallex.checkout(...) is deprecated and has been removed in SDK > 6.7.1. Pass a PaymentConsent object via the paymentConsent parameter instead — at minimum, provide id and nextTriggeredBy.

Pay with Google Pay

Make sure you have set up Google Pay correctly. See the Google Pay section in Prepare Session object.

Kotlin
1airwallex.startGooglePay(
2 session = session,
3 listener = object : Airwallex.PaymentResultListener {
4 override fun onCompleted(status: AirwallexPaymentStatus) {
5 // Handle different payment statuses and perform UI actions accordingly
6 }
7 }
8)

Pay by redirection

low-level-api-redirect

Use the redirect payment method for payment methods like Alipay, AlipayHK, DANA, GCash, Kakao Pay, Touch 'n Go, etc.

Kotlin
1airwallex.startRedirectPay(
2 session = session,
3 paymentType = "alipayhk", // Payment method type (e.g., "alipaycn", "alipayhk", "gcash", "dana")
4 listener = object : Airwallex.PaymentResultListener {
5 override fun onCompleted(status: AirwallexPaymentStatus) {
6 // Handle different payment statuses and perform UI actions accordingly
7 }
8 }
9)

Step 6: Handle payment result

After the payment is confirmed, the onCompleted callback will be invoked by the SDK automatically. You can check the status to see whether the payment process has completed or not.

The AirwallexPaymentStatus can be one of the following:

  • AirwallexPaymentStatus.Success - Payment completed successfully
  • AirwallexPaymentStatus.InProgress - Payment is still in progress
  • AirwallexPaymentStatus.Failure - Payment failed
  • AirwallexPaymentStatus.Cancel - Payment was cancelled
Kotlin
1listener = object : Airwallex.PaymentResultListener {
2 override fun onCompleted(status: AirwallexPaymentStatus) {
3 when (status) {
4 is AirwallexPaymentStatus.Success -> {
5 // Payment completed successfully
6 val paymentIntentId = status.paymentIntentId
7 // Show success message to user
8 }
9 is AirwallexPaymentStatus.InProgress -> {
10 // Payment is still in progress
11 // This might require further action from the user
12 }
13 is AirwallexPaymentStatus.Failure -> {
14 // Payment failed
15 val exception = status.exception
16 // Show error message to user
17 }
18 is AirwallexPaymentStatus.Cancel -> {
19 // Payment was cancelled by user
20 // Return to previous screen or show message
21 }
22 }
23 }
24}
Was this page helpful?