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

[in_app_purchase] Implementation of platform interface #3781

Merged
merged 17 commits into from
Apr 22, 2021

Conversation

mvanbeusekom
Copy link
Contributor

@mvanbeusekom mvanbeusekom commented Apr 2, 2021

Defines a common platform interface for the in_app_purchase plugin.

NOTE:

As part of the in_app_purchase_platform_interface we will be replacing the following methods:

  • the Future<BillingResultWrapper> completePurchase(PurchaseDetails) method is replaced by the Future<void> finishPurchase(PurchaseDetails) method. The new finishPurchase method will no longer return the Android specific BillingResultWrapper, instead it will complete the future successfully if the finishPurchase executed successfully or throw an instance of the PurchaseException when an error occurred. The PurchaseException should be implemented per platform to indicate if developers should retry based on platform specific error codes;
  • the Future<QueryPurchaseDetailsResponse> queryPastPurchases({String? applicationUserName}) method is replaced by the Future<void> restorePurchases({String? applicationUserName}) method. The new restorePurchases will no longer return a list of restored purchases but instead emits each purchase on the new purchaseStream with the specific PurchaseStatus.restored status;
  • and the Stream<List<PurchaseDetails>> get purchaseUpdatedStream is replaced by the Stream<List<PurchaseDetails>> get purchaseStream property. The new purchaseStream should no longer filter out purchases with the PurchaseStatus.restored status, but instead emit those as well, giving developers the change to validate the receipt, deliver the content and finish the purchase correctly.

The existing Android and iOS implementations should mark the above methods as deprecated and should provide implementation for the new methods.

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • 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 updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@google-cla google-cla bot added the cla: yes label Apr 2, 2021
@mvanbeusekom mvanbeusekom marked this pull request as ready for review April 7, 2021 13:13
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.

Discussed offline, we are going to add a InAppPurchaseExtend and InAppPurchaseExtendProvider to the platform interface so Platform specific code can extend features.

CC @stuartmorgan @mvanbeusekom
Please comment with better name for these 2 classes if you can think of any :)

///
/// `autoConsume` is provided as a utility and will instruct the plugin to
/// automatically consume the product after a succesful purchase.
/// `autoConsume` is `true` by default. On iOS comsumable products are
Copy link
Contributor

Choose a reason for hiding this comment

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

we should remove the iOS related doc here and make sure it is documented in the plugin.

/// * [buyNonConsumable], for buying a non consumable product or
/// subscription.
/// * [restorePurchases], for restoring non consumable products.
/// * [consumePurchase], for manually consuming products on Android.
Copy link
Contributor

Choose a reason for hiding this comment

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

[consumePurchase] is not part of the platform interface, let's remove this line

@stuartmorgan
Copy link
Contributor

Discussed offline, we are going to add a InAppPurchaseExtend and InAppPurchaseExtendProvider to the platform interface so Platform specific code can extend features.

CC @stuartmorgan @mvanbeusekom
Please comment with better name for these 2 classes if you can think of any :)

How about s/Extend/Additions/ (It would need to be Extension to be the right part of speech, but that's a potentially confusing term given Dart's extension methods)

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.

LGTM % some doc nits

platform-specific behavior, and when you register your plugin, set the default
`InAppPurchasePlatform` by calling
`InAppPurchasePlatform.setInstance(MyPlatformInAppPurchase())`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's also add doc for how to add additional features in a platform

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

/// The interface that platform implementations must implement when they want to
/// provide platform specific in_app_purchase features.
abstract class InAppPurchaseAddition {
/// The instance containing the platform specific in_app_purchase features.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a code example of how a platform can add "Addition".
Something like:

class InAppPurchaseSomeStoreAddition extends InAppPurchaseAddition {
    void someMethod() {}
}

class InAppPurchaseSomeStorePluginWeb {
    static void registerWith() {
         InAppPurchaseAddition = InAppPurchaseSomePlatformAddition();
     }
}

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

@cyanglaz
Copy link
Contributor

The publishable check failed due to some tooling bug, which is fixed on master. Rebase should resolve the issue

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.

LGTM

@cyanglaz
Copy link
Contributor

We will hold off publishing the platform interface until we integrated with the plugin and made sure everything works. Please keep the "needs-publishing" label on

bhaveshptl pushed a commit to bhaveshptl/plugins that referenced this pull request Apr 23, 2021
* master: (397 commits)
  [in_app_purchase] Implementation of platform interface (flutter#3781)
  [google_sign_in] Add todo WRT correctly setting X-Goog-AuthUser header (flutter#3819)
  [tools] fix version check command not working for new packages (flutter#3818)
  [camera] android-rework part 1: Base classes to support Android Camera features (flutter#3795)
  fix MD (flutter#3815)
  Path provider windows crash fix (flutter#3814)
  [local_auth] docs update (flutter#3103)
  Update PULL_REQUEST_TEMPLATE.md (flutter#3801)
  [quick_actions] handle cold start on iOS correctly (flutter#3811)
  Replace path_provider_linux widget tests with simple unit tests (flutter#3812)
  [sensors] format dart code based on the new dart formatter (flutter#3809)
  [google_sign_in] Fix "pick account" on iOS (flutter#3805)
  [image_picker_platform_interface] Added pickMultiImage (flutter#3782)
  [in_app_purchase] Added currency code and numerical price to product detail model. (flutter#3794)
  [local_auth] Fix iOS crash when no localizedReason (flutter#3780)
  Fix and update version checks (flutter#3792)
  [in_app_purchase] Configured example app to use StoreKit Testing on iOS 14 (flutter#3772)
  [local_auth] Unnecessary reassignment in example removed (flutter#2983)
  [flutter_webview] Fix `allowsInlineMediaPlayback` ignored on iOS (flutter#3791)
  Switch script/tools over to the new analysis options (flutter#3777)
  ...
yasargil added a commit to yasargil/plugins that referenced this pull request Apr 28, 2021
* master: (79 commits)
  Fix grammatical error in contributing guide (flutter#3217)
  [google_sign_in_web] fix README typos.
  [tool] combine run and runAndExitOnError (flutter#3827)
  [camera] android-rework part 2: Android auto focus feature (flutter#3796)
  [in_app_purchase_platform_interface] Added additional fields to ProductDetails (flutter#3826)
  Move all null safety packages' min dart sdk to 2.12.0 (flutter#3822)
  [path_provider_*] code cleanup: sort directives (flutter#3823)
  [in_app_purchase] Implementation of platform interface (flutter#3781)
  [google_sign_in] Add todo WRT correctly setting X-Goog-AuthUser header (flutter#3819)
  [tools] fix version check command not working for new packages (flutter#3818)
  [camera] android-rework part 1: Base classes to support Android Camera features (flutter#3795)
  fix MD (flutter#3815)
  Path provider windows crash fix (flutter#3814)
  [local_auth] docs update (flutter#3103)
  Update PULL_REQUEST_TEMPLATE.md (flutter#3801)
  [quick_actions] handle cold start on iOS correctly (flutter#3811)
  Replace path_provider_linux widget tests with simple unit tests (flutter#3812)
  [sensors] format dart code based on the new dart formatter (flutter#3809)
  [google_sign_in] Fix "pick account" on iOS (flutter#3805)
  [image_picker_platform_interface] Added pickMultiImage (flutter#3782)
  ...
samandmoore added a commit to Betterment/plugins that referenced this pull request May 6, 2021
* upstream/master: (383 commits)
  Add implement and registerWith method to plugins (flutter#3833)
  Update third_party license checking (flutter#3844)
  [tool] add `all` and `dry-run` flags to publish-plugin command (flutter#3776)
  Re-add bin/ to flutter_plugin_tools (flutter#3839)
  switch from using 'tuneup' to analyze to 'dart analyze' (flutter#3837)
  [in_app_purchase] Federated iOS implementation (flutter#3832)
  Prep the tools for publishing (flutter#3836)
  [in_app_purchase] Make PurchaseDetails.status mandatory (flutter#3831)
  Fix grammatical error in contributing guide (flutter#3217)
  [google_sign_in_web] fix README typos.
  [tool] combine run and runAndExitOnError (flutter#3827)
  [camera] android-rework part 2: Android auto focus feature (flutter#3796)
  [in_app_purchase_platform_interface] Added additional fields to ProductDetails (flutter#3826)
  Move all null safety packages' min dart sdk to 2.12.0 (flutter#3822)
  [path_provider_*] code cleanup: sort directives (flutter#3823)
  [in_app_purchase] Implementation of platform interface (flutter#3781)
  [google_sign_in] Add todo WRT correctly setting X-Goog-AuthUser header (flutter#3819)
  [tools] fix version check command not working for new packages (flutter#3818)
  [camera] android-rework part 1: Base classes to support Android Camera features (flutter#3795)
  fix MD (flutter#3815)
  ...
fotiDim pushed a commit to fotiDim/plugins that referenced this pull request Sep 13, 2021
@mvanbeusekom mvanbeusekom deleted the iap_platform_interface branch September 21, 2021 09:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants