[in_app_purchase] Add immediateAndChargeFullPrice ProrationMode (#6415)
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 910c5cd..8733a1c 100644
--- a/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
+++ b/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
@@ -1,6 +1,7 @@
-## NEXT
+## 0.2.3+4
* Updates minimum Flutter version to 2.10.
+* Adds IMMEDIATE_AND_CHARGE_FULL_PRICE to the `ProrationMode`.
## 0.2.3+3
diff --git a/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.dart b/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.dart
index 4c64a99..b64eaab 100644
--- a/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.dart
@@ -495,7 +495,8 @@
@JsonValue(0)
unknownSubscriptionUpgradeDowngradePolicy,
- /// Replacement takes effect immediately, and the remaining time will be prorated and credited to the user.
+ /// Replacement takes effect immediately, and the remaining time will be prorated
+ /// and credited to the user.
///
/// This is the current default behavior.
@JsonValue(1)
@@ -508,15 +509,23 @@
@JsonValue(2)
immediateAndChargeProratedPrice,
- /// Replacement takes effect immediately, and the new price will be charged on next recurrence time.
+ /// Replacement takes effect immediately, and the new price will be charged on next
+ /// recurrence time.
///
/// The billing cycle stays the same.
@JsonValue(3)
immediateWithoutProration,
- /// Replacement takes effect when the old plan expires, and the new price will be charged at the same time.
+ /// Replacement takes effect when the old plan expires, and the new price will
+ /// be charged at the same time.
@JsonValue(4)
deferred,
+
+ /// Replacement takes effect immediately, and the user is charged full price
+ /// of new plan and is given a full billing cycle of subscription, plus
+ /// remaining prorated time from the old plan.
+ @JsonValue(5)
+ immediateAndChargeFullPrice,
}
/// Serializer for [ProrationMode].
diff --git a/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.g.dart b/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.g.dart
index efe7656..99355a1 100644
--- a/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.g.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.g.dart
@@ -32,6 +32,7 @@
ProrationMode.immediateAndChargeProratedPrice: 2,
ProrationMode.immediateWithoutProration: 3,
ProrationMode.deferred: 4,
+ ProrationMode.immediateAndChargeFullPrice: 5,
};
const _$BillingClientFeatureEnumMap = {
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 320e4b8..a0563f1 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/main/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.3+3
+version: 0.2.3+4
environment:
sdk: ">=2.14.0 <3.0.0"
diff --git a/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/billing_client_wrapper_test.dart b/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/billing_client_wrapper_test.dart
index e803e81..4dae957 100644
--- a/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/billing_client_wrapper_test.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/billing_client_wrapper_test.dart
@@ -311,6 +311,45 @@
const ProrationModeConverter().toJson(prorationMode));
});
+ test(
+ 'serializes and deserializes data when using immediateAndChargeFullPrice',
+ () async {
+ const String debugMessage = 'dummy message';
+ const BillingResponse responseCode = BillingResponse.ok;
+ const BillingResultWrapper expectedBillingResult = BillingResultWrapper(
+ responseCode: responseCode, debugMessage: debugMessage);
+ stubPlatform.addResponse(
+ name: launchMethodName,
+ value: buildBillingResultMap(expectedBillingResult),
+ );
+ const SkuDetailsWrapper skuDetails = dummySkuDetails;
+ const String accountId = 'hashedAccountId';
+ const String profileId = 'hashedProfileId';
+ const ProrationMode prorationMode =
+ ProrationMode.immediateAndChargeFullPrice;
+
+ expect(
+ await billingClient.launchBillingFlow(
+ sku: skuDetails.sku,
+ accountId: accountId,
+ obfuscatedProfileId: profileId,
+ oldSku: dummyOldPurchase.sku,
+ prorationMode: prorationMode,
+ purchaseToken: dummyOldPurchase.purchaseToken),
+ equals(expectedBillingResult));
+ final Map<dynamic, dynamic> arguments = stubPlatform
+ .previousCallMatching(launchMethodName)
+ .arguments as Map<dynamic, dynamic>;
+ expect(arguments['sku'], equals(skuDetails.sku));
+ expect(arguments['accountId'], equals(accountId));
+ expect(arguments['oldSku'], equals(dummyOldPurchase.sku));
+ expect(arguments['obfuscatedProfileId'], equals(profileId));
+ expect(
+ arguments['purchaseToken'], equals(dummyOldPurchase.purchaseToken));
+ expect(arguments['prorationMode'],
+ const ProrationModeConverter().toJson(prorationMode));
+ });
+
test('handles null accountId', () async {
const String debugMessage = 'dummy message';
const BillingResponse responseCode = BillingResponse.ok;