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

fetchSubscriptions and startSubscription not defined for iOS #14

Open
benedictstrube opened this issue Dec 9, 2021 · 11 comments
Open

Comments

@benedictstrube
Copy link

As I understand, for subscriptions we have to use fetchSubscriptions instead of fetchItems according to #13 (comment). 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
Copy link
Author

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

@jchavezberkeley
Copy link

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

mreall commented Jan 20, 2022

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

@mreall Thank you for looking into this.

@felixkrautschuk
Copy link

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

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

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

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

brianrclow commented Jun 22, 2023

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

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

@brianrclow
Copy link
Contributor

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

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

5 participants