How to request upgrade and downgrade of subscription in ios and android?
Please use Discussion board if you want get some help out of it. Please report issue if there is a bug.
Version of react-native-iap
^7.5.3
Version of react-native
0.66.1
Platforms you faced the error (IOS or Android or both?)
Both iOS and Android
Expected behavior
Not applicable
Actual behavior
Not applicable
Tested environment (Emulator? Real Device?)
Real Device
Steps to reproduce the behavior
We get the same error as mentioned in this link https://github.com/dooboolab/react-native-iap/issues/1099 , how can we proceed further? This should not close automatically.
To do this on iOS you need to set up your subscriptions in the same subscription group in App Store Connect - put them in order with the most valuable subscription at the top and the least valuable at the bottom - you can find instructions here: https://help.apple.com/app-store-connect/#/dev06f89ce98
The Play Store doesn't have subscription groups, so instead if you're wanting to upgrade/downgrade a subscription you need to provide the purchase token from the existing subscription to RNIap.requestSubscription. The documentation is here: https://react-native-iap.dooboolab.com/docs/api_reference/methods
but essentially you call:
RNIap.requestSubscription( SKU of the new subscription, false, the purchase token for the subscription you are upgrading from, The proration mode (e.g. IMMEDIATE_AND_CHARGE_PRORATED_PRICE) - make sure to import it from the RNIap module )
https://react-native-iap.dooboolab.com/docs/api_reference/methods this is now a dead link
@k8xian It is part of the migration to code-generated documentation. Please use https://react-native-iap.dooboolab.com/docs/api/modules in the meantime. Sorry for the inconvenience
can anyone confirm this is how we should use it today for android if we want to apply the immediate prorated price?
await requestSubscription({
sku: sku,
prorationModeAndroid: ProrationModesAndroid.IMMEDIATE_AND_CHARGE_PRORATED_PRICE,
subscriptionOffers: [
{
sku: sku,
offerToken: offerToken,
},
],
})
Because this parameter "prorationModeAndroid" doesn't seem to do anything, when I am subscribed to basic subscription, then want to subscribe to premium (more expensive) one, it asks me to pay full price.
What did I miss? They are two different offers from google play console, do I need to have a particular setup there?
@steven-sh you mentioned we should add the "purchase token", where can I find it?
@pierroo The subscription you're upgrading from should be returned in RNIap.getAvailablePurchases() and you can find the purchase token in the purchaseToken field on the object. Android needs this to know which subscription you're upgrading from, otherwise it will treat the upgrade as a new purchase and keep the original subscription active so the user will be subscribed to both at the same time.
that makes a lot of sense, thank you so much for taking the time @steven-sh !
Do you happen to know what to do with iOS?
Unfortunately not at all @oajh04 ; subscription on iOS is a complete mess and nearly impossible to properly test compared to android. I am still going through the struggle as we speak.
For my project I created a subscription group in AppStoreConnect and listed all the subscriptions in order (with the most expensive being the first and the cheapest being the last). Then the App Store knows that those SKUs are related and figures out itself that the customer is doing an upgrade/downgrade rather than purchasing a second subscription.
Testing subscriptions on iOS is a pain, but they do have the sandbox environment which is much better than it was before (as hard as that is to believe). Do remember to test re-subscribing to an expired subscription from outside your app! https://developer.apple.com/documentation/storekit/in-app_purchase/testing_in-app_purchases_with_sandbox/testing_an_auto-renewable_subscription
If someone looking for a code example with purchase token
export const getOfferToken = (subscriptions, productId) => {
const currentProduct = subscriptions.find(product => {
return productId === product.productId;
});
const offerToken = currentProduct.subscriptionOfferDetails[0].offerToken;
return offerToken;
};
const purchaseToken =
availablePurchases.length > 0 && availablePurchases[0]?.purchaseToken;
const offerToken = getOfferToken(subscriptions, sku);
const gradeSubParams =
Platform.OS === 'android' && purchaseToken
? { purchaseTokenAndroid: purchaseToken, prorationModeAndroid }
: {};
return await requestSubscription({
sku,
subscriptionOffers: [{ sku, offerToken: offerToken }],
...gradeSubParams,
});
Pay attention that upgrade/downgrade doesn't work without purchaseToken of subscription you upgraded from.
@lossen Is this work for both Android and iOS? Also offerToken token always there in the SKU response?
@steven-sh @nahmedpk Are we have any document flow or code flow?
@codal-mpawar as you can see from example gradeSubParams is only for android. As I understand for upgrade/downgrade on IOS we do not need to send that, we only need to order subscriptions on appstoreconnect.
@codal-mpawar Yes as long as you put all the subscriptions you're upgrading/downgrading to in the same subscription group in app store connect then you don't need to specify the current subsection in your app - Apple will figure that out for you. I don't have any particular documentation for this as I'm not a developer on this project so I can only suggest checking their official documentation: https://react-native-iap.dooboolab.com/docs/get-started
Thanks, it will great help for me.
Does anybody have an issue while trying to change the subscription on iOS devices? I'm using the requestSubscription and passing the SKU of the new subscription seems to update my subscription if I check it in the App Store section for my sandbox account but I receive on the purchaseErrorListener the following error:
{
"responseCode": "0",
"code": "E_UNKNOWN",
"debugMessage": "An unknown error occurred",
"message": "An unknown error occurred",
"productId": "_______"
}