Closed rol4x4 closed 7 months ago
Same. This looks like to be similar to issue #1442
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
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?
same problem , any solutions ?
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.
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.
Can anyone confirms that the plugin works with ionic 3, so we can close this issue?
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.
These days I will try what @tien271 suggested although I am not sure how to proceed but I will try
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(); }
const product = CdvPurchase.store.get(productId);
if (product.canPurchase) { CdvPurchase.store.order(product.getOffer()); }
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
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.
Maybe you could just do this:
declare CdvPurchase: any;
and use it in your code (without typescript types basically)
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
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.
Hi @fellipefonseca, the solution for ionic 3 is already published in the readme file
Thanks, @rol4x4. Were you able to compile it in production without errors in node_modules?
Hi @fellipefonseca , yes I had no problems building it in production.
It worked. Thank you
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.