Thanks to visit codestin.com
Credit goes to github.com

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

[in_app_purchase] Fix upgrading subscription by deferred proration mode on android. #4560

Merged
merged 5 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.2

* Fixes the `purchaseStream` incorrectly reporting `PurchaseStatus.error` when user upgrades subscription by deferred proration mode.

## 0.2.1

* Deprecated the `InAppPurchaseAndroidPlatformAddition.enablePendingPurchases()` method and `InAppPurchaseAndroidPlatformAddition.enablePendingPurchase` property. Since Google Play no longer accepts App submissions that don't support pending purchases it is no longer necessary to acknowledge this through code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,17 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform {
if (purchases.isNotEmpty) {
return Future.wait(purchases);
} else {
PurchaseStatus status = PurchaseStatus.error;
if (resultWrapper.responseCode == BillingResponse.userCanceled) {
status = PurchaseStatus.canceled;
} else if (resultWrapper.responseCode == BillingResponse.ok) {
status = PurchaseStatus.purchased;
}
return [
PurchaseDetails(
purchaseID: '',
productID: '',
status: resultWrapper.responseCode == BillingResponse.userCanceled
? PurchaseStatus.canceled
: PurchaseStatus.error,
status: status,
transactionDate: null,
verificationData: PurchaseVerificationData(
localVerificationData: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: in_app_purchase_android
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.2.1
version: 0.2.2

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,51 @@ void main() {
GooglePlayPurchaseDetails result = await completer.future;
expect(result.status, PurchaseStatus.canceled);
});

test(
'should get purchased purchase status when upgrading subscription by deferred proration mode',
() async {
final SkuDetailsWrapper skuDetails = dummySkuDetails;
final String accountId = "hashedAccountId";
const String debugMessage = 'dummy message';
final BillingResponse sentCode = BillingResponse.ok;
final BillingResultWrapper expectedBillingResult = BillingResultWrapper(
responseCode: sentCode, debugMessage: debugMessage);
stubPlatform.addResponse(
name: launchMethodName,
value: buildBillingResultMap(expectedBillingResult),
additionalStepBeforeReturn: (_) {
// Mock java update purchase callback.
MethodCall call = MethodCall(kOnPurchasesUpdated, {
'billingResult': buildBillingResultMap(expectedBillingResult),
'responseCode': BillingResponseConverter().toJson(sentCode),
'purchasesList': []
});
iapAndroidPlatform.billingClient.callHandler(call);
});

Completer completer = Completer();
PurchaseDetails purchaseDetails;
Stream purchaseStream = iapAndroidPlatform.purchaseStream;
late StreamSubscription subscription;
subscription = purchaseStream.listen((_) {
purchaseDetails = _.first;
completer.complete(purchaseDetails);
subscription.cancel();
}, onDone: () {});
final GooglePlayPurchaseParam purchaseParam = GooglePlayPurchaseParam(
productDetails: GooglePlayProductDetails.fromSkuDetails(skuDetails),
applicationUserName: accountId,
changeSubscriptionParam: ChangeSubscriptionParam(
oldPurchaseDetails: GooglePlayPurchaseDetails.fromPurchase(
dummyUnacknowledgedPurchase),
prorationMode: ProrationMode.deferred,
));
await iapAndroidPlatform.buyNonConsumable(purchaseParam: purchaseParam);

PurchaseDetails result = await completer.future;
expect(result.status, PurchaseStatus.purchased);
});
});

group('complete purchase', () {
Expand Down