How to integrate with Google InApp Purchases?

Configuration steps:

After all the configurations are done, make below changes inside the App code:

  • List products from Play store
  • When user selects a product for purchase, Make preview API call to Accesstype with the sku of selected plan as subscription_plan_id. Ensure that payment_type for a subscription product is googlepay_recurring and for managed one-time product its googlepay. You will recieve an attempt_token in response of a successful preview API call.
  • Trigger purchase and make sure to send attempt_token received from the preview call in developer payload as {attempt_token: <attempt-token-here>}

Accesstype will listen to the real-time notification and create the subscription.

Configure payment gateway settings

You need to add jwt(it is the JSON file you get to download when you create a service account on GCP) and package name in Configure > Payment Gateways > Gpay.

Create subscription plans

Create a private subscription group. Add subscription plans. Make sure you create recurring or one time based on your requirement and that the desired assets are added.

Create inApp products in Google Play console

For each of the plans created above, you need to create one inApp product(managed product or subscription for one-time and recurring respectively) in google play console. While creating an inApp product, ensure that the product Id is same as Accesstype plan Id.

subscritption product id

plan id

Fill in all other details as required to create a product successfully. These details will be displayed to the end users while purchasing products.

Configure realtime notifications using Google Cloud pub sub.

Accesstype relies on real-time notifications to create/renew subscritions. You hvae to follow below steps to enable realtime notifications on google cloud.

  1. To configure, create a topic and subscription as described in set up pub-sub-notifications-guide.
  2. Enable real time notification from here

Ensure that you set Googlepay webhook URL of your accesstype account as the push endpoint URL.

webhook url

subscritption product id

How to send attempt token

If you are using react native iap package. you need to follow below code.

Requesting subscription on google iap

await requestSubscription(sku, false, undefined, undefined, undefined, <ACCESSTYPE_ATTEMPT_TOKEN>, <ACCESSTYPE_ATTEMPT_TOKEN>);

4th and 5th argument will be the Accestype attempt token.

Receiving the response and send purchase token in acknowledgePurchaseAndroid

const purchaseUpdateCallback = async (purchase, store) => {
  try {
    /* If consumable (can be purchased again) */
    await acknowledgePurchaseAndroid(purchase.purchaseToken);
    await finishTransaction(purchase, false);
    /* If not consumable, handle if consumable products come in */
    /* finishTransaction(purchase, false); */
  } catch (e) {
    console.error(`Finishing transaction failed`, e);