Link

How to switch googlepay subscriptions?

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

Steps

Step 1.

In the response of Get All subscriptions API, check is_upgradable, is_downgradable and is_crossgradable boolean values for the subscription you want to switch, true means the subscription is upgradable, downgradable and crossgradable respectively.

Step 2.

Use Get Subscription Switchable Plans API to get a subscription with lists of upgradable, downgradable and crossgradable plans, this can be used to display list of plans available for switch, with prorated amount, to the user. The response of this API call contains subscription details along with payment_token, original_attempt_token, and list of plans available for upgrade, downgrade and crossgrade. prorated_amount_cents is the estimated proration amount and proration_enabled is the proration configuration in AT for current subscription plan.

Switchable Plan Details

Step 3.

Make Subscription switch Preview call, it returns attempt_token in response

Step 4.

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

Requesting subscription on google iap

await requestSubscription(
    {
          sku: sku,
          subscriptionOffers: [{ sku: sku, offerToken: offerToken }],
          purchaseTokenAndroid: <ACCESSTYPE_SUBSCRIPTION_PAYMENT_TOKEN>,
          prorationModeAndroid: <PRORATION_MODE>
          obfuscatedAccountIdAndroid: <ACCESSTYPE_ORIGINAL_ATTEMPT_TOKEN>,
          obfuscatedProfileIdAndroid: <ACCESSTYPE_ATTEMPT_TOKEN>,
        }
);

  • obfuscatedAccountIdAndroid argument will be the Accesstype original_attempt_token from get subscription API response (step 2) as {attempt_token: <original-attempt-token-here>}
  • obfuscatedProfileIdAndroid argument will be the Accestype attempt token from switch preview API response (step 3) as {attempt_token: <attempt-token-here>}
  • purchaseTokenAndroid argument will be the payment_token received in get subscription API response (step 2)
  • The value of prorationModeAndroid depends on proration_enabled value from get subscription API response (step 2):
    • For Recurring (googlepay autorenewing) subscription: if proration_enabled is true then pass prorationModeAndroid=ProrationModesAndroid.IMMEDIATE_AND_CHARGE_PRORATED_PRICE
    • For Recurring (googlepay autorenewing) subscription: if proration_enabled is false then pass prorationModeAndroid=ProrationModesAndroid.DEFERRED
    • For OneTime (googlepay prepaid) subscription, only allowed mode is: prorationModeAndroid=ProrationModesAndroid.IMMEDIATE_AND_CHARGE_FULL_PRICE
  • ProrationModesAndroid is an enum present in react native iap package. Refer android billing library to understand different proration modes and their behaviour.