I have a question on Subscriptions. I have implemented the Subscription and you can easily subscribe on Google Pay and Backend saving the relevant information in the database. I’m having trouble on upgrading and downgrading a subscription. There is no reference in documentation l can see talking about this even in the documentation.
I need a user to be able to upgrade or downgrade not adding another subscription on top of another.
I believe you just call order and the respective store handles the upgrade/downgrade as long as your subscriptions are configured correctly.
On Android, I believe you need to also set the AdditionalData.googlePlay.oldPurchaseToken property and possibly AdditionalData.googlePlay.replacementMode though this issue mentions differently.
Normal subscription purchase works fine and the subscriptions are configured correctly. In order to upgrade there shld be a parameter or token that needss to be sent with the subscribe request.
Thats what l am not sure how to do.
The AdditionalData.googlePlay.oldPurchaseToken all this information is not in the documntation and how to do that. below is my subscribe button code
async subscribe(data: any) {
const loading = await this.loadingController.create({ message: ‘Please wait…’ });
loading.present();
console.log(data);
const googleProduct = data?.productID;
const product = CdvPurchase.store.get(googleProduct);
if (!product) {
console.log(‘Product not found!’);
loading.dismiss();
this.flashNotice(‘Product not found!’);
return;
}
product.getOffer()?.order().then((err: any) => {
if (err) {
console.log(err);
if (err.code === CdvPurchase.ErrorCode.PAYMENT_CANCELLED) {
console.log(‘Payment cancelled by user!’);
loading.dismiss();
this.flashNotice(‘Payment cancelled by user!’);
} else if (err.code === 6777003) {
loading.dismiss();
this.flashNotice(You are already subscribed to ${ this.product?.title});
} else {
loading.dismiss();
console.log(‘Failed to subscribe:’, err);
this.flashNotice(‘Failed to subscribe user’);
}
} else {
loading.dismiss();
}
});
}