NativeScript / payments

In-App Purchase, Subscriptions, Google Pay, Apple Pay for NativeScript
Apache License 2.0
34 stars 10 forks source link

`fetchSubscriptions` and `startSubscription` not defined for iOS #14

Open benedictstrube opened 2 years ago

benedictstrube commented 2 years ago

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 commented 2 years ago

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

jchavezberkeley commented 2 years ago

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.

mreall commented 2 years ago

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.

jchavezberkeley commented 2 years ago

@mreall Thank you for looking into this.

felixkrautschuk commented 1 year ago

@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 commented 1 year ago

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

brianrclow commented 1 year ago

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

felixkrautschuk commented 1 year ago

@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?

brianrclow commented 1 year ago

@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.

felixkrautschuk commented 1 year ago

@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 _FINALIZINGORDER event being triggered with SUCCESS as expected. BUT when keeping the app open and unused for some time, suddenly the _FINALIZINGORDER 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?

brianrclow commented 1 year ago

@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 👍🏻