Our Google Pay Component renders Google Pay in your payment form. When the shopper selects Google Pay, Drop-in invokes the payment sheet, where shoppers select the card they want to use, and completes the payment.
When building your Google Pay integration, you also need to handle the redirect if the the shopper makes a payment with a card that requires 3D Secure authentication.
Before you begin
Before starting your Google Pay integration:
Show Google Pay in your payment form
To show Google Pay Component in your payment form, you need to:
-
Specify in your /paymentMethods request:
- countryCode: Country where Google Pay is supported. For example, NL.
- amount.currency: Any supported currency. For example, EUR.
-
Deserialize the response from the
/paymentMethods
call and get the object withtype
: googlepay. -
Add the Google Pay Component:
a. Import the Google Pay Component to your
build.gradle
file.implementation "com.adyen.checkout:googlepay:<latest-version>"
Check the latest version on GitHub.
b. Create a
GooglePayConfiguration
object, passing your client key. You can also include optional configuration, for example to add the amount on the Pay button.val amount = Amount() // Optional. In this example, the amount is EUR 10. amount.currency = "EUR" amount.value = 10_00 val googlePayConfig = GooglePayConfiguration.Builder(YourContext, "YOUR_CLIENT_KEY") .setAmount(amount) // When you're ready to accept live payments, change the value to one of our live environments (for example, Environment.LIVE). .setEnvironment(Environment.TEST) // Required for versions earlier than v4.5.0. When you're ready to accept live payments, change the value to ENVIRONMENT_PRODUCTION. .setGooglePayEnvironment(WalletConstants.ENVIRONMENT_TEST) .build()
c. Check if Google Pay is available on the shopper's device. If available, initialize the Component and present a Google Pay button according to Google Pay specifications.
var googlePayComponent: GooglePayComponent GooglePayComponent.PROVIDER.isAvailable(application, paymentMethod, googlePayConfiguration) { isAvailable: Boolean, paymentMethod: PaymentMethod, config: GooglePayConfiguration? -> if (isAvailable) { googlePayButton.visibility = View.VISIBLE googlePayComponent = GooglePayComponent.PROVIDER.get(YourContext, paymentMethod, googlePayConfiguration) } }
d. When the shopper selects the Google Pay button, call
startGooglePayScreen
.googlePayComponent.startGooglePayScreen(YourContext, googlePayRequestCode)
e. Pass the result to the Component, and wait to be notified by the observer.
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == googlePayRequestCode) { googlePayComponent.observe(YourContext) { googlePayComponentState -> if (googlePayComponentState?.isValid == true) { // When the shopper proceeds to pay, pass the `paymentComponentState.data` to your server to send a /payments request sendPayment(googlePayComponentState.data) } } googlePayComponent.handleActivityResult(resultCode, data) } }
Make a payment
When the shopper proceeds to pay, the Component returns the paymentComponentState.data.paymentMethod
.
- Pass the
paymentComponentState.data.paymentMethod
to your server. -
From your server, make a /payments request, specifying:
paymentMethod.type
: ThepaymentComponentState.data.paymentMethod
from your client app.browserInfo
: Required if you want to trigger 3D Secure authentication.returnURL
: URL where the shopper will be redirected back to after completing a 3D Secure authentication. Get this URL from the Component in theRedirectComponent.getReturnUrl(context)
.
The response contains the result of the payment.
If the shopper used a card that requires 3D Secure authentication before the payment can be completed, you receive an
action.type
redirect in the response.
- Pass the
action
object to your client app. You need this to initialize the Redirect Component.
Cards with 3D Secure: Handle the redirect
If the shopper makes a payment with a card that requires 3D Secure authentication, use the Redirect Component to redirect the shopper to another website to complete the authentication. After the shopper returns to your app, make a POST /payments/details request from your server, providing:
details
: TheactionComponentData.details
object from the Redirect Component.
You receive a response containing:
resultCode
: Use this to present the payment result to your shopper.pspReference
: Our unique identifier for the transaction.
Present the payment result
Use the resultCode
that you received in the /payments or /payments/details response to present the payment result to your shopper.
The resultCode
values you can receive for Google Pay are:
resultCode | Description | Action to take |
---|---|---|
Authorised | The payment was successful. | Inform the shopper that the payment has been successful. |
Error | There was an error when the payment was being processed. | Inform the shopper that there was an error processing their payment. The response contains a refusalReason , indicating the cause of the error. |
Refused | The payment was refused by the shopper's bank. | Ask the shopper to try the payment again using a different payment method. |
Recurring payments
To make recurring Google Pay payments, you first need to create a shopper token and then make subsequent recurring transactions with the token.
Refer to Tokenization for more information and detailed instructions.
Test and go live
To test Google Pay, log in to a Google account, create a Google Pay wallet and add the details for a real card.
When you test with this card it will be masked to one of our test cards, so there are no charges to your card. Your test transactions show test card details of the same brand in your Customer Area.
You can enrol your wallet in the Google Pay test card suite to use their test cards, which cover a limited number of scenarios. For example, you cannot test changes to your configuration in the PaymentDataRequest
object using the Google Pay test card suite because Google Pay API always returns the same output.
Currently, Google Pay wallets enrolled in the Test Card Suite return only full PAN tokens (FPANs) for test payments, and not device authenticated tokens AKA Cryptograms.
To test 3D Secure 2, you can use American Express or Discover cards, which trigger 3D Secure 2 challenge flows in the test environment. You cannot use any other card brands or any of Google Pay's test cards to test 3D Secure 2.
You can check the status of a Google Pay test payment in your Customer Area > Transactions > Payments.
For more information, see Google Pay's test environment for Android.
Before you go live
We recommend that you test the scenarios described in Google Pay’s API reference for Android in your live environment.
- Make sure your API credential has the API Clientside Encryption Payments role. Check this in your live Customer Area or ask your Admin user to verify.
- Go to your live Customer Area to configure your Google Merchant ID.
- Complete all the steps in the Google Pay API deploy to production documentation for Android.
In the live environment, note that Google Pay will only be available if:
- The shopper is logged in to their Google account.
- The shopper has at least one valid payment method on their Google Pay account.