forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[in_app_purchase] Adds Dart BillingClient APIs for loading purchases (f…
…lutter#1286) 1. Wires the Purchase data class and serializes in to Dart. 2. BillingClient now required a callback for responding to Purchase updates to be passed in at construction time. 3. Exposes `BillingClient#queryPurchases` and `BillingClient#queryPurchaseHistory`. For now GooglePlayConnection passes in a lambda that does nothing to `BillingClient`. This will need to be fixed when all the collections are updated.
- Loading branch information
Michael Klimushyn
authored
Mar 7, 2019
1 parent
5bea35b
commit 6d7b459
Showing
11 changed files
with
416 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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.