Airwallex logo
Airwallex logo

Google Pay

This guide describes how to add Google Pay to your Airwallex Android SDK integration.

In addition to this, please refer additional material

  1. Google Pay API setup instructions
  2. Google Pay button brand guidelines
  3. Google Pay UX best practices

When setting up your Google 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

Step 1 : Install Google Pay component

SDK components are available through Maven Central, you only need to add the Gradle dependency.

To install the SDK, in your app-level build.gradle, add the following:

1dependencies
2{
3// It's required
4implementation 'io.github.airwallex:payment:4.1.0'
5
6// Select the payment method you want to support.
7implementation 'io.github.airwallex:payment-googlepay:4.1.0'
8}

Step 2 : Configure the SDK

We provide GooglePay parameter that can be used to debug the SDK, you can call it in Application. Please refer sample code below:

1Airwallex.initialize(
2 AirwallexConfiguration.Builder()
3 .enableLogging(true) // Enable log in sdk, and don’t forogt to set to false when it is ready to release
4 .setEnvironment(Environment.DEMO) // You can change the environment to STAGING, DEMO or PRODUCTION. It must be set to PRODUCTION when it is ready to release.
5 .setSupportComponentProviders(
6 listOf(
7 CardComponent.PROVIDER,
8 WeChatComponent.PROVIDER,
9 RedirectComponent.PROVIDER,
10 GooglePayComponent.PROVIDER
11 )
12 )
13 .build(),
14 ExampleClientSecretProvider() // If you need to support recurring, you must to support your custom ClientSecretProvider
15 )

Step 3 : Setup Google Pay on SDK

As a merchant you need to complete the registration with Google following the integration guidelines . Request production access to use Google Pay API once the integration checklist is complete.

Note : Do not fill information under direct integration section on Google Pay API business console , this is not required since Airwallex manages this on your behalf.

Configure your SDK with required options to process Google Pay transactions. Refer code sample below:

1val googlePayOptions = GooglePayOptions
2(
3 allowedCardAuthMethods = listOf("CRYPTOGRAM_3DS")
4billingAddressParameters = BillingAddressParameters(BillingAddressParameters.Format.FULL),
5 shippingAddressParameters = ShippingAddressParameters(listOf("AU", "CN"), true)
6 )
7val paymentSession = AirwallexPaymentSession.Builder
8(
9 paymentIntent = ...,
10 countryCode = ...,
11 googlePayOptions = googlePayOptions
12)

Step 4: Create a PaymentIntent

Your client app will need a PaymentIntent to form a payment 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 5: Present the payment sheet to shopper

Present the payment sheet to the shopper, Use presentPaymentFlow to complete the payment, you need to pass in a AirwallexSession object.

1private fun buildSession(
2 paymentIntent: PaymentIntent? = null,
3 customerId: String? = null
4): AirwallexSession {
5 return when (checkoutMode) {
6 AirwallexCheckoutMode.PAYMENT -> {
7 AirwallexPaymentSession.Builder(
8 paymentIntent = requireNotNull(
9 paymentIntent,
10 { "PaymentIntent is required" }
11 ),
12 countryCode = Settings.countryCode,
13 googlePayOptions = GooglePayOptions(
14 billingAddressRequired = true,
15 billingAddressParameters = BillingAddressParameters(BillingAddressParameters.Format.FULL),
16 merchantId = {PUBLIC_MERCHANT_ID}
17 )
18 )
19 .setReturnUrl(Settings.returnUrl)
20 .build()
21 }
22. . . .
23 }
24}

Step 6 : obtain the payment result

To obtain the payment result, you can use the retrievePaymentIntent method and check the latest status. Then you can prompt the shopper with the result.

1airwallex.retrievePaymentIntent(
2 params = RetrievePaymentIntentParams(
3 // the ID of the `PaymentIntent`, required.
4 paymentIntentId = paymentIntentId,
5 // the clientSecret of `PaymentIntent`, required.
6 clientSecret = clientSecret
7 ),
8 listener = object : Airwallex.PaymentListener<PaymentIntent> {
9 override fun onSuccess(response: PaymentIntent) {
10 onComplete.invoke(response)
11 }
12
13 override fun onFailed(exception: AirwallexException) {
14 Log.e(TAG, "Retrieve PaymentIntent failed", exception)
15 }
16 }
17 )

Customise googlePay options

You can customize the Google Pay options to restrict as well as provide extra context. For more information, please refer to GooglePayOptions class below:

1val googlePayOptions = GooglePayOptions(
2 allowedCardAuthMethods = listOf("3DS"),
3 merchantId = {PUBLIC_MERCHANT_ID},
4 billingAddressParameters = BillingAddressParameters(BillingAddressParameters.Format.FULL),
5 shippingAddressParameters = ShippingAddressParameters(listOf("AU", "CN"), true)
6 )

You can also overwrite color values in your app, refer link for more details.

1<color name="airwallex_tint_color">@color/airwallex_color_red</color>
Was this page helpful?