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

Commit 5e7c779

Browse files
authored
[in_app_purchase] Add immediateAndChargeFullPrice ProrationMode (#6415)
1 parent 2802ca4 commit 5e7c779

File tree

5 files changed

+55
-5
lines changed

5 files changed

+55
-5
lines changed

packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## NEXT
1+
## 0.2.3+4
22

33
* Updates minimum Flutter version to 2.10.
4+
* Adds IMMEDIATE_AND_CHARGE_FULL_PRICE to the `ProrationMode`.
45

56
## 0.2.3+3
67

packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ enum ProrationMode {
495495
@JsonValue(0)
496496
unknownSubscriptionUpgradeDowngradePolicy,
497497

498-
/// Replacement takes effect immediately, and the remaining time will be prorated and credited to the user.
498+
/// Replacement takes effect immediately, and the remaining time will be prorated
499+
/// and credited to the user.
499500
///
500501
/// This is the current default behavior.
501502
@JsonValue(1)
@@ -508,15 +509,23 @@ enum ProrationMode {
508509
@JsonValue(2)
509510
immediateAndChargeProratedPrice,
510511

511-
/// Replacement takes effect immediately, and the new price will be charged on next recurrence time.
512+
/// Replacement takes effect immediately, and the new price will be charged on next
513+
/// recurrence time.
512514
///
513515
/// The billing cycle stays the same.
514516
@JsonValue(3)
515517
immediateWithoutProration,
516518

517-
/// Replacement takes effect when the old plan expires, and the new price will be charged at the same time.
519+
/// Replacement takes effect when the old plan expires, and the new price will
520+
/// be charged at the same time.
518521
@JsonValue(4)
519522
deferred,
523+
524+
/// Replacement takes effect immediately, and the user is charged full price
525+
/// of new plan and is given a full billing cycle of subscription, plus
526+
/// remaining prorated time from the old plan.
527+
@JsonValue(5)
528+
immediateAndChargeFullPrice,
520529
}
521530

522531
/// Serializer for [ProrationMode].

packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.g.dart

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/in_app_purchase/in_app_purchase_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: in_app_purchase_android
22
description: An implementation for the Android platform of the Flutter `in_app_purchase` plugin. This uses the Android BillingClient APIs.
33
repository: https://github.com/flutter/plugins/tree/main/packages/in_app_purchase/in_app_purchase_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
5-
version: 0.2.3+3
5+
version: 0.2.3+4
66

77
environment:
88
sdk: ">=2.14.0 <3.0.0"

packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/billing_client_wrapper_test.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,45 @@ void main() {
311311
const ProrationModeConverter().toJson(prorationMode));
312312
});
313313

314+
test(
315+
'serializes and deserializes data when using immediateAndChargeFullPrice',
316+
() async {
317+
const String debugMessage = 'dummy message';
318+
const BillingResponse responseCode = BillingResponse.ok;
319+
const BillingResultWrapper expectedBillingResult = BillingResultWrapper(
320+
responseCode: responseCode, debugMessage: debugMessage);
321+
stubPlatform.addResponse(
322+
name: launchMethodName,
323+
value: buildBillingResultMap(expectedBillingResult),
324+
);
325+
const SkuDetailsWrapper skuDetails = dummySkuDetails;
326+
const String accountId = 'hashedAccountId';
327+
const String profileId = 'hashedProfileId';
328+
const ProrationMode prorationMode =
329+
ProrationMode.immediateAndChargeFullPrice;
330+
331+
expect(
332+
await billingClient.launchBillingFlow(
333+
sku: skuDetails.sku,
334+
accountId: accountId,
335+
obfuscatedProfileId: profileId,
336+
oldSku: dummyOldPurchase.sku,
337+
prorationMode: prorationMode,
338+
purchaseToken: dummyOldPurchase.purchaseToken),
339+
equals(expectedBillingResult));
340+
final Map<dynamic, dynamic> arguments = stubPlatform
341+
.previousCallMatching(launchMethodName)
342+
.arguments as Map<dynamic, dynamic>;
343+
expect(arguments['sku'], equals(skuDetails.sku));
344+
expect(arguments['accountId'], equals(accountId));
345+
expect(arguments['oldSku'], equals(dummyOldPurchase.sku));
346+
expect(arguments['obfuscatedProfileId'], equals(profileId));
347+
expect(
348+
arguments['purchaseToken'], equals(dummyOldPurchase.purchaseToken));
349+
expect(arguments['prorationMode'],
350+
const ProrationModeConverter().toJson(prorationMode));
351+
});
352+
314353
test('handles null accountId', () async {
315354
const String debugMessage = 'dummy message';
316355
const BillingResponse responseCode = BillingResponse.ok;

0 commit comments

Comments
 (0)