Solved

purchaseSubscriptionOption() not available for ionic?


Badge +1

Hi, I want to purchase a specific subscription offer from google play.

This should work as described here: https://www.revenuecat.com/docs/subscription-offers#more-control-over-offer-selection and here: https://github.com/RevenueCat/cordova-plugin-purchases/releases/tag/4.0.0

 

I did my setup for Ionic(Vue) + Capacitor as described here (https://www.revenuecat.com/docs/ionic)

I have the following dependencies installed:

@awesome-cordova-plugins/core@^6.3.0 @awesome-cordova-plugins/purchases@^6.3.0 cordova-plugin-purchases@^4.2.3 cordova-annotated-plugin-android@^1.0.4
 

In my App I am using

import { Purchases } from '@awesome-cordova-plugins/purchases';

and geht the typings from here:

node_modules/@awesome-cordova-plugins/purchases/index.d

(those seem to be incomplete! subscriptionOptions are not defined in the types I get)

 

BUT: In the results of “Purchases.getOfferings()” I get packages with products and those products have an array called “subscriptionOptions” with all my options listed. So the information is available!

 

But on my “Purchases” instance there is no function: purchaseSubscriptionOption()

Should this not be available? What am I doing wrong?

icon

Best answer by Andy 31 August 2023, 15:47

View original

12 replies

Badge +6

I am actually just looking at upgrading RevenueCat in our app (still running v2) and it looks like @awesome-cordova-plugins/purchases hasn’t been updated to support cordova-plugin-purchases@^4.0.0. It is still on version 3. The last PR is here to update it to v3.

Badge +6

Oh, it looks like there is an official Capacitor plugin (well soon to be official). Maybe we should switch to that. See this post - 

 

Userlevel 4
Badge +6

Hey @twestrick

Yes, sorry for the inconvenience, the Ionic SDK doesn’t yet use the Cordova version that supports Billing Client 5. As Andy mentioned in the post that you linked, we are looking forward to offering a more robust Capacitor in the fall.

Badge +1

@twestrick Thank you for linking the other topic. I was not aware of the fact that the recommended capacitor implementation (https://www.revenuecat.com/docs/ionic) relies on an external maintained projects wich is not up to date… (https://github.com/danielsogl/awesome-cordova-plugins/tree/master/src/%40awesome-cordova-plugins/plugins/purchases)

I think the docs should point this out!

So as far as I understand the RC team now recommends to use this project instead since it will be the official maintained one soon? https://github.com/Cap-go/capacitor-purchases/

Is this the case @kaitlin & @Andy ?

Importing and using the Package from ‘@capgo/capacitor-purchases’ does work partially.

I can get offerings and customer info. So my configuration seems to be correct. When trying to purchasePackage(p) the crashes without any report or error.?

Also a lot of functionality is missing (f.e. the function I want purchaseSubscriptionOption() )

I assume this project by cap-go is not yet up to date with the latest SDK version of cordova-plugin-purchases wich supports Billing Client 5?

Are there any other options to use Revenuecat in the latest version in my current setup?

  • Ionic Vue (+Typescript): 6.3.2
  • Capacitor: 5.0

@Tom McLellan mentioned here that he uses cordova-plugin-purchases npm library directly: 

I tried this:

import Purchases, { PurchasesPackage } from 'cordova-plugin-purchases';

My Editor is fine with this and shows Types but when starting the app I got the error that the project cannot find this module (it is there and installed)

Is this even possible? And if yes, why is a wrapper project like the two mentioned above even needed? Are they just there to wrap the callback functions into Promises? Sorry I am not very familiar with cordova / capacitor differences.

What are my options to use the latest version of RC?

I am quite confused and a bit frustrated since I already invested a lot of time implementing RC... Right now I am not sure if and how I can use RC for my project. (I really would like to, but my client has a deadline in mind for implementing in app purchases!)

Badge +6

I went down the rabbit hole the last two days going through all the options. I first switched to the Capgo plugin but then realized it was missing functionality I needed. I was going to PR an isAnonymous function but then realized it is also missing userCancelled when purchasePackage errors.

I then was going to try the cordova-plugin-purchases plugin directly but didn’t want to rewrite a whole bunch of stuff as my code base relies heavily on Promises. I am using Vite and had to change the package.json file of the Cordova plugin in order for it to build. I think I was getting a similar module missing error or something.

I ended up sticking with the awesome-cordova-plugins wrapper that uses v3 of the cordova-plugin-purchases and am waiting for an official Capacitor plugin to be released in the fall. An interim solution would be a PR to the awesome-cordova-plugins repo to upgrade to v4 of the Cordova plugin. From what I can see, there aren’t any breaking changes but hopefully the RevenueCat team could confirm and possibly help with the PR.

Badge +1

@twestrick Thank you for your lightning fast reply! Does make me not feel too alone with this trouble.

I did the exact same research you did with a simlar result but different reasons 😅

  1. @capgo option
    1. I could set this up, get offerings and user information but my app crashed instantly when trying to purchase a package without info (?)
  2.  cordova-plugin-purchases direct use option
    1. I was willing to wrap all functions in a generic written “promisify” wrapper to get around the callbackhell. But my compiler was complaining about missing module. Did you have this issue, too or didnt you go that far?
  3. Sticking with awesome-cordova-plugins
    1. I did create an issue to request a module update already: https://github.com/danielsogl/awesome-cordova-plugins/issues/4607

I would really love to get some official recommendation what to from RC Team, too.

Badge +6

Yeah, I did have some sort of module missing error when Vite was trying to build my project when using the Cordova plugin directly. I found this issue that gave me some insight - https://github.com/RevenueCat/cordova-plugin-purchases/issues/174.

If you change the Cordova plugin’s package.json file with the following things, it should work. I changed it in the node_modules folder temporarily just to see if it would work.

  • Change type to “module”, might work as is set to “commonjs” but didn’t try
  • Add main and set to ./www/plugin.js

Example

{
"name": "cordova-plugin-purchases",
"type": "module",
"version": "3.15.0",
"description": "Purchases Cordova Plugin",
"main": "./www/plugin.js",
"types": "./www/plugin.d.ts"
...
}

 

Badge +5

@nico-hof Regarding using  cordova-plugin-purchases npm library directly, I’ve doing this with an ionic/angular project with Capacitor 2.x. through 5.x. My main project.json file has a direct dependency (e.g. npm i cordova-plugin-purchases@3.13.0

 

For my purposes I’m not bothering with any typings and I’m trying to minimize dependencies. My typescript-based Angular service doesn’t have any import statements for the cordova plugin but instead just a declaration alongside my imports: 

declare var Purchases; // revenuecat plugin
 

If I understand correctly, the above line exposes window.Purchases as Purchases and lets me do calls like this without any typescript transpilation errors: 

Purchases.purchasePackage(rcPackage, (productIdentifier, purchaserInfo?) => {

   etc 

});


I’m in Angular, not sure if the same hold trues for Vue. ​​​

​​​
Just my experience, but I’ve found the “callback hell” is easier (with stuff like https://javascript.info/promisify)  than “dependency hell” related to the ionic awesome plugins project. They seem to run behind the latest updates. Anyway, traveling right now so may be slow to respond on any follow up questions but hopefully this is useful if you’re still considering the direct approach. 

Badge +1

Thanks both of you for the replies!

@kaitlin  & @Andy could we get some feedback from your team as RevenueCat Staff, too?

Badge +1

@Cesar maybe you can give some information about the future usage of @awesome-cordova-plugins/purchases.

Looks like you did the last version update for this plugin 🙂

Userlevel 5
Badge +8

Hey folks, I had missed this thread. We’re currently working on an official Capacitor plugin, should have something we can share by end of this week or next week. Stay tuned! 

Userlevel 5
Badge +8

Hey folks, update here: 

We have released the first beta of the capacitor plugin! https://www.npmjs.com/package/@revenuecat/purchases-capacitor. Please check it out and let us know if you run into any issues or feedback. We will finish the public documentation soon, so it's easier to implement.

 

cc @toni-rico 

Reply