This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[in_app_purchase] Adds Dart BillingClient APIs for loading purchases #1286
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
packages/in_app_purchase/lib/src/billing_client_wrappers/purchase_wrapper.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| // Copyright 2019 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| import 'dart:ui' show hashValues; | ||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:json_annotation/json_annotation.dart'; | ||
| import 'enum_converters.dart'; | ||
| import 'billing_client_wrapper.dart'; | ||
|
|
||
| // WARNING: Changes to `@JsonSerializable` classes need to be reflected in the | ||
| // below generated file. Run `flutter packages pub run build_runner watch` to | ||
| // rebuild and watch for further changes. | ||
| part 'purchase_wrapper.g.dart'; | ||
|
|
||
| /// Data structure reprenting a succesful purchase. | ||
| /// | ||
| /// All purchase information should also be verified manually, with your | ||
| /// server if at all possible. See ["Verify a | ||
| /// purchase"](https://developer.android.com/google/play/billing/billing_library_overview#Verify). | ||
| /// | ||
| /// This wraps [`com.android.billlingclient.api.Purchase`](https://developer.android.com/reference/com/android/billingclient/api/Purchase) | ||
| @JsonSerializable() | ||
| class PurchaseWrapper { | ||
| @visibleForTesting | ||
| PurchaseWrapper({ | ||
| @required this.orderId, | ||
| @required this.packageName, | ||
| @required this.purchaseTime, | ||
| @required this.purchaseToken, | ||
| @required this.signature, | ||
| @required this.sku, | ||
| @required this.isAutoRenewing, | ||
| @required this.originalJson, | ||
| }); | ||
|
|
||
| factory PurchaseWrapper.fromJson(Map map) => _$PurchaseWrapperFromJson(map); | ||
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (identical(other, this)) return true; | ||
| if (other.runtimeType != runtimeType) return false; | ||
| final PurchaseWrapper typedOther = other; | ||
| return typedOther.orderId == orderId && | ||
| typedOther.packageName == packageName && | ||
| typedOther.purchaseTime == purchaseTime && | ||
| typedOther.purchaseToken == purchaseToken && | ||
| typedOther.signature == signature && | ||
| typedOther.sku == sku && | ||
| typedOther.isAutoRenewing == isAutoRenewing && | ||
| typedOther.originalJson == originalJson; | ||
| } | ||
|
|
||
| @override | ||
| int get hashCode => hashValues(orderId, packageName, purchaseTime, | ||
| purchaseToken, signature, sku, isAutoRenewing, originalJson); | ||
|
|
||
| /// The unique ID for this purchase. Corresponds to the Google Payments order | ||
| /// ID. | ||
| final String orderId; | ||
|
|
||
| /// The package name the purchase was made from. | ||
| final String packageName; | ||
|
|
||
| /// When the purchase was made, as an epoch timestamp. | ||
| final int purchaseTime; | ||
|
|
||
| /// A unique ID for a given [SkuDetailsWrapper], user, and purchase. | ||
| final String purchaseToken; | ||
|
|
||
| /// Signature of purchase data, signed with the developer's private key. Uses | ||
| /// RSASSA-PKCS1-v1_5. | ||
| final String signature; | ||
|
|
||
| /// The product ID of this purchase. | ||
| final String sku; | ||
|
|
||
| /// True for subscriptions that renew automatically. Does not apply to | ||
| /// [SkuType.inapp] products. | ||
| /// | ||
| /// For [SkuType.subs] this means that the subscription is canceled when it is | ||
| /// false. | ||
| final bool isAutoRenewing; | ||
|
|
||
| /// Details about this purchase, in JSON. | ||
| /// | ||
| /// This can be used verify a purchase. See ["Verify a purchase on a | ||
| /// device"](https://developer.android.com/google/play/billing/billing_library_overview#Verify-purchase-device). | ||
| /// Note though that verifying a purchase locally is inherently insecure (see | ||
| /// the article for more details). | ||
| final String originalJson; | ||
| } | ||
|
|
||
| /// A data struct representing the result of a transaction. | ||
| /// | ||
| /// Contains a potentially empty list of [PurchaseWrapper]s and a | ||
| /// [BillingResponse] to signify the overall state of the transaction. | ||
| /// | ||
| /// Wraps [`com.android.billingclient.api.Purchase.PurchasesResult`](https://developer.android.com/reference/com/android/billingclient/api/Purchase.PurchasesResult). | ||
| @JsonSerializable() | ||
| @BillingResponseConverter() | ||
| class PurchasesResultWrapper { | ||
| PurchasesResultWrapper( | ||
| {@required BillingResponse this.responseCode, | ||
| @required List<PurchaseWrapper> this.purchasesList}); | ||
|
|
||
| factory PurchasesResultWrapper.fromJson(Map map) => | ||
| _$PurchasesResultWrapperFromJson(map); | ||
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (identical(other, this)) return true; | ||
| if (other.runtimeType != runtimeType) return false; | ||
| final PurchasesResultWrapper typedOther = other; | ||
| return typedOther.responseCode == responseCode && | ||
| typedOther.purchasesList == purchasesList; | ||
| } | ||
|
|
||
| @override | ||
| int get hashCode => hashValues(responseCode, purchasesList); | ||
|
|
||
| /// The status of the operation. | ||
| /// | ||
| /// This can represent either the status of the "query purchase history" half | ||
| /// of the operation and the "user made purchases" transaction itself. | ||
| final BillingResponse responseCode; | ||
|
|
||
| /// The list of succesful purchases made in this transaction. | ||
| /// | ||
| /// May be empty, especially if [responseCode] is not [BillingResponse.ok]. | ||
| final List<PurchaseWrapper> purchasesList; | ||
| } |
28 changes: 28 additions & 0 deletions
28
packages/in_app_purchase/lib/src/billing_client_wrappers/purchase_wrapper.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.