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

Purchases.purchasePackage(package) takes too long #693

Open
8 of 11 tasks
JustinWeru12 opened this issue May 19, 2023 · 36 comments
Open
8 of 11 tasks

Purchases.purchasePackage(package) takes too long #693

JustinWeru12 opened this issue May 19, 2023 · 36 comments
Labels
bug Something isn't working

Comments

@JustinWeru12
Copy link

JustinWeru12 commented May 19, 2023

Environment

  • Output of flutter doctor
    `[✓] Flutter (Channel stable, 3.7.12, on macOS 13.0.1 22A400 darwin-x64, locale en-GB)
    • Flutter version 3.7.12 on channel stable at /Users/mac/Code/Flutter/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4d9e56e694 (4 weeks ago), 2023-04-17 21:47:46 -0400
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/mac/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: /Library/Internet
Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
• Java version Java(TM) SE Runtime Environment (build 1.8.0_361-b09)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14E222b
• CocoaPods version 1.12.1

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
• Android Studio not found; download from
https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for
detailed instructions).

[✓] VS Code (version 1.78.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.64.0

[✓] Connected device (3 available)
• iPhone 14 Pro Max (mobile) • 0BC2EBC6-CF53-4D82-96C2-16475ED01166 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
• macOS (desktop) • macos • darwin-x64 •
macOS 13.0.1 22A400 darwin-x64
• Chrome (web) • chrome • web-javascript •
Google Chrome 113.0.5672.126

[✓] HTTP Host Availability
• All required HTTP hosts are available`

  • Version of purchases-flutter

4.12.0

  • Testing device version e.g.: iOS 15.5, Android API 30, etc.

iOS 16.4

  • How often the issue occurs- every one of your customers is impacted? Only in dev?
    DEV AND PROD

  • Debug logs that reproduce the issue

  • Steps to reproduce, with a description of expected vs. actual behavior
    Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)

Describe the bug

Our flutter/ios app is taking ~8 seconds to load the iOS payment page, on android it is instantaneous. The purchase goes through after the delay but the response also taker longer. This has barred us from deploying the app to apple store.

Additional context

Add any other context about the problem here.

@JustinWeru12 JustinWeru12 added the bug Something isn't working label May 19, 2023
@RCGitBot
Copy link
Contributor

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

@JustinWeru12 JustinWeru12 changed the title Purchases.purchasePackage(package) Purchases.purchasePackage(package) takes too long May 19, 2023
@HaleyRevcat
Copy link

Hi, this is happening from Apple's end. This is most likely from a iOS sandbox user with a lot of receipts so it is causing a delay. I recommend you try making a new sandbox user, this should remove the delay.

@JustinWeru12
Copy link
Author

Hello, this is happening in production. We are not using sandbox users.

@NachoSoto
Copy link
Contributor

Could you share debug logs when you reproduce the issue?

iOS app is taking ~8 seconds to load the iOS payment page

Could you describe what exactly takes 8 seconds? Is it the time from the user entering AppStore credentials or accepting the purchase until the time your flutter app receives the confirmation? Or the time between accepting the purchase and receiving the "purchase success" alert from iOS?

@babirms
Copy link

babirms commented May 23, 2023

Hello, I'm having the exact same problem.

When I click the button to make the purchase, in Android works perfectly, in iOs it takes ~4 to 5 seconds to show the Apple payment modal. It doesn't show any error on the console.

Lib version: 4.12.0

Flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.12, on macOS 13.3.1 22E772610a darwin-arm64
    (Rosetta), locale en-BR)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.78.2)
Scanning for devices is taking a long time...[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

@NachoSoto
Copy link
Contributor

It would be helpful if you could attached debug logs as well as the code you're using to call purchase. Thanks!

@babirms
Copy link

babirms commented May 23, 2023

I used await Purchases.purchasePackage(plan); to call when I click the button and then, it showed the following logs:

[Purchases] - DEBUG: ℹ️ Vending Offerings from cache
[Purchases] - INFO: 💰 Purchasing Product 'product' from package in Offering 'default_offering'
[Purchases] - DEBUG: ℹ️ Adding payment for product 'product'. 0 transactions already in the queue.
[Purchases] - DEBUG: ℹ️ StoreKit1Wrapper (0x00000002803d5260) updatedTransaction: product 0

@babirms
Copy link

babirms commented May 26, 2023

@NachoSoto hey! Do you have any updates on this? I'm still having this problem (same log as before)

@NachoSoto
Copy link
Contributor

My guess is the delay happens between the "adding payment" and "updated transaction" logs. Can you confirm that?

@armandojimenez
Copy link

Is there any update on this? seeing this in dev

@unilogica
Copy link

unilogica commented Jun 8, 2023

The delay on iOS is really too long. As a palliative solution, I block the UI with a loader and call the purchasePackage only after UI is already blocked, but there will be a loader layer on top of another loader in the bottom sheet, a weird experience, because I can't dismiss the first loader from the layer down and keep visible due to opacity from de second layer.

I also tested if it was possible to get the in app purchase screen from the hierarchy of components above, using an observable notification, but as it is native code it is not a simple task to detect when it is launched on the screen, and there isn't another method that triggers any action at the exact moment the native bottom sheet payment is shown.

@dimakrest
Copy link

It happens for me for both production and new sandbox user. After calling the purchasePackage function it takes ~ 7 seconds until iOS payment page loads.
Tested it both with 5.0.0 and 4.13.0

Since it takes a lot of time to load and complete the purchase the abandonment rate is very high and people do not complete payment!!
if there's no solution I would have to switch to other company

@NachoSoto
Copy link
Contributor

NachoSoto commented Jun 20, 2023

I just tested this and the delay is less than 1 second both on simulator (iOS 16.4) and on device (iOS 17.0 beta 1).
Also tested on the iOS 14.4 simulator with no issues.

When you reproduce this, could you pause the debugger on Xcode and send us a trace of what all the threads look like?

@NachoSoto
Copy link
Contributor

I just randomly saw this from a completely different app (not even Flutter).

I confirmed that the delay happens after we call SKPaymentQueue.add(payment), and none of the threads are locked or anything. Meaning the delay is entirely on Apple's side.

Also confirmed this happens even without our SDK, same delay on both StoreKit 1 and StoreKit 2.

I just filed FB12402539 to Apple including my device diagnostics. I recommend you do the same to maximize the chances of Apple fixing this.

@dimakrest
Copy link

@NachoSoto Thanks for the update

@fatherOfLegends
Copy link

@NachoSoto this is not a random delay, it is a consistent delay. We just updated from flutter_purchases: 4.11.1 to 5.3.0. The older version was not slow, the new version is slow. We are forced to upgrade soon but my company is concerned about this delay causing churn.

@pratikbaid3
Copy link

@NachoSoto I am facing the same issue. The await for purchase package never completes

@NachoSoto
Copy link
Contributor

I’d appreciate it if you could provide any additional details to help us debug this 🙏

@pratikbaid3
Copy link

@NachoSoto This is the logs that I get

[tcp] tcp_input [C1.1.1.1:3] flags=[R] seq=817168140, ack=0, win=0 state=LAST_ACK rcv_nxt=817168140, snd_una=3717549969
[tcp] tcp_input [C1.1.1.1:3] flags=[R] seq=817168140, ack=0, win=0 state=CLOSED rcv_nxt=817168140, snd_una=3717549969
[Purchases] - DEBUG: ℹ️ applicationDidBecomeActive
[Purchases] - DEBUG: ℹ️ applicationDidBecomeActive
[Purchases] - DEBUG: ℹ️ StoreKit1Wrapper (0x00000002809e3f00) updatedTransaction: rc_premium_monthly 2000000373185658 1
flutter: ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
flutter: │ #0   SettingsProvider.setListenerForInAppPurchases.<anonymous closure> (package:feedbackai/modules/settings/providers/settings_provider.dart:117:20)
flutter: │ #1   _RootZone.runUnaryGuarded (dart:async/zone.dart:1593:10)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 Purchase successful!
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[Purchases] - DEBUG: ℹ️ Found 0 unsynced attributes for App User ID: $RCAnonymousID:8f248f4495ab439ebe689ce73bf72647
[Purchases] - DEBUG: ℹ️ Force refreshing the receipt to get latest transactions from Apple.
[Purchases] - DEBUG: ℹ️ SKReceiptRefreshRequest started
[] nw_path_necp_check_for_updates Failed to copy updated result (22)
[Purchases] - DEBUG: ℹ️ StoreKit1Wrapper (0x00000002809e3f00) removedTransaction: rc_premium_monthly 2000000373185658 1
[Purchases] - DEBUG: ℹ️ StoreKit1Wrapper (0x00000002809e3f00) removedTransaction for (rc_premium_monthly but not callbacks to notify
<SKReceiptRefreshRequest: 0x282d474c0>: Finished refreshing receipt with error: Error Domain=ASDErrorDomain Code=603 "Request throttled" UserInfo={NSLocalizedFailureReason=Unified receipt is valid and current, NSLocalizedDescription=Request throttled, AMSServerErrorCode=0}
[Purchases] - DEBUG: ℹ️ SKReceiptRefreshRequest finished
[Purchases] - DEBUG: ℹ️ Loaded receipt from url file:///private/var/mobile/Containers/Data/Application/E9DB90F5-0134-40CE-B4E5-965698565CDB/StoreKit/sandboxReceipt
[Purchases] - DEBUG: ℹ️ Skipping products request for these products because they were already cached: ["rc_premium_monthly"]
[Purchases] - DEBUG: ℹ️ PostReceiptDataOperation: Started
[Purchases] - INFO: ℹ️ Parsing receipt
[Purchases] - INFO: ℹ️ Receipt parsed successfully
[Purchases] - DEBUG: ℹ️ PostReceiptDataOperation: Posting receipt (note: the contents might not be up-to-date, but it will be refreshed with Apple's servers):
{"opaque_value":"pCYb8zO+pl6OgoobmBlyaA==","original_application_version":"1.0","bundle_id":"ch.promptly.promptly","sha1_hash":"zHRryx2E\/eFIIUUGOqnkefvR8bw=","application_version":"48","creation_date":"2023-07-21T05:56:39Z","in_app_purchases":[{"product_id":"rc_premium_monthly","quantity":1,"transaction_id":"2000000373185658","is_in_trial_period":false,"is_in_intro_offer_period":false,"expires_date":"2023-07-21T06:01:30Z","web_order_line_item_id":2000000032360253,"original_purchase_date":"2023-07-21T05:56:38Z","original_transaction_id":"2000000373185658","product_type":3,"purchase_date":"2023-07-21T05:56:30Z"}]}
[Purchases] - DEBUG: ℹ️ There are no requests currently running, starting request POST receipts
[Purchases] - DEBUG: ℹ️ API request started: POST /v1/receipts
[Purchases] - DEBUG: ℹ️ API request completed: POST /v1/receipts (200)
[Purchases] - DEBUG: ℹ️ PostReceiptDataOperation: Finished
[Purchases] - INFO: 💰 Finishing transaction '2000000373185658' for product 'rc_premium_monthly'
[Purchases] - DEBUG: ℹ️ Serial request done: POST receipts, 0 requests left in the queue

Even if the purchase says completed, the await never completes

@NachoSoto
Copy link
Contributor

Can you send us the complete logs, including from SDK initialization?
Also, any chance you have any other StoreKit SDK in your app? (Example: RevenueCat/purchases-ios#2415 (comment))

@pratikbaid3
Copy link

  static configureSDK() async {
    if (Platform.isIOS || Platform.isMacOS) {
      StoreConfig(
        store: Store.appStore,
        apiKey: Constants.appleApiKey,
      );
    }
    await Purchases.setLogLevel(LogLevel.debug);

    PurchasesConfiguration configuration;
    if (StoreConfig.isForAmazonAppstore()) {
      configuration = AmazonConfiguration(StoreConfig.instance.apiKey)
        ..appUserID = null
        ..observerMode = false;
    } else {
      configuration = PurchasesConfiguration(StoreConfig.instance.apiKey)
        ..appUserID = null
        ..observerMode = false;
    }
    await Purchases.configure(configuration);
  }

@pratikbaid3
Copy link

pratikbaid3 commented Jul 21, 2023

I also have in_app_purchase

@NachoSoto
Copy link
Contributor

Do you mind filing a separate issue for that so we can keep this about slow StoreKit calls?

@pratikbaid3
Copy link

Sure @NachoSoto. I dont think it is slow, it never seems to be complete. I waited for 25 mins.

@NachoSoto
Copy link
Contributor

Yup, seems like a separare issue.

@pratikbaid3
Copy link

#768

@pratikbaid3
Copy link

@NachoSoto I think this might be related since the issues discussed in the thread here is exactly what we are facing

@Lyesbcb
Copy link

Lyesbcb commented Aug 9, 2023

Hello, I have the same issue only on IOS.

I use React native SDK.

The paiement popup are opening in less than 1 second on android but on IOS it's take 8 seconds !

I want to release my app but I can't do it with this delay.

Do you have idea ?

@NachoSoto
Copy link
Contributor

This is a known iOS issue, especially on sandbox.
We've filed a bug with Apple but have not heard back yet: FB12402539

I recommend filing more feedbacks directly with Apple. The more duplicate they get, the higher the chances they'll address it.

@Lyesbcb
Copy link

Lyesbcb commented Aug 9, 2023

This is a known iOS issue, especially on sandbox. We've filed a bug with Apple but have not heard back yet: FB12402539

I recommend filing more feedbacks directly with Apple. The more duplicate they get, the higher the chances they'll address it.

I just sent the version on Testflight and the delay is always so long!

I'm going to send to production like this, hope I don't lose too many customers :/

@djsjr
Copy link

djsjr commented Sep 11, 2023

Are there ANY flutter users for which this bug ONLY occurs in TestFlight (sandbox users) and not in production apps?

This issue is exactly like this one for the in_app_purchases plugin, except that OP claims it works fine in production.

I am releasing at app in a few weeks and can not have this long a wait for purchases! Any headway or more info on this? @HaleyRevcat @NachoSoto

@nguyen703
Copy link

Are there any updates on this issue? I encountered the same on iOS 17, iPhone XS Max :(

@TurkiTAK
Copy link

TurkiTAK commented Feb 3, 2024

I sent an update to my users and now stuck with this nonsense.
It's not even a delay it's just purely not working.

How the hell can this happen

@YonatanLeulseged
Copy link

I am having an issue where it gets to the Purchases.purchasePackage method and the app reaches out to Apple's end and never gets a response back. Passing in aPackage parameter that I've console logged and it has a package being sent. Getting this error:

tcp_input [C1.1.1.1:3] flags=4 seq=3,963,150,005, ack=0, win=0 state=8 rcv_nxt=3,963,150,005, snd_una=3,069,187,791

tcp_input [C1.1.1.1:3] flags=4 seq=3,963,150,005, ack=0, win=0 state=0 rcv_nxt=3,963,150,005, snd_una=3,069,187,791

tcp_input [C1.1.1.1:3] flags=4 seq=3,963,150,005, ack=0, win=0 state=0 rcv_nxt=3,963,150,005, snd_una=3,069,187,791

Has anyone ever gotten this before?

@atakangl
Copy link

I am facing the same issue.

Happens only on Apple iPhone.
I use flutter.
There is no issue seen. And not too long, method just does not respond.

I have transferred my app to another App Store developer account, and have transferred my app to another Revenuecat account. Issue started to happen in same day. No update released and no other changes in the day.

I have taken all required actions for transferring app. Webhook works fine. Users can purchase, webhook send to data to my server. But the method does not respond in client side.

@minhdanh
Copy link

minhdanh commented Oct 8, 2024

I added code to track the purchase time on production, and for iOS many purchases seem to take very long.
This is the code I used when a user starts purchasing a subscription:

                              final startPurchaseTime = DateTime.now();
                              setState(() {
                                isLoading = true;
                              });
                              try {
                                final CustomerInfo customerInfo = await Purchases.purchasePackage(packages![selectedPackageIndex!]);
                                final now = DateTime.now();
                                final parameters = {
                                  "status": "success",
                                  "user_id": user!.isFirebaseUser ? user.id : customerInfo.originalAppUserId,
                                  "package": packages![selectedPackageIndex!].storeProduct.identifier,
                                  "platform": Platform.operatingSystem,
                                  "time": now.difference(startPurchaseTime).inMilliseconds,
                                };
                               logAnalyticsEvent("user_purchased_subscription", parameters);
                              } on PlatformException catch (e, stackTrace) {
                                final errorCode = PurchasesErrorHelper.getErrorCode(e);
                                final customerInfo = await Purchases.getCustomerInfo();
                                final now = DateTime.now();
                                final parameters = {
                                  "status": "failed",
                                  "user_id": user!.isFirebaseUser ? user.id : customerInfo.originalAppUserId,
                                  "error_code": errorCode.toString(),
                                  "error_name": errorCode.name,
                                  "package": packages![selectedPackageIndex!].storeProduct.identifier,
                                  "platform": Platform.operatingSystem,
                                  "time": now.difference(startPurchaseTime).inMilliseconds,
                                };
                               logAnalyticsEvent("user_purchased_subscription", parameters);
                              }
                              setState(() {
                                isLoading = false;
                              });

Here you can see it took almost 51.4 seconds until the purchased is cancelled. I guess the user did not want to wait for more:
image

It should be noted that not all purchases take this long. Some finished in 13 seconds.
On Android it takes about 10 seconds, never seen a purchase took more than 50 seconds.

What can we do about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests