Skip to content

Commit f48f8db

Browse files
authored
[in_app_purchase] Ensure the introductoryPriceMicros field is transported as a String. (flutter#4370)
1 parent 326e3c4 commit f48f8db

File tree

6 files changed

+98
-14
lines changed

6 files changed

+98
-14
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,5 +1,6 @@
1-
## NEXT
1+
## 0.1.5
22

3+
* Introduced the `SkuDetailsWrapper.introductoryPriceAmountMicros` field of the correct type (`int`) and deprecated the `SkuDetailsWrapper.introductoryPriceMicros` field.
34
* Update dev_dependency `build_runner` to ^2.0.0 and `json_serializable` to ^5.0.2.
45

56
## 0.1.4+7

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class SkuDetailsWrapper {
3232
required this.description,
3333
required this.freeTrialPeriod,
3434
required this.introductoryPrice,
35-
required this.introductoryPriceMicros,
35+
@Deprecated('Use `introductoryPriceAmountMicros` parameter instead')
36+
String introductoryPriceMicros = '',
37+
this.introductoryPriceAmountMicros = 0,
3638
required this.introductoryPriceCycles,
3739
required this.introductoryPricePeriod,
3840
required this.price,
@@ -45,7 +47,9 @@ class SkuDetailsWrapper {
4547
required this.type,
4648
required this.originalPrice,
4749
required this.originalPriceAmountMicros,
48-
});
50+
}) : _introductoryPriceMicros = introductoryPriceMicros;
51+
52+
final String _introductoryPriceMicros;
4953

5054
/// Constructs an instance of this from a key value map of data.
5155
///
@@ -67,9 +71,19 @@ class SkuDetailsWrapper {
6771
@JsonKey(defaultValue: '')
6872
final String introductoryPrice;
6973

70-
/// [introductoryPrice] in micro-units 990000
71-
@JsonKey(name: 'introductoryPriceAmountMicros', defaultValue: '')
72-
final String introductoryPriceMicros;
74+
/// [introductoryPrice] in micro-units 990000.
75+
///
76+
/// Returns 0 if the SKU is not a subscription or doesn't have an introductory
77+
/// period.
78+
@JsonKey(name: 'introductoryPriceAmountMicros', defaultValue: 0)
79+
final int introductoryPriceAmountMicros;
80+
81+
/// String representation of [introductoryPrice] in micro-units 990000
82+
@Deprecated('Use `introductoryPriceAmountMicros` instead.')
83+
@JsonKey(ignore: true)
84+
String get introductoryPriceMicros => _introductoryPriceMicros.isEmpty
85+
? introductoryPriceAmountMicros.toString()
86+
: _introductoryPriceMicros;
7387

7488
/// The number of subscription billing periods for which the user will be given the introductory price, such as 3.
7589
/// Returns 0 if the SKU is not a subscription or doesn't have an introductory period.
@@ -131,7 +145,7 @@ class SkuDetailsWrapper {
131145
other.description == description &&
132146
other.freeTrialPeriod == freeTrialPeriod &&
133147
other.introductoryPrice == introductoryPrice &&
134-
other.introductoryPriceMicros == introductoryPriceMicros &&
148+
other.introductoryPriceAmountMicros == introductoryPriceAmountMicros &&
135149
other.introductoryPriceCycles == introductoryPriceCycles &&
136150
other.introductoryPricePeriod == introductoryPricePeriod &&
137151
other.price == price &&
@@ -150,7 +164,7 @@ class SkuDetailsWrapper {
150164
description.hashCode,
151165
freeTrialPeriod.hashCode,
152166
introductoryPrice.hashCode,
153-
introductoryPriceMicros.hashCode,
167+
introductoryPriceAmountMicros.hashCode,
154168
introductoryPriceCycles.hashCode,
155169
introductoryPricePeriod.hashCode,
156170
price.hashCode,

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

Lines changed: 3 additions & 3 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/master/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.1.4+7
5+
version: 0.1.5
66

77
environment:
88
sdk: ">=2.12.0 <3.0.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// TODO(mvanbeusekom): Remove this file when the deprecated
6+
// `SkuDetailsWrapper.introductoryPriceMicros` field is
7+
// removed.
8+
9+
import 'package:flutter_test/flutter_test.dart';
10+
import 'package:in_app_purchase_android/billing_client_wrappers.dart';
11+
12+
void main() {
13+
test(
14+
'Deprecated `introductoryPriceMicros` field reflects parameter from constructor',
15+
() {
16+
final SkuDetailsWrapper skuDetails = SkuDetailsWrapper(
17+
description: 'description',
18+
freeTrialPeriod: 'freeTrialPeriod',
19+
introductoryPrice: 'introductoryPrice',
20+
// ignore: deprecated_member_use_from_same_package
21+
introductoryPriceMicros: '990000',
22+
introductoryPriceCycles: 1,
23+
introductoryPricePeriod: 'introductoryPricePeriod',
24+
price: 'price',
25+
priceAmountMicros: 1000,
26+
priceCurrencyCode: 'priceCurrencyCode',
27+
priceCurrencySymbol: r'$',
28+
sku: 'sku',
29+
subscriptionPeriod: 'subscriptionPeriod',
30+
title: 'title',
31+
type: SkuType.inapp,
32+
originalPrice: 'originalPrice',
33+
originalPriceAmountMicros: 1000,
34+
);
35+
36+
expect(skuDetails, isNotNull);
37+
expect(skuDetails.introductoryPriceAmountMicros, 0);
38+
// ignore: deprecated_member_use_from_same_package
39+
expect(skuDetails.introductoryPriceMicros, '990000');
40+
});
41+
42+
test(
43+
'`introductoryPriceAmoutMicros` constructor parameter is reflected by deprecated `introductoryPriceMicros` and `introductoryPriceAmountMicros` fields',
44+
() {
45+
final SkuDetailsWrapper skuDetails = SkuDetailsWrapper(
46+
description: 'description',
47+
freeTrialPeriod: 'freeTrialPeriod',
48+
introductoryPrice: 'introductoryPrice',
49+
introductoryPriceAmountMicros: 990000,
50+
introductoryPriceCycles: 1,
51+
introductoryPricePeriod: 'introductoryPricePeriod',
52+
price: 'price',
53+
priceAmountMicros: 1000,
54+
priceCurrencyCode: 'priceCurrencyCode',
55+
priceCurrencySymbol: r'$',
56+
sku: 'sku',
57+
subscriptionPeriod: 'subscriptionPeriod',
58+
title: 'title',
59+
type: SkuType.inapp,
60+
originalPrice: 'originalPrice',
61+
originalPriceAmountMicros: 1000,
62+
);
63+
64+
expect(skuDetails, isNotNull);
65+
expect(skuDetails.introductoryPriceAmountMicros, 990000);
66+
// ignore: deprecated_member_use_from_same_package
67+
expect(skuDetails.introductoryPriceMicros, '990000');
68+
});
69+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final SkuDetailsWrapper dummySkuDetails = SkuDetailsWrapper(
1111
description: 'description',
1212
freeTrialPeriod: 'freeTrialPeriod',
1313
introductoryPrice: 'introductoryPrice',
14-
introductoryPriceMicros: 'introductoryPriceMicros',
14+
introductoryPriceAmountMicros: 990000,
1515
introductoryPriceCycles: 1,
1616
introductoryPricePeriod: 'introductoryPricePeriod',
1717
price: 'price',
@@ -134,7 +134,7 @@ Map<String, dynamic> buildSkuMap(SkuDetailsWrapper original) {
134134
'description': original.description,
135135
'freeTrialPeriod': original.freeTrialPeriod,
136136
'introductoryPrice': original.introductoryPrice,
137-
'introductoryPriceAmountMicros': original.introductoryPriceMicros,
137+
'introductoryPriceAmountMicros': original.introductoryPriceAmountMicros,
138138
'introductoryPriceCycles': original.introductoryPriceCycles,
139139
'introductoryPricePeriod': original.introductoryPricePeriod,
140140
'price': original.price,

0 commit comments

Comments
 (0)