Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rol4x4 opened this issue Aug 15, 2023 · 19 comments
Closed

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

rol4x4 opened this issue Aug 15, 2023 · 19 comments

Comments

@rol4x4
Copy link

rol4x4 commented Aug 15, 2023

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
Copy link

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

@tien271
Copy link

tien271 commented Sep 6, 2023

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
Copy link
Contributor

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
Copy link

same problem , any solutions ?

@j3k0
Copy link
Owner

j3k0 commented Oct 16, 2023

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
Copy link

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
Copy link
Owner

j3k0 commented Oct 17, 2023

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

@rol4x4
Copy link
Author

rol4x4 commented Oct 17, 2023

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
Copy link
Author

rol4x4 commented Oct 17, 2023

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

@tien271
Copy link

tien271 commented Oct 18, 2023

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

  • If you are using @ionic-native/in-app-purchase-2, you have to remove it first since it is not work anymore then install the latest version of cordova-plugin-purchase
  • import the plugin: import 'cordova-plugin-purchase'
  • Register events: CdvPurchase.store.when().verified(this._verifiedHandler);
  • Add validator when purchasing and register all products:

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

  • To purchase a product:
    const product = CdvPurchase.store.get(productId);
    if (product.canPurchase) { CdvPurchase.store.order(product.getOffer()); }

@j3k0
Copy link
Owner

j3k0 commented Oct 18, 2023

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

@j3k0 j3k0 closed this as completed Oct 18, 2023
@rol4x4
Copy link
Author

rol4x4 commented Oct 18, 2023

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
Copy link
Owner

j3k0 commented Oct 20, 2023

Maybe you could just do this:

declare CdvPurchase: any;

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

@fellipefonseca
Copy link

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
Copy link
Author

rol4x4 commented Oct 20, 2023

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
Copy link
Author

rol4x4 commented Oct 24, 2023

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

@fellipefonseca
Copy link

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

@rol4x4
Copy link
Author

rol4x4 commented Oct 25, 2023

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

@fellipefonseca
Copy link

It worked. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants