[in_app_purchase] Ensure purchases correctly report if they are acknowledged on Android (#4257)
* Ensure purchases correctly show they are acknowledged
* Update packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
Co-authored-by: Rene Floor <r.floor.1@gmail.com>
* Update packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
Co-authored-by: Rene Floor <r.floor.1@gmail.com>
* Modify so public API is not changed
Co-authored-by: Rene Floor <r.floor.1@gmail.com>
diff --git a/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md b/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
index 8e342a6..1a03ba2 100644
--- a/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
+++ b/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.1.4+6
+
+* Ensure that purchases correctly indicate whether they are acknowledged or not. The `PurchaseDetails.pendingCompletePurchase` field now correctly indicates if the purchase still needs to be completed.
+
## 0.1.4+5
* Add `implements` to pubspec.
@@ -9,7 +13,7 @@
## 0.1.4+3
-- Updated installation instructions in README.
+* Updated installation instructions in README.
## 0.1.4+2
diff --git a/packages/in_app_purchase/in_app_purchase_android/lib/src/types/google_play_purchase_details.dart b/packages/in_app_purchase/in_app_purchase_android/lib/src/types/google_play_purchase_details.dart
index 66e3a8f..53b58bd 100644
--- a/packages/in_app_purchase/in_app_purchase_android/lib/src/types/google_play_purchase_details.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/lib/src/types/google_play_purchase_details.dart
@@ -20,30 +20,19 @@
required this.billingClientPurchase,
required PurchaseStatus status,
}) : super(
- productID: productID,
- purchaseID: purchaseID,
- transactionDate: transactionDate,
- verificationData: verificationData,
- status: status) {
- this.status = status;
+ productID: productID,
+ purchaseID: purchaseID,
+ transactionDate: transactionDate,
+ verificationData: verificationData,
+ status: status,
+ ) {
+ this.pendingCompletePurchase = !billingClientPurchase.isAcknowledged;
}
/// Points back to the [PurchaseWrapper] which was used to generate this
/// [GooglePlayPurchaseDetails] object.
final PurchaseWrapper billingClientPurchase;
- late PurchaseStatus _status;
-
- /// The status that this [PurchaseDetails] is currently on.
- PurchaseStatus get status => _status;
- set status(PurchaseStatus status) {
- _pendingCompletePurchase = status == PurchaseStatus.purchased;
- _status = status;
- }
-
- bool _pendingCompletePurchase = false;
- bool get pendingCompletePurchase => _pendingCompletePurchase;
-
/// Generate a [PurchaseDetails] object based on an Android [Purchase] object.
factory GooglePlayPurchaseDetails.fromPurchase(PurchaseWrapper purchase) {
final GooglePlayPurchaseDetails purchaseDetails = GooglePlayPurchaseDetails(
diff --git a/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml b/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml
index 745b651..d9b0982 100644
--- a/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml
+++ b/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml
@@ -2,7 +2,7 @@
description: An implementation for the Android platform of the Flutter `in_app_purchase` plugin. This uses the Android BillingClient APIs.
repository: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase/in_app_purchase_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
-version: 0.1.4+5
+version: 0.1.4+6
environment:
sdk: ">=2.12.0 <3.0.0"
diff --git a/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/purchase_wrapper_test.dart b/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/purchase_wrapper_test.dart
index bb7ff85..70b9fca 100644
--- a/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/purchase_wrapper_test.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/purchase_wrapper_test.dart
@@ -71,9 +71,10 @@
expect(parsed, equals(expected));
});
- test('toPurchaseDetails() should return correct PurchaseDetail object', () {
+ test('fromPurchase() should return correct PurchaseDetail object', () {
final GooglePlayPurchaseDetails details =
GooglePlayPurchaseDetails.fromPurchase(dummyPurchase);
+
expect(details.purchaseID, dummyPurchase.orderId);
expect(details.productID, dummyPurchase.sku);
expect(details.transactionDate, dummyPurchase.purchaseTime.toString());
@@ -84,6 +85,25 @@
expect(details.verificationData.serverVerificationData,
dummyPurchase.purchaseToken);
expect(details.billingClientPurchase, dummyPurchase);
+ expect(details.pendingCompletePurchase, false);
+ });
+
+ test(
+ 'fromPurchase() should return set pendingCompletePurchase to true for unacknowledged purchase',
+ () {
+ final GooglePlayPurchaseDetails details =
+ GooglePlayPurchaseDetails.fromPurchase(dummyUnacknowledgedPurchase);
+
+ expect(details.purchaseID, dummyPurchase.orderId);
+ expect(details.productID, dummyPurchase.sku);
+ expect(details.transactionDate, dummyPurchase.purchaseTime.toString());
+ expect(details.verificationData, isNotNull);
+ expect(details.verificationData.source, kIAPSource);
+ expect(details.verificationData.localVerificationData,
+ dummyPurchase.originalJson);
+ expect(details.verificationData.serverVerificationData,
+ dummyPurchase.purchaseToken);
+ expect(details.billingClientPurchase, dummyUnacknowledgedPurchase);
expect(details.pendingCompletePurchase, true);
});
});