Android APK Top Up API

The top up can occur in three different environments:

  • Payment integrator's Android app
  • Payment integrator's mobile website
  • Payment integrator's desktop website

Regardless of the flow, Google hands off the user interaction to the Payment integrator's software. The payment integrator implement a UI that feels familiar to the user, but the flow must be dedicated specifically to topping up the user's balance, meaning the user should be directed through a top up process rather than dropped into a general purpose UI where they would be expected to further navigate into a top-up flow.

All flows result in the integrator producing a TopUpRedirectResponse. This response is signed and sent back to Google.

The mobile and desktop websites must follow the Web Top Up API Specification, while the Android App flow must follow the Android Top Up API Specification.

Integrators should implement an Android APK solution to authenticate the user and then direct them through a flow where they can top-up their balance. This top up is a different modality, but the same purpose as the top up provided by the Web top up.

A user enters the flow on the payment integrator app via an Android Activity. The top up intent can be invoked directly from a Play app where the user is intending to make a purchase. To prevent Android from terminating Play in the background during the top up, the integrator needs to include the following in the activity theme.

<item name="android:windowIsTranslucent">true</item>

Method definition

The intent needs to have these properties:

Method properties
Action com.google.android.payments.standard.TOPUP_V1
Category android.intent.category.DEFAULT

Request

Fields
gspTopUpRequest TopUpRedirectRequest

Top-up request.

gspAssociationId string

Contains an identifier that the integrator uses to look up credentials for the account that the user is topping up. This is the association ID that is sent during account linking in the AssociateAccountRequest.

Response

After the user completes the top-up flow, your application needs to send a result intent back to Google. If the top-up is successful, create an intent and add the encrypted encoded gspTopUpResponse and redirectRequestId as extras. Next, set the activity result to the appropriate result code.

...
result.setExtra("gspTopUpResponse", gspTopUpResponse);
result.setExtra("redirectRequestId", redirectRequestId);
setResult(Activity.RESULT_OK, result);
...
finish();

Result

Fields
result int

Activity.RESULT_OK
Top-up was successful.
Activity.RESULT_CANCELED User canceled the flow manually and the flow should be aborted.
Activity.RESULT_FIRST_USER Top-up failed for a fatal reason and the flow should be aborted. IE server returned HTTP 500 response on login.

Extras

Fields
gspTopUpResponse TopUpRedirectResponse

REQUIRED: Top-up response. This encoded value must not exceed 1KB.
redirectRequestId string

REQUIRED: The requestId sent in the original/initiating redirect payment request. Google will verify this matches the sent requestId, and the Complete Redirect flow will fail if it doesn't match.

Other activity requirements

The activity that supports the above mentioned TOPUP_V1 action must also check that callers of the API only come from Google-signed applications. This will help prevent other apps from trying to invoke your activity and retrieve user data. This can be done by using the supplied StandardPaymentUtils.verifyCallingActivityIsGoogleSigned right after super.onCreate within your Activity implementation.

Here's a sample:


@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  StandardPaymentsUtils.verifyCallingActivityIsGoogleSigned(this);

  ....
}

All activities invoked within the top-up flow must supply an activity theme that has windowIsTranslucent=true. This must be done with the AndroidManifest android:theme attribute and not using Context.setTheme(). Programmatically, setting the theme doesn’t work correctly for window translucency. Google will enforce that the first activity launched follows this pattern but any sub activities that are also launched must also follow this pattern. If not, then purchases from 3rd party developers might not work.