Question

Purchases.purchasePackage() doesn't return



Show first post

42 replies

Badge +1

@Bamba : Thanks for the update, it is appreciated.  Unfortunately the ‘minutes’ to update the status plays havoc with our ability to even get past the app store validation phase.

I have done the UI finessing that you mentioned in terms of a hint to log out and log back in but unfortunately this is (in my mind) a super unprofessional approach for someone who is making an application purchase in particular since the application can’t tell what phase the user is at with their interaction with the app store dialogs.  Unfortunately I’ve also seen this behaviour with a non-sandboxed version as well so that’s what really worries me is that this will become some ‘unknown’ behaviour in production.

Thanks,

 Thomas

Badge +6

Hi @tfletcher - thanks for sharing!

With Firebase, and Flutter, I have this loop while showing “Thank You!” screen (asking users to wait 5-10 seconds) with “logout” and “contact to support” buttons, this loop is run right after the (sync, “await”) call to “purchase”:

// this is just "compressed" snippet for illustrations only

CustomerInfo customerInfo =
await Purchases.purchasePackage(
myProductList[index]);

bool active =
customerInfo.entitlements.all['premium'] !=
null &&
customerInfo.entitlements.all['premium']!
.isActive;
if (active) {
Dialogs.thankYouForSubscribing();
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Please be patient...")));
Dialogs.thankYouForSubscribing();
}

for (var i = 0; i < 100; i++) {
await Future.delayed(Duration(seconds: 10),
() async {
// force token refresh to get updated claims
IdTokenResult idTokenResult = await FirebaseAuth
.instance.currentUser!
.getIdTokenResult(true);
if (/* premium subscription claim has been set up */ break;
}


Although customerInfo.entitlements.all['premium']! .isActive; is “true” after customer makes successful purchase, it is response from RevenueCat API.

I still need to wait for Firebase to update “claims”.  So that I have “loop” of 100, with 10 seconds interval.

Passing “true” .getIdTokenResult(true); enforces IdTokenResult (Firebase API) to be explicitly refreshed; otherwise it will use cached version, which, by default, refreshes once per hour.

And I also have registered listener which redirects user to “premium” content whenever “premium” claim received:

    FirebaseAuth.instance.idTokenChanges().listen(_idTokenChanges);

// _idTokenChanges will check "premium" claim:
Future<void> _idTokenChanges(User? u) async {
...

if (authStateChange) await _configureRevenueCatSDK(userId: u!.uid);

IdTokenResult idTokenResult = await u!.getIdTokenResult(
false); // "false": no refresh needed; otherwise we are in recursive loop of triggering "_idTokenChanges"

// now, find out if it is "premium" from IdTokenResult, and redirect to "premium" screen; otherwise redirect to "paywall":
...


I released my app about 10 days ago, and I have had no complaints so far. I believe “slowness” is only in SandBox; I saw similar messages in other forums.


So, two snippets above correspond to two execution threads: 1st one will explicitly force token refresh while showing “Thank you, please be patient”; and 2nd one will listen for token updates and redirect to either Paywall, or to Premium screens. In any case, this is needed: for example, billing issues & expired subscription, etc.

P.S. If you suspect something wrong with RevenueCat SDK, try the official Google example instead and compare results: https://codelabs.developers.google.com/codelabs/flutter-in-app-purchases 

Badge +2

I get the same warning:

This StoreProduct represents an SK1 product, the type of product cannot be determined, the value will be undefined. Use `StoreProduct.productCategory` instead.
 

purchases_flutter: 5.4.0

Badge +2

@Cesar could you please support us here?

Badge +2

In my case this issue appears only on iOS. On Android everything seems to work fine. Now on iOS, I have two subscriptions. An annual and a monthly. The annual one, works fine. But when a user chooses the monthly, I’m getting the following warning:

This StoreProduct represents an SK1 product, the type of product cannot be determined, the value will be undefined. Use `StoreProduct.productCategory` instead.

 

Userlevel 3
Badge +3

Does your `purchasePackage` function also not return? Is anything not working?

Those warnings are just indicating that the product’s productType will be `nonConsumable` because it can’t be determined and that should be accessing `productCategory` instead, so they should be safe to ignore. I think we will probably update that log since it’s clear it’s too noisy.

Userlevel 3
Badge +3

@Thanh Did you figure this out? We couldn’t reproduce purchasePackage not returning. We have identified an issue with purchaseProduct, but that seems unrelated

Userlevel 1
Badge +5

Hi Cesar, I haven’t tested on simulator as you said (using storekit config file) yet. Other than that the function does return on real iphones after setting Appstore shared secret.

Badge +2

Same issue here. Using Expo w. React Native.

When calling: `const result = await Purchases.purchaseStoreProduct(product)` Promise neither rejects nor resolves and thus subsequent statements are not executed.

This happens on physical iOS device. Haven’t tested on Android just yet.

Badge +2

Actually, I fixed my issue. I was mistakenly calling Purchases.configure mutliple times as the call was located in a custom hook.

I moved Purchases.configure outside my component tree into the root file and instead called Purchases.logIn inside my custom hook to add the appUserId.

Works as expected now on my end. 👍

Userlevel 3
Badge +3

Thanks for opening this question with more details. One quick question. Does this happen to you only on iOS? Have you tried on an Android device?

Are you running on a physical device or a simulator?

Thanks!

Userlevel 1
Badge +5

Hi @Cesar, I’m experiencing this on iOS only. I haven’t been able to test this on Android yet.

I tried on both physical iPhone and simulator, both stuck after tapping the package (which triggers the purchase function).

Badge +1

Getting same error on IOS Device at the same place as the poster (also not using android):

[Purchases] - WARN: 🍎‼️ There is a problem with the SKPaymentTransaction missing a transaction date - this is an issue with the App Store. Unix Epoch will be used instead.

Transactions in the backend and in webhooks are unaffected and will have the correct timestamps. This is a bug in StoreKit 1. To prevent running into this issue on devices running iOS 15+, watchOS 8+, macOS 12+, and tvOS 15+, you can set `usesStoreKit2IfAvailable` to true when calling `configure`.

 

I’m using flutter and had the following code:

await Purchases.setup("blahblahblah",    appUserId: LoginUser.userUid);

which was showing as deprecated.

So I updated to the new format found on the revenuecat website:

 await Purchases.configure(     PurchasesConfiguration("blahblahblah")       ..appUserID = LoginUser.userUid

and got the above error. 

Reverted back to the deprecated code and its working ok.

Userlevel 1
Badge +5

This looks related to my issue: https://github.com/RevenueCat/purchases-flutter/issues/431

Badge +6

I am experiencing the same issue with Flutter 6.3.0 MagicWeather example; tried to run in XCode, and the same debug messages:
This StoreProduct represents an SK1 product, the type of product cannot be determined, the value will be undefined. Use `StoreProduct.productCategory` instead.

 

https://github.com/RevenueCat/purchases-flutter/issues/875

 

Badge +6

but it still hangs on the iOS simulator.

 

That’s probably because iOS simulators require a special configuration using StoreKit config files. You can read more about that in this article in our docs https://docs.revenuecat.com/docs/apple-app-store#ios-14-only-testing-on-the-simulator

Do you mind giving that a try and report back?

The fact that purchasePackage doesn’t return is indeed a weird one, because I would expect it would throw an error indicating there’s a problem with your configuration in RevenueCat. We’ll look into that

 

This documentation link describes how to configure and use local App Store simulator (instead of actual App Store sandbox); but I need full integration test…

 

Fortunately, it works with real device (when I connect iPhone to Mac, and run it via XCode on real iPhone).

And today is Nov-18-2023, still unresolved, looks like bug from Apple.

I created this issue: https://github.com/RevenueCat/purchases-flutter/issues/875 - indeed it is not just “apple” ;)

For example, Flutter library in_app_purchase: ^3.1.1 doesn’t have such issue.

Badge +3

I am having this same issue. 

Reply