Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[in_app_purchase] Fix finishing purchases upon payment dialog cancel… #3106

Merged
merged 1 commit into from Oct 6, 2020

Conversation

dennis-tra
Copy link
Contributor

@dennis-tra dennis-tra commented Oct 2, 2020

Description

This PR fixes finishing purchases upon payment dialog cancellation on iOS.

When the user cancels the payment dialog there is no transactionIdentifier which means the transaction cannot be finished in the current implementation and therefore not initiated again.

Duplicate of:

Related Issues

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@dennis-tra
Copy link
Contributor Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Oct 2, 2020
@dennis-tra dennis-tra changed the title [in_app_purchase] Fixe finishing purchases upon payment dialog cancel… [in_app_purchase] Fix finishing purchases upon payment dialog cancel… Oct 2, 2020
@dennis-tra dennis-tra force-pushed the in_app_purchase/cancel_modal branch 5 times, most recently from 285a35c to 51e8c04 Compare October 2, 2020 10:44
Copy link
Contributor

@LHLL LHLL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!


NSArray<SKPaymentTransaction *> *pendingTransactions =
[self.paymentQueueHandler getUnfinishedTransactions];

for (SKPaymentTransaction *transaction in pendingTransactions) {
if ([transaction.transactionIdentifier isEqualToString:transactionIdentifier]) {
// If the user cancels the purchase dialog we won't have a transactionIdentifier. So if it is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two words break the line. Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reformatted the comment

@@ -103,9 +103,11 @@ class SKPaymentQueueWrapper {
/// finishTransaction:]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/1506003-finishtransaction?language=objc).
Future<void> finishTransaction(
SKPaymentTransactionWrapper transaction) async {
Map requestMap = transaction.toFinishMap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer lightweight generic. Consider adding a type for the Map. For example: Map<String, String>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@LHLL LHLL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the version needs to be updated from pubspec.yaml

@LHLL LHLL merged commit 05b1010 into flutter:master Oct 6, 2020
@luisdhm
Copy link

luisdhm commented Oct 6, 2020

Still getting an error after calling completePurchase method in version 0.3.4+11.
PlatformException(storekit_invalid_argument, Argument type of finishTransaction is not a Dictionary, null, null)

EDIT: Worked with latest version 0.3.4+12

@fbardecio
Copy link

fbardecio commented Oct 6, 2020

Hi! I'm experiencing the same error PlatformException(storekit_invalid_argument, Argument type of finishTransaction is not a Dictionary, null, null)

EDIT: My bad, it is working after switching to a new sandbox account (IDK if it has something to do but just in case) and also running flutter clean! Thanks for the fix!

@DangKhoi1997
Copy link

Updated to version 0.3.4+12 but it still not pop up purchase dialog :(. Anyone has same error ??

@LHLL
Copy link
Contributor

LHLL commented Oct 7, 2020

Updated to version 0.3.4+12 but it still not pop up purchase dialog :(. Anyone has same error ??

@DangKhoi1997 I think dialog not showing up is a different issue and not related to this PR. Apple Pay UI/dialog is not showing up is related to not finishing transactions. Can you try something similar to following code to see if your problem is solved:

class PurchaseService{
    final _connection = InAppPurchaseConnection();

    const PurchaseService(){
          _connection.purchaseUpdatedStream.listen((detail) {
               ...
              // Verify the receipt for succeeded transactions and handle the error for the failed
              // transaction here.
              _connection.completePurchase(detail);
          });    
    }
}

yasargil added a commit to yasargil/plugins that referenced this pull request Oct 8, 2020
* master:
  [in_app_purchase] Android Code Inspection and Clean up (flutter#3120)
  Android Code Inspection and Clean up (flutter#3117)
  [in_app_purchase] Fix finishing purchases upon payment cancellation (flutter#3106)
  [google_maps_flutter_web] Fix convert.dart issues (flutter#3093)
  [multiple] Opt-out tests of null-safety (flutter#3113)
  [webview_flutter] add public documentation. (flutter#3114)
  in_app_purchase: started supported null as a parameter for the sandbox arguement (flutter#3110)
  [connectivity] Android Code Inspection and Clean up (flutter#3051)
  [android_intent] Android Code Inspection and Clean up (flutter#3043)
  Remove `io.flutter.embedded_views_preview` from README
  [google_maps_flutter] Fix headline in the readme (flutter#3100)
  [webview_flutter] Add new entrypoint that uses hybrid composition on Android (flutter#3067)
  [google_maps_flutter] Out of developers preview, bump to 1.0.0 (flutter#3091)
  [url_launcher_web] Move third_party under src. (flutter#3080)
  [plugin_platform_interface] Fix homepage in pubspec.yaml (flutter#3088)
  [connectivity_for_web] Fix homepage in pubspec.yaml (flutter#3089)
  [in_app_purchase] Update typo in example main.dart (flutter#3073)
@daoc13
Copy link

daoc13 commented Oct 8, 2020

Updated to latest version 0.3.4+12 but we are still not able to buy again whenever we cancel the purchase dialogue. The button works fine if we complete the purchase flow and I am able to buy many time if the purchase flow ends correct, but whenever I cancel and try to tap again the button it won’t open the purchase dialogue. Do we need to add any additional code to our implementation?

jorgefspereira pushed a commit to jorgefspereira/plugins_flutter that referenced this pull request Oct 10, 2020
FlutterSu pushed a commit to FlutterSu/flutter-plugins that referenced this pull request Nov 20, 2020
@hai199580
Copy link

Updated to latest version 0.3.4+12 but we are still not able to buy again whenever we cancel the purchase dialogue. The button works fine if we complete the purchase flow and I am able to buy many time if the purchase flow ends correct, but whenever I cancel and try to tap again the button it won’t open the purchase dialogue. Do we need to add any additional code to our implementation?

@daoc13 do you find any solution for this issue :((

@daoc13
Copy link

daoc13 commented Nov 25, 2020

Updated to latest version 0.3.4+12 but we are still not able to buy again whenever we cancel the purchase dialogue. The button works fine if we complete the purchase flow and I am able to buy many time if the purchase flow ends correct, but whenever I cancel and try to tap again the button it won’t open the purchase dialogue. Do we need to add any additional code to our implementation?

@daoc13 do you find any solution for this issue :((

@hai199580 I did not find a solution for this issue. I recommend you to use Revenue Cat, we implemented it in 4 hours and it works fine. I will keep using Revenue Cat until this issue is solved. Hope it helps!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
9 participants