danielsogl/awesome-cordova-plugins

in-app-purchase-2 isn't compatible with latest version of cordova-plugin-purchase. Docs should be updated at minimum.

tomingoglia opened this issue · 29 comments

I'm submitting a ... (check one with "x")
[X] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use the discussions section https://github.com/danielsogl/awesome-cordova-plugins/discussions

Current behavior:
Regarding in-app-purchase-2
The current version of https://github.com/j3k0/cordova-plugin-purchase is 13.x. This has a breaking change from version 11. 11 seems to be the latest version that is supported by the capacitor in-app-purchase-2 wrapper. The root of the window object has been changed for the newer version. It also looks like there may be other breaking changes.

Expected behavior:
Please update the plugin to support the latest version of the library or update the documentation to specify the latest compatible version.
npm install cordova-plugin-purchase@11

Steps to reproduce:
Install without specifying version 11 will cause an exception that the Cordova plugin is not installed.
npm install cordova-plugin-purchase

Just to help someone in the same situation, I got it working in a dirty way. I'm using

npm @awesome-cordova-plugins/in-app-purchase-2@5.41.0 --force
npm cordova-plugin-purchase@11.0.0 --force

The --force option will install a theoretically uncompatible version of these plugins, so be careful and test it before to release.

Just to help someone in the same situation, I got it working in a dirty way. I'm using

npm @awesome-cordova-plugins/in-app-purchase-2@5.41.0 --force
npm cordova-plugin-purchase@11.0.0 --force

The --force option will install a theoretically uncompatible version of these plugins, so be careful and test it before to release.

You shouldn't need --force. It will just force a download from the remote location vs, using your cached version. They key is to ensure that the capacitor plugin is compatible with the cordova plugin. As indicated, version 11 works. If you don't specify, the latests is pulled and that is version 13.x. All the examples on the Ionic site and around the web were built before version 13.

I'm getting the same error on iOS after updating cordova-plugin-purchase to v13.1.5:

⚡️  [warn] - Native: tried calling InAppPurchase2.when, but the InAppPurchase2 plugin is not installed.
⚡️  [warn] - Install the InAppPurchase2 plugin: 'ionic cordova plugin add cordova-plugin-purchase'
⚡️  [warn] - Native: tried calling InAppPurchase2.DEBUG, but the InAppPurchase2 plugin is not installed.
⚡️  [warn] - Install the InAppPurchase2 plugin: 'ionic cordova plugin add cordova-plugin-purchase'

Hi,
I have the same identical problem.
The only solution is to downgrade the plugin:

npm install @awesome-cordova-plugins/core@5.45.0
npm install cordova-plugin-purchase@11.0.0
npm install @awesome-cordova-plugins/in-app-purchase-2@5.45.0

I also have to downgrade @awesome-cordova-plugins/core.

Hi, I have the same identical problem. The only solution is to downgrade the plugin:

npm install @awesome-cordova-plugins/core@5.45.0
npm install cordova-plugin-purchase@11.0.0
npm install @awesome-cordova-plugins/in-app-purchase-2@5.45.0

I also have to downgrade @awesome-cordova-plugins/core.

@losciur, I've been able to successfully use @awesome-cordova-plugins (both core and in-app-purchase) version 6.2.0. Are you getting some other error using that latest version with version 11 of cordova-plugin-purchase?

Yes, I had an error that now I can't reproduce, but kind of incompatibility with the @awesome-cordova-plugins/core version, for that reason I downgrade all the plugins.
In any case, today I retried to uninstall e reinstall all the plugins and you're right, it's only necessary to downgrade cordova-plugin-purchase: npm install cordova-plugin-purchase@11.0.0.
Sorry for the previous bad post, and thanks!

Ok, so there is no way to use in-app-purchase-2 with cordova-plugin-purchase 13 right now, correct?

There is no way to use it right now. In-app-purchase-2 has to be updated with new methods such as initialize() as opposed to using refresh(). I gave it an attempt but it was quite challenging for me. I hope someone can update the wrapper for this plugin to be compatible with v13 soon

There is no way to use it right now. In-app-purchase-2 has to be updated with new methods such as initialize() as opposed to using refresh(). I gave it an attempt but it was quite challenging for me. I hope someone can update the wrapper for this plugin to be compatible with v13 soon

I removed the in-app-purchase-2 and use only cordova-plugin-purchase 13. It is a bit more complex than with the angular wrapper, but I need to implement the new "offer" functionality in my app, to allow test periods for my subscriptions. And this is not supported by version 11.

Will the wrapper be updated for v13 of the plugin - is that planned at all, or should we look for alternatives / use cordova pluin directly?

tnx

j3k0 commented

I'm the author of the cordova plugin. Using the cordova plugin directly is a good alternative, from what I heard. What exactly "awesome-cordova-plugins" added that made it simpler? Maybe this can be built directly into the plugin?

@j3k0 awesome-cordova-plugins contains "a set of typescript wrappers around Cordova plugins that add niceties like promises and documentation around the hundreds of quality plugins in the Cordova ecosystem".

See this blog post for more background.

j3k0 commented

OK, version 13 of cordova-plugin-purchase now being fully written in typescript, and it ships with type definitions, this should be less a necessity. Except if I'm missing something.

OK, version 13 of cordova-plugin-purchase now being fully written in typescript, and it ships with type definitions, this should be less a necessity. Except if I'm missing something.

@j3k0 I can confirm that version 13 works almost perfectly by itself using Ionic Angular with Capacitor! I had to read carefully through the wiki for any Typescript headsups. The only issue I experience is the timing of the initialization of the CdvPurchase object in window object. According to the documentation, we can use a event deviceready which Cordova has. However, by using Capacitor this event does not exist. My current workaround is verifying in an interval whether window.CdvPurchase is not undefined, and when it is defined I execute the rest of the code. I tried using Ionic's Platform.ready() as I thought it would be the equivalent, but the window.CdvPurchase object is still undefined then.

What is your recommendation as alternative to the deviceready event? Or does cordova-plugin-purchase need a custom event for this? Or am I missing something?

j3k0 commented

Sorry I don't know what replaces deviceready on Capacitor. On Cordova, it's the event that's triggered once all plugins have been loaded. Capacitor should have something similar. If not, you can implement something like this:

function checkReady() {
  if (!window.CdvPurchase)
    setTimeout(checkReady, 100); // not loaded yet, check again in 100ms
  else
    deviceReady(); // plugin is available, call a "deviceReady()" function that you define.
}

checkReady(); // check if plugins are loaded already

Using ionic this.platform.ready seems to work for me:

constructor(private platform: Platform) {
    this.platform.ready().then(() => {
        const store: any = new window.CdvPurchase.Store();
        console.log('platform ready', store);
    });
}

Just not sure yet how to use the types but it's working.

j3k0 commented

I think if you just import the plugin, you should have the types.

import "cordova-plugin-purchase"

@j3k0 Indeed, found that on the doc a bit after my comment hehe.

j3k0 commented

To summarize:

  1. Install "cordova-plugin-purchase" directly with npm install cordova-plugin-purchase, no need for @awesome-cordova-plugins/in-app-purchase-2 anymore as the latest version includes typescript types.
  2. import "cordova-plugin-purchase/www/store.d" in your code to get the typescript types.
  3. Wait for ionic's this.platform.ready before initializing the plugin [1].

Ionic React and Vue don't have this.platform.ready, only Angular...

I asked how to handle this in the Capacitor forum.

In addition to providing TypeScript wrappers, in-app-purchase-2 gives devs something to import so that the plugin can be used easily in React and other frameworks. Cordova plugins aren't bundles so they can't be imported, right?

For me I don`t have any error to initialization but when uploading to Google Play, it says not compatible with BILLING VERSION 4. Is that related?