Skip to content

[in_app_purchase] restorePurchases handles "nothing to restore"-case differently on iOS and Android #82795

@JetA2

Description

@JetA2

I'm using the 0.6.0 release of in_app_purchase.

My use case is that I want to inform the user if there were no previous purchases to restore if they request to restore purchases.

This can be done, but it requires different solutions for iOS and Android. It would be nice if restorePurchases worked the same on both platforms.

iOS:
restorePurchases returns a Future that completes when paymentQueueRestoreCompletedTransactionsFinished is received from the platform:

https://github.com/flutter/plugins/blob/47b2a96a8d93cdcd964a78008bb26594853fea6f/packages/in_app_purchase/in_app_purchase_ios/lib/src/in_app_purchase_ios_platform.dart#L187-L189

When the Future completes, any restored purchases will have already been delivered to the StreamSubscription.
However, if there are no purchases to restore, nothing is added to the queue for purchase updates.

  • Detection of "nothing to restore" can be achieved by waiting for the Future to complete, then checking if any restored purchases were delivered.
  • Detection of "nothing to restore" can not be achieved by waiting for an empty result to be delivered to the StreamSubscription.

Android:
restorePurchases returns a Future that completes after restored purchases have been added to the queue for purchase updates:

https://github.com/flutter/plugins/blob/e742a7b6557b2f1be7c4fae92d712078347f5ac5/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart#L218

When the Future completes, the events from the queue for purchase updates have not yet been delivered to the StreamSubscription. If there are no purchases to restore, an empty List<PurchaseDetails> will be added to the queue for purchase updates.

  • Detection of "nothing to restore" can not be achieved by waiting for the Future to complete, then checking if any restored purchases were delivered.
  • Detection of "nothing to restore" can be achieved by waiting for an empty result to be delivered to the StreamSubscription.

Both detection methods are fine by me, but it would be preferable to be able to use the same method on both platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterp: in_app_purchasePlugin for in-app purchasepackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions