Alipay+ DocsAlipay+ Docs

Auto Debit Integration Guide for Google

Introduction

Auto Debit occurs when a user purchases merchandise on a merchant platform and the merchant deducts funds from the user's account by using an access token. To use this payment product, the merchant must obtain the user's authorization in advance.

For Auto Debit payment for Google, the Alipay+ Android SDK encapsulates Google's Android APK Authentication API, so the authorization process is simplified.

Key capability

Help the user to handle the authentication process on the MPP side.

Before you begin

Make sure that you have added the Alipay+ Android SDK to your project. For more information about the installation procedures, see Get Started. You also need to implement showAuthPage API and getAuthCode API.

Implementation

Declare the activity for Auto Debit payment for Google

According to Google's document on Android Authentication, for Android native authentication, the integrator should implement an Android activity. But if you integrate Alipay+ Android SDK, which has already implemented the activity, you only need to declare the activity in Alipay+ Android SDK as follows in your AndroidManifest.xml file:

copy
// AndroidManifest.xml
<activity android:name="com.iap.android.mppclient.autodebit.GoogleAutoDebitActivity"
          android:theme="@style/AgsAuthenticationTheme">
  <intent-filter>
    <action android:name="com.google.android.payments.standard.AUTHENTICATE_V1"/>
    <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>
</activity>

// styles.xml
<style name="AgsAuthenticationTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">

  <!-- for Google Authentication
            To prevent Android from terminating Play in the background
            during authentication, the integrator needs to include the
            following in the activity theme. -->
  <item name="android:windowIsTranslucent">true</item>
</style>

The full process of Auto Debit payment for Google is:

  1. The user chooses the target MPP in Google Play.
  2. The user triggers the process of signing the contract in Google Play.
  3. Google Play jumps to MPP APP's activity which is implemented by Alipay+ Android SDK.
  4. If the authorization URL is constructed by MPP, Alipay+ Android SDK will call MPP's getAuthCode API to get the auth code. If the authorization URL is constructed by Alipay+, Alipay+ Android SDK will first call showAuthPage API to obtain the referenceAgreementId and then call getAuthCode API to get the auth code.
  5. Alipay+ Android SDK returns the result of signing contract process to Google Play at Google's request.