j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.29k stars 529 forks source link

cordova-plugin-purchase v13 not working on ionic 3 #1455

Closed rol4x4 closed 7 months ago

rol4x4 commented 9 months ago

Hi everyone, we use ionic 3 and the cordova-plugin-purchase plugin, this plugin worked normally until version 11, now due to the changes in Google we updated to version 13 but the plugin stopped working, it only shows Create CdvPurchase... and it doesn't go from there Could someone advise us? thanks.

MarcelSchuermann commented 9 months ago

Same. This looks like to be similar to issue #1442

tien271 commented 8 months ago

Version 13 will not work together with @ionic-native/in-app-purchase-2 but you can use the plugin directly. Just remove @ionic-native/in-app-purchase-2 then use CdvPurchase.store instead of inject the module and call this.store

dominic-simplan commented 8 months ago

Same here. Could it be because the CdvPurchase Object is set in a setTimeout callback: https://github.com/j3k0/cordova-plugin-purchase/blob/master/src/ts/store.ts#L719?

bahadir1981 commented 8 months ago

same problem , any solutions ?

j3k0 commented 7 months ago

It looks like most people make it work now, I don't know the issue nor solution to this unfortunately. With a bit more details maybe I could give pointers.

MarcelSchuermann commented 7 months ago

Maybe you need to look for correct case of the CdvPurchase objects (write them with a big letter f.e.) or define them like this: const { store, ProductType, Platform } = CdvPurchase;

Here is an example: #1442

Though, my product could still not be registered, like mentioned in the issue above.

j3k0 commented 7 months ago

Can anyone confirms that the plugin works with ionic 3, so we can close this issue?

rol4x4 commented 7 months ago

Hi @j3k0, the problem remains the same, I can't get it to work with ionic 3, I have tried the latest updates to the repository but it remains the same.

rol4x4 commented 7 months ago

These days I will try what @tien271 suggested although I am not sure how to proceed but I will try

tien271 commented 7 months ago

Hi @rol4x4 it is now working on my project, so

async registerAppProducts() { CdvPurchase.store.validator = (product: CdvPurchase.Validator.Request.Body, callback) => { //showLoader('Please wait while we process your order...'); const receipt = this.platform.is('android') ? (product.transaction as CdvPurchase.Validator.Request.ApiValidatorBodyTransactionGoogle).purchaseToken : (product.transaction as CdvPurchase.Validator.Request.ApiValidatorBodyTransactionApple).appStoreReceipt console.log('validator product', receipt) //Call your API this.inAppService.upgradePlan(...).then((res: any) => { if (res.status == 'success') { // callback when success callback({ ok: true, data: { id: product.id, latest_receipt: true, transaction: product.transaction as any } }) } }) } //register products PRODUCTS.forEach(product => { CdvPurchase.store.register({ id: product.id, platform: CdvPurchase.store.defaultPlatform(), type: CdvPurchase.store[product.type] }) }) await CdvPurchase.store.initialize(); await CdvPurchase.store.update(); }

j3k0 commented 7 months ago

Notice it's not necessary to call update after initialize.

await CdvPurchase.store.initialize();
// do not call update: initialize already does it...
// await CdvPurchase.store.update();

And handle case where trying to purchase a product that doesn't exists.

const product = CdvPurchase.store.get(productId);
if (!product) return alert("Product not found (might not be available in your country)");
if (product.canPurchase) { CdvPurchase.store.order(product.getOffer()); }

Full code example here: https://github.com/j3k0/cordova-subscription-example

rol4x4 commented 7 months ago

Hi @j3k0 @tien271, thank you for your suggestions, the problem is that my project is a little old and works with typescript 2.4.2, angular 5 and when directly importing the cordova-plugin-purchase it throws a lot of exceptions of typescript. I can't find any other way to have CdvPurchase.store available without going through Typescript verification in the build.

j3k0 commented 7 months ago

Maybe you could just do this:

declare CdvPurchase: any;

and use it in your code (without typescript types basically)

fellipefonseca commented 7 months ago

Hi, @rol4x4, Did you manage to solve it?

In Ionic 3 I believe it is correct to declare

const { store, ProductType, Platform: p } = CdvPurchase;

and import the plugin

import 'cordova-plugin-purchase';

However, the problem is to do ionic cordova build android --prod, as it gives some errors due to the fact that the project is in typescript 4 and we cannot reach this version in ionic 3 For example: ERROR in node_modules/cordova-plugin-purchase/www/store.d.ts:2485:23 - error TS1005: ',' expected.

putting the object like this: ype RawReceiptArgs = [ base64, bundleIdentifier, bundleShortVersion, bundleNumericVersio, bundleSignature ]; and putting the notation "skipLibCheck": true, in tsconfig.json it will compile, ignoring other problems that caused.

It worked on my phone, but in production we had many customers reporting a white screen and we had to return to version v11 for now to pause the problems

rol4x4 commented 7 months ago

Hi @fellipefonseca, thank you for sharing your code, I will try it, I have tried some codes but I still have some conflicts, what a shame until version 11 which worked perfectly, all that remains is to continue investigating to find the best solution.

rol4x4 commented 6 months ago

Hi @fellipefonseca, the solution for ionic 3 is already published in the readme file

fellipefonseca commented 6 months ago

Thanks, @rol4x4. Were you able to compile it in production without errors in node_modules?

rol4x4 commented 6 months ago

Hi @fellipefonseca , yes I had no problems building it in production.

fellipefonseca commented 6 months ago

It worked. Thank you