In App Purchase with cordova-plugin-purchase 13 Subscription Upgrade or Downgrade

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.

Ionic:

Ionic CLI : 7.2.1 (C:\Users\bevin\AppData\Roaming\npm\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 8.4.3
@angular-devkit/build-angular : 19.2.0
@angular-devkit/schematics : 19.2.0
@angular/cli : 19.2.0
@ionic/angular-toolkit : 12.1.1

Capacitor:

Capacitor CLI : 7.1.0
@capacitor/android : 7.1.0
@capacitor/core : 7.1.0
@capacitor/ios : not installed

Utility:

cordova-res : not installed globally
native-run : 2.0.1

System:

NodeJS : v20.15.1 (C:\Program Files\nodejs\node.exe)
npm : 10.7.0
OS : Windows 10

1 Like

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.

GitHub - j3k0/cordova-plugin-purchase: In-App Purchase for Cordova on iOS, Android and Windows is a 3rd-party plugin so if you need additional help, your best bet would be to reach out to the maintainer.

Or switch to RevenueCat, it’s documented better and easier to use :grin:

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();
}
});
}

your assistance will be much appreciated.

Please use proper code blocks.

The link for the order method above shows the API for AdditionalData.

Like I said, if you cannot figure it out, your best bet is to reach out on the plugin repo.

Hi thanks for the assist, l would will do so.

Just for others out there who are facing the same issue as me or for educational purposes. I managed to find the upgrade and downgrade.

/** cordova-plugin-purchase/src/example/example.ts at 95e935c56b11ad0ed614f37a1979924ee41cc250 · j3k0/cordova-plugin-purchase · GitHub /
/
Upgrade or Downgrade line 83 */

Below is my code can be improved and the most important thing to keep in mind from the documentation on line 83

**// Replace an old purchase when finalizing the new one on google play.**

** store.order(product, {**
** googlePlay: {**
** oldPurchaseToken: ‘abcdefghijkl’,**
** prorationMode: CdvPurchase.GooglePlay.ProrationMode.IMMEDIATE_AND_CHARGE_PRORATED_PRICE,**
** }**
** });**