📜 ⬆️ ⬇️

Google Pay Integration

Hi, Habr!

My name is Igor, I'm an Android developer on the Trinity Digital team. Today I want to talk about the cool tool - Google Pay API .

Image from https://developers.google.com/payments/
')
So , if you can make purchases in your application, and at the same time you are not using In-app Billing (processing is not responsible for Google Play), then you most likely have “Payment by card” among the payment options. This means that every time you have to send a user to enter card data or on beautifully designed screens with a card, or on the website of your payment service provider (hereinafter - payment processor). Have you already counted how many actions the user will have to make in order to pay for the coveted order? Yeah, and now imagine that he can perform the same target action in just two tapas. We also introduced and thought, why not give users the opportunity? The main conditions for success - the seller must be registered with Google and the payment processor must cooperate with Google.

The list of Russian banks that cooperate with Android Pay:

AK Bars Bank
Alfa Bank
BINBANK
Promsvyazbank
VTB 24
Bank opening
MTS Bank
Raiffeisen Bank
Roketbank
Agricultural Bank
Russian Standard Bank
Sberbank
Tinkoff Bank
Point
Yandex money

How everything will look for the user : he gets on the screen for choosing the type of payment in your application, clicks on the button “Pay via Google”, selects the desired card or leaves the one specified by default, presses the confirmation button. Done!
Remember that Google Pay API allows users to select any card linked either to a Google account or added to Google Pay.

We now turn directly to the integration .

Consider the steps:

  1. Layout
  2. Code
  3. Testing
  4. Send for manual check
  5. Release

1. Layout


The first thing worth mentioning is to warn designers about guidelines . Briefly by points:


Compliance with these items will allow you to quickly pass all checks and get into the white list.

2. Code


For Google payment to work, Google Play Services must be version 11.4 or later on the user's phone. But do not worry, there is a special method that will tell you whether you can make a payment or whether it is worth hiding the button.

To begin with, add the necessary dependencies to the build.gradle of the application level. Before implementation, check the relevance of the versions!

dependencies { compile 'com.google.android.gms:play-services-wallet:11.4.0' compile 'com.android.support:support-v4:24.1.1' compile 'com.android.support:appcompat-v7:24.1.1' } 

Next, update AndroidManifest:

 <application> ... <!-- Enables the Google Pay API --> <meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true" /> </application> 

Now there is quite a bit:


That's all, in paymentData you will have a token that should be given to your server. Further logic depends on your payment processor.

3. Testing


Nothing complicated, just check that the WalletConstants.ENVIRONMENT_TEST constant is set , and go through the entire flow. There will be no debit from the card, you will receive a test token, so the payment processor must reject the payment.

4. Send to manual check.


Congratulations! You are ready to send your debug build for manual verification to Google.
Some tips:


Send the build to androidpay-api-support@google.com and wait for an answer.

5. Release


You were told that everything is good and you can release the application. First of all, you will be asked to activate the application at (from the merchant account).

Next you may be asked to send a PCI Compliance. These documents confirm that your payment processor complies with card security standards. Ask him and send in support.

Once you have completed these two items, you will be told that you can change WalletConstants.ENVIRONMENT_TEST to WalletConstants.ENVIRONMENT_PRODUCTION . You may also need to change the TOKENIZATION_PUBLIC_KEY if you used the key from the test environment of your payment processor.

That's all, now test the real payment and you can release a release to the market!

Thanks and good luck!

Source: https://habr.com/ru/post/347460/


All Articles