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.

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>,
}
);
obfuscatedAccountIdAndroidargument will be the Accesstypeoriginal_attempt_tokenfrom get subscription API response (step 2) as{attempt_token: <original-attempt-token-here>}obfuscatedProfileIdAndroidargument will be the Accestype attempt token from switch preview API response (step 3) as{attempt_token: <attempt-token-here>}purchaseTokenAndroidargument will be thepayment_tokenreceived in get subscription API response (step 2)- The value of
prorationModeAndroiddepends onproration_enabledvalue from get subscription API response (step 2):- For Recurring (googlepay autorenewing) subscription: if
proration_enabledistruethen passprorationModeAndroid=ProrationModesAndroid.IMMEDIATE_AND_CHARGE_PRORATED_PRICE - For Recurring (googlepay autorenewing) subscription: if
proration_enabledisfalsethen passprorationModeAndroid=ProrationModesAndroid.DEFERRED - For OneTime (googlepay prepaid) subscription, only allowed mode is:
prorationModeAndroid=ProrationModesAndroid.IMMEDIATE_AND_CHARGE_FULL_PRICE
- For Recurring (googlepay autorenewing) subscription: if
- ProrationModesAndroid is an enum present in react native iap package. Refer android billing library to understand different proration modes and their behaviour.