Testing and Deploying Android Pay From An Unsupported Country

Would you like to support payments in your Android app? Android Pay could be the answer. Although it’s really simple and fast to implement, you know that nothing comes easy in the development world and Android Pay comes with a few challenges of its own.

tl;dr;

There is an hidden step that you must do to have production access to the Android Pay API that nobody mentions. Contacting support.

First let me tell you a little about the Android Pay API. It offers a quick and easy path to enable secure one touch payments in your app. The user can add credit cards to the Android Pay app and use them in compatible apps. Keep in mind that it doesn’t do everything, it only serves to facilitate the payment flow of your app, so you must have or obtain a payment processor like Stripe (which is the one we’ve used in a project here at Coletiv), that will be responsible for validating and processing all the payments.

That seems pretty easy, but if you’re not in one of the few supported countries by Android Pay you’re going to have a hard time.

That seems pretty easy, but if you’re not in one of the few supported countries by Android Pay (you can check the list here) you’re going to have a hard time implementing and testing the payment flow like we did here in Portugal.

Before I start telling you the challenges we’ve faced to implement Android Pay while working from an unsupported country let me explain a bit more about the payment flow. It’s pretty simple.

  • First you should setup your project and install all the dependencies;
  • After that you add the Android Pay button. Don’t forget to follow the branding guidelines.
  • In your checkout activity, before starting the payment flow, you must see if the user is ready to pay, and hide/show the android pay button accordingly.
  • If the user is ready and tapped the button, the app requests the Masked Wallet which contains partial information such as billing address, shipping address, masked backing payment instrument number, and cart items. The app uses this information to present order review screens and other options. Don’t forget to add your payment processor information into the parameters of this request. This might vary based on which payment processor you’re using.
  • If everything is good, the app makes a Full Wallet request where you will obtain a Token object that you can convert to JSON and send to your backend like this:
PaymentMethodToken token = fullWallet.getPaymentMethodToken();
JSONObject tokenJson = new JSONObject(token.getToken());
tokenJson.getString("encryptedMessage")
  • Finally you use this token with your payment processor to finalize the purchase flow.

You can follow a more detailed step-by-step guide with code in the official Android Pay documentation.

After you have the payment flow implemented in your app you must test it right? If you’re in a supported country that will be no problem. You can download the Android Pay app add a credit card and test right away. But if you’re not?

Unless you have an account in one of the supported countries there is no way for you to add a valid credit card, and Google doesn’t seem to provide dummy cards to test.

The only thing that you can do in this case is to use a VPN in your test device. I’m using Tunnel Bear app to connect to different countries. After this you can download the Android Pay app, but you’ll have another problem: the credit card. Unless you have a bank account in one of the supported countries there is no way for you to add a valid credit card, and for what I know, Google doesn’t provide dummy cards to test. In our case it was our client who provided us one.

If you’ve managed somehow to get a valid credit card in the Android Pay app you can start testing your app right away.

To use the test environment you must sign your app with a debug key and use the test keys of your payment processor.

The payment flow has two environments. Test, check your flow and make purchases that won’t be charged, and Production, that will charge the payment. Please note that to use the test environment you must sign your app with a debug key and use the test keys of your payment processor. It won’t work if you sign your app apk file with any other key.

After you’ve tested the payment flow with this environment you should test the Production environment. In this case the app must be signed with release keys. Even after doing this, you will see that you can’t make a single purchase using the production environment even if it’s working in the test environment.

It’s a shame that there’s no information anywhere in the documentation about gaining production access. You have no other solution than contacting the google android pay support.

It’s a shame that there’s no information anywhere in the documentation about this but you have no other solution than contacting the google android pay support using this email androidpay-api-support@google.com. At least they respond pretty quickly and are very helpful answering any question you might have and guiding you through all the process.

They will give you access to this URL where you’ll be asked to fill a form with some information about your app and your business and then, after they validate everything, you will have access to the production environment and can test live transactions.

After all this trouble, you should have your app fully working with Android Pay and can upload it with confidence to the Play Store.

I wish I had known all these things before starting developing this feature, it was a long process until I’ve got the app working with Android Pay. So I hope this article can help you setup your app’s purchase flow more smoothly and with more confidence in what you’re doing.