Skip to content

[in_app_purchase] Cannot start a new purchase after cancelling on iOS 14 #66886

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

Closed
zodiark23 opened this issue Sep 29, 2020 · 21 comments
Closed
Labels
e: OS-version specific Affects only some versions of the relevant operating system p: in_app_purchase Plugin for in-app purchase package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically

Comments

@zodiark23
Copy link

zodiark23 commented Sep 29, 2020

Since iOS 14 I can't seem to finishTransaction for failed purchases. This will happen if you buy a product then cancel it, this one will stay on SKPaymentTransactionQueue. However re-running the debugger will clear out the transactions.

Steps to reproduce:

  1. Buy a product
  2. Cancel the payment screen.
  3. Buy the product again, nothing will happen (Payment Dialog will not pop out)

I tried this with in_app_purchase v0.3.4+8 and v.0.3.4+9 same thing.

Previously before iOS 14 this is not happening. Need help please.

Previously just by calling .completePurchase() for iOS its working properly.
I'm also clearing the SKTransactionQueue with this code

Future<void> clearIOSTransactions() async {
    // clear the transaction queue for failed completeTransaction or finishTransaction
    final transactions = await SKPaymentQueueWrapper().transactions();
    print("SkTransactionCount: ${transactions.length}");
    for (final transaction in transactions) {
      if (transaction.transactionState !=
          SKPaymentTransactionStateWrapper.purchasing) {
        await SKPaymentQueueWrapper().finishTransaction(transaction);
      }
    }
  }
@darshankawar
Copy link
Member

@zodiark23
Please provide flutter doctor -v.
Thanks.

@darshankawar darshankawar added in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels Sep 29, 2020
@zodiark23
Copy link
Author

@darshankawar

✓] Flutter (Channel beta, 1.22.0-12.1.pre, on Mac OS X 10.15.6 19G2021, locale en-PH)
    • Flutter version 1.22.0-12.1.pre at /Users/reyan/Documents/Development/flutter
    • Framework revision 8b3760638a (2 weeks ago), 2020-09-15 17:47:13 -0700
    • Engine revision 4654fc6cf6
    • Dart version 2.10.0 (build 2.10.0-110.3.beta)


[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/reyan/Library/Android/sdk
    • Platform android-29, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.0, Build version 12A7209
    • CocoaPods version 1.9.1

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 31.3.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] IntelliJ IDEA Ultimate Edition (version 2020.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 46.0.3
    • Dart plugin version 201.7223.43

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

[✓] Connected device (1 available)
    • Reyan’s iPhone (mobile) • 9XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1 • ios • iOS 14.0
    ! Error: Reyan’s iPhone is busy: Copying cache files from device. Xcode will continue when Reyan’s iPhone is finished. (code -10)

• No issues found!

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 30, 2020
@zodiark23
Copy link
Author

zodiark23 commented Sep 30, 2020

If it helps i can see this error logs when i run the code via xcode ( since i can't run it on debug just white screen)

2020-09-30 15:05:56.145736+0800 Runner[3063:993843] flutter: Purchase Status: PurchaseStatus.pending
2020-09-30 15:06:00.920292+0800 Runner[3063:995011] <SKPaymentQueue: 0x283611000>: Payment completed with error: Error Domain=ASDErrorDomain Code=907 "Unhandled exception" UserInfo={NSUnderlyingError=0x283b0fb70 {Error Domain=AMSErrorDomain Code=6 "Payment Sheet Failed" UserInfo={NSLocalizedDescription=Payment Sheet Failed, NSLocalizedFailureReason=Payment sheet cancelled}}, NSLocalizedFailureReason=An unknown error occurred, NSLocalizedDescription=Unhandled exception}
2020-09-30 15:06:00.925677+0800 Runner[3063:993843] flutter: Purchase Status: PurchaseStatus.error
2020-09-30 15:06:00.935201+0800 Runner[3063:993843] [VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: PlatformException(storekit_invalid_argument, Argument type of finishTransaction is not a string., null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
<asynchronous suspension>
#2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
#3      SKPaymentQueueWrapper.finishTransaction (package:in_app_purchase/src/store_kit_wrappers/sk_payment_queue_wrapper.dart:106:19)
#4      AppStoreConnection.completePurchase (package:in_app_purchase/src/in_app_purchase/app_store_connection.dart:68:10)
#5      StoreBloc._listenToPurchaseUpdated.<anonymous closure> (package:volumeup/blocs/storeBloc.dart:169:18)
#6      List.forEach (dart:core-patch/growable_array.dart:313:8)
#7      StoreBloc._listenToPurchaseUpdated (package:volumeup/blocs/storeBloc.dart:155:25)
#8      StoreBloc.initialState.<anonymous closure>.<anonymous closure> (package:volumeup/blocs/storeBloc.dart:82:9)
#9      _rootRunUnary (dart:async/zone.dart:1198:47)
#10     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#11     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
#12     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
#13     _DelayedData.perform (dart:async/stream_impl.dart:611:14)
#14     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:730:11)
#15     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:687:7)
#16     _rootRun (dart:async/zone.dart:1182:47)
#17     _CustomZone.run (dart:async/zone.dart:1093:19)
#18     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#19     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#20     _rootRun (dart:async/zone.dart:1190:13)
#21     _CustomZone.run (dart:async/zone.dart:1093:19)
#22     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#23     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#24     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#25     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

I think this is the reason why its failing to complete those failed transaction via .completePurchase or .finishTransaction when you just cancel the payment screen.

@darshankawar
Copy link
Member

@zodiark23 thanks for the logs.
Can you upgrade to latest beta and check again ? There were few issues resolved to iOS14 in latest version.
Thanks.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 30, 2020
@zodiark23
Copy link
Author

I'll try again. I'll give you an update

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 30, 2020
@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 30, 2020
@zodiark23
Copy link
Author

@darshankawar same thing with latest of beta version.
When I cancel the payment screen. (I'll mark it complete for iOS and this error is happening)

2020-10-01 11:38:15.656406+0800 Runner[4578:1269438] flutter: Purchase Status: PurchaseStatus.pending
2020-10-01 11:38:21.504451+0800 Runner[4578:1270955] <SKPaymentQueue: 0x2815dc010>: Payment completed with error: Error Domain=ASDErrorDomain Code=907 "Unhandled exception" UserInfo={NSUnderlyingError=0x2818ed140 {Error Domain=AMSErrorDomain Code=6 "Payment Sheet Failed" UserInfo={NSLocalizedDescription=Payment Sheet Failed, NSLocalizedFailureReason=Payment sheet cancelled}}, NSLocalizedFailureReason=An unknown error occurred, NSLocalizedDescription=Unhandled exception}
2020-10-01 11:38:21.512931+0800 Runner[4578:1269438] flutter: Purchase Status: PurchaseStatus.error
2020-10-01 11:38:21.520484+0800 Runner[4578:1269438] [VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: PlatformException(storekit_invalid_argument, Argument type of finishTransaction is not a string., null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
<asynchronous suspension>
#2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
#3      SKPaymentQueueWrapper.finishTransaction (package:in_app_purchase/src/store_kit_wrappers/sk_payment_queue_wrapper.dart:106:19)
#4      AppStoreConnection.completePurchase (package:in_app_purchase/src/in_app_purchase/app_store_connection.dart:68:10)
#5      StoreBloc._listenToPurchaseUpdated.<anonymous closure> (package:volumeup/blocs/storeBloc.dart:169:18)
#6      List.forEach (dart:core-patch/growable_array.dart:313:8)
#7      StoreBloc._listenToPurchaseUpdated (package:volumeup/blocs/storeBloc.dart:155:25)
#8      StoreBloc.initialState.<anonymous closure>.<anonymous closure> (package:volumeup/blocs/storeBloc.dart:82:9)
#9      _rootRunUnary (dart:async/zone.dart:1198:47)
#10     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#11     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
#12     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
#13     _DelayedData.perform (dart:async/stream_impl.dart:611:14)
#14     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:730:11)
#15     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:687:7)
#16     _rootRun (dart:async/zone.dart:1182:47)
#17     _CustomZone.run (dart:async/zone.dart:1093:19)
#18     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#19     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#20     _rootRun (dart:async/zone.dart:1190:13)
#21     _CustomZone.run (dart:async/zone.dart:1093:19)
#22     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#23     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#24     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#25     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 1, 2020
@darshankawar darshankawar added p: first party p: in_app_purchase Plugin for in-app purchase platform-ios iOS applications specifically and removed in triage Presently being triaged by the triage team labels Oct 1, 2020
@darshankawar
Copy link
Member

darshankawar commented Oct 1, 2020

Related to #61047

@DangKhoi1997
Copy link

Same thing @zodiark23 mentioned happened to me yesterday. Any workaround guys ?

@zodiark23
Copy link
Author

@DangKhoi1997 I haven't found any workaround, and we're starting our testing haha. @darshankawar should we wait another release of in_app_purchase?

@DangKhoi1997
Copy link

Haha it still works well in android . Yesterday i thought i did something wrong in my code but no :)) . Let wait for the next version of it .

@koskimas
Copy link

koskimas commented Oct 1, 2020

I'm also seeing this. After a purchase has been cancelled, a new purchase cannot be started for the same product. After rebooting the app it works again, but the same thing happens again every time if I cancel a purchase.

@zodiark23
Copy link
Author

zodiark23 commented Oct 2, 2020

@darshankawar I manage to get another iphone with iOS 12.4.8 and this is not happening. I didn't change anything and same version and same flutter version. Looks like this is only an iOS 14 issue.

@koskimas
Copy link

koskimas commented Oct 2, 2020

I can confirm. Only happens on iOS 14.

@koskimas
Copy link

koskimas commented Oct 2, 2020

@darshankawar I don't know if this is relevant, but I've only tried this with testflight users for which the purchases are free. I can't test this with "real" users because the version of our app using the new version of this library is not yet in production. This doesn't happen with v0.3.4+3 that's currently in production for our app.

@koskimas
Copy link

koskimas commented Oct 2, 2020

@zodiark23 Should the title of this issue be modified to say something like "cannot start a new purchase after cancelling on iOS" so that other people also find this easier? That's the problem people will encounter first. For example I found this issue by going through all issues in desperation 😄

@koskimas
Copy link

koskimas commented Oct 2, 2020

This is the same issue as #66253

@darshankawar darshankawar added the e: OS-version specific Affects only some versions of the relevant operating system label Oct 2, 2020
@darshankawar darshankawar changed the title [in_app_purchase] iOS storekit_duplicate object issue [in_app_purchase] Cannot start a new purchase after cancelling on iOS 14 Oct 2, 2020
@zodiark23
Copy link
Author

@koskimas I was initially thinking of doing that, however when i try to buy the item again this error pops out

@dennis-tra
Copy link

dennis-tra commented Oct 2, 2020

Just created a fix for this issue flutter/plugins#3106

@zodiark23
Copy link
Author

Thanks @dennis-tra hope it gets merged soon

@darshankawar
Copy link
Member

@koskimas Thanks for identifying the similar issue.
@zodiark23 I am going ahead and closing this in favor of 66253 as duplicate. Please follow-up there for updates and any questions.

If you disagree or think this was closed by mistake and should have kept open, please write in comments and I'll reopen.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
e: OS-version specific Affects only some versions of the relevant operating system p: in_app_purchase Plugin for in-app purchase package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically
Projects
None yet
Development

No branches or pull requests

5 participants