payments icon indicating copy to clipboard operation
payments copied to clipboard

`fetchSubscriptions` and `startSubscription` not defined for iOS

Open benedictstrube opened this issue 3 years ago • 11 comments

As I understand, for subscriptions we have to use fetchSubscriptions instead of fetchItems according to https://github.com/NativeScript/payments/issues/13#issue-1068957262. However, fetchSubscriptions is defined in the API but not implemented for iOS, therefore calling it leads to an error. Same for startSubscription. I suggest implementing it even though it seems not needed on iOS, but as it is part of the API, it should at least call the fetchItems functions on iOS side internally.

benedictstrube avatar Dec 09 '21 10:12 benedictstrube

Also in this context: what is startSubscription actually for? Is it semantically equivalent to buyItem and should be used instead for subscriptions?

benedictstrube avatar Dec 09 '21 10:12 benedictstrube

I also tried to use it on iOS and gave me an error. I'm not sure whether or not I'm supposed to use it for subscriptions rather than fetchItems.

jchavezberkeley avatar Dec 17 '21 00:12 jchavezberkeley

I confirmed that you can use buyItem for iOS for subscriptions. It's confusing, though. fetchSubscriptions and startSubscription should be set up for iOS, even if they act as an alias for other functions.

Also, for App Store subscription products, Apple provides subscriptionPeriod in the response to fetchItems. This field should be included in the event.payload object.

mreall avatar Jan 20 '22 18:01 mreall

@mreall Thank you for looking into this.

jchavezberkeley avatar Jan 20 '22 23:01 jchavezberkeley

@mreall I just came across this issue. Can you still confirm that subscriptions work for iOS using this plugin? I tried to load the subscription items using the fetchItems method like this:

const nsPaymentsPlugin = require("@nativescript/payments");

nsPaymentsPlugin.fetchItems(["12345", "67890"]);

But I only get an error message:

Invalid product identifiers: "12345, 67890".

Do you (or anyone else) have any advice?

felixkrautschuk avatar Jun 20 '23 14:06 felixkrautschuk

Just for anyone else coming across this: you have to follow this guide and create a StoreKit configuration file: https://www.revenuecat.com/blog/engineering/ios-in-app-subscription-tutorial-with-storekit-2-and-swift/#h-setting-up-app-store-connect then the fetchItems and buyItem methods can be used for subscriptions

felixkrautschuk avatar Jun 21 '23 15:06 felixkrautschuk

@felixkrautschuk I assume you got it working? I'm currently using this plugin for subscriptions using the fetchItems method and things are working fine.

brianrclow avatar Jun 21 '23 16:06 brianrclow

@brianrclow yes, at least when creating the StoreKit config file in xcode and when running the app via xcode after that. However, it does not work when running thenapp via ns run ios. Does that work for you?

felixkrautschuk avatar Jun 22 '23 12:06 felixkrautschuk

@felixkrautschuk Interesting, we were able to get up and running after following the steps listed here: https://github.com/NativeScript/payments/tree/main/packages/payments#readme Without any StoreKit config file, but we are using the fetchItems and not the fetchSubscriptions. Each time we can run iOS and while on a physical device use the sandbox user to access the subscriptions in Apple's sandbox mode. We created all of the subscriptions in appstoreconnect and make sure to reference the correct product ID to get them.

brianrclow avatar Jun 22 '23 18:06 brianrclow

@brianrclow thanks for your help, indeed the fetchItems/buyItem methods work on a physical device when creating a sandbox account (without StoreKit config file). You seem to have some experience with this plugin, so please allow me to ask you a few more questions, as I am still struggling with this plugin.

Sometimes I am able to successfully buy a subscription, I get the sandbox-confirmation dialog from iOS, and then I see the FINALIZING_ORDER event being triggered with SUCCESS as expected. BUT when keeping the app open and unused for some time, suddenly the FINALIZING_ORDER event is being triggered another time with a different orderId and restored = false, so it looks like I was manually buying a new subscription, but I didn't do anything.

In addition, when starting the app and fetching the subscription items, I am sometimes not able to buy a subscription, because of this line. pendingCount is greater than 0 (sometimes, 6, sometimes 24, ...), even though I just started the app and did not make any new subscriptions. Restarting the app and even reinstalling does not help, pendingCount still has the same value > 0 so I can't test any new subscriptions. I noticed, that calling restoreOrders helps in some situations.... This payment stuff on iOS is driving me crazy.

Did you experience something like this before?

felixkrautschuk avatar Jun 29 '23 11:06 felixkrautschuk

@felixkrautschuk Good questions, the iOS sandbox environment and process for testing subscriptions can be tricky. There are lots of steps and if things are not unsubscribed or cleared properly you can run into issues where you can't purchase another subscription properly. I haven't ran into an issue where when I leave it open, FINALIZING_ORDER runs and subscribes to another subscription. I know that pendingCount is pretty important and it can get mixed up if your app or sandbox user hasn't been cleared since you last sandbox purchase. That is something I have ran into before.

I can chat more about this over in the Official NativeScript Discord: https://discord.com/invite/RgmpGky9GR That is where most of the community is and it's easier to message back and forth without cluttering this GitHub issue. Join it and shoot a message in the #plugins channel 👍🏻

brianrclow avatar Jun 29 '23 16:06 brianrclow

Fixed in v3+

NathanWalker avatar Jan 15 '25 01:01 NathanWalker