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

Commit 15bcf56

Browse files
committed
Added introductoryPriceAmountMicros field.
Introduced the `SkuDetailsWrapper.introductoryPriceAmountMicros` field of the correct type (`int`) and deprecated the `SkuDetailsWrapper.introductoryPriceMicros` field.
1 parent ed2e7a7 commit 15bcf56

File tree

6 files changed

+95
-14
lines changed

6 files changed

+95
-14
lines changed

packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## 0.1.4+7
1+
## 0.1.5
22

3-
* Ensure that the `SkuDetailsWrapper.introductoryPriceMicros` is populated correctly.
3+
* Introduced the `SkuDetailsWrapper.introductoryPriceAmountMicros` field of the correct type (`int`) and deprecated the `SkuDetailsWrapper.introductoryPriceMicros` field.
44

55
## 0.1.4+6
66

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

Lines changed: 19 additions & 6 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
///
@@ -68,8 +72,17 @@ class SkuDetailsWrapper {
6872
final String introductoryPrice;
6973

7074
/// [introductoryPrice] in micro-units 990000
71-
@JsonKey(name: 'introductoryPriceAmountMicros', defaultValue: '')
72-
final String introductoryPriceMicros;
75+
@JsonKey(name: 'introductoryPriceAmountMicros', defaultValue: 0)
76+
final int introductoryPriceAmountMicros;
77+
78+
/// String representation of [introductoryPrice] in micro-units 990000
79+
@Deprecated('Use `introductoryPriceAmountMicros` instead.')
80+
@JsonKey(ignore: true)
81+
String get introductoryPriceMicros => _introductoryPriceMicros.isEmpty
82+
? introductoryPriceAmountMicros != 0
83+
? introductoryPriceAmountMicros.toString()
84+
: ''
85+
: _introductoryPriceMicros;
7386

7487
/// The number of subscription billing periods for which the user will be given the introductory price, such as 3.
7588
/// Returns 0 if the SKU is not a subscription or doesn't have an introductory period.
@@ -131,7 +144,7 @@ class SkuDetailsWrapper {
131144
other.description == description &&
132145
other.freeTrialPeriod == freeTrialPeriod &&
133146
other.introductoryPrice == introductoryPrice &&
134-
other.introductoryPriceMicros == introductoryPriceMicros &&
147+
other.introductoryPriceAmountMicros == introductoryPriceAmountMicros &&
135148
other.introductoryPriceCycles == introductoryPriceCycles &&
136149
other.introductoryPricePeriod == introductoryPricePeriod &&
137150
other.price == price &&
@@ -150,7 +163,7 @@ class SkuDetailsWrapper {
150163
description.hashCode,
151164
freeTrialPeriod.hashCode,
152165
introductoryPrice.hashCode,
153-
introductoryPriceMicros.hashCode,
166+
introductoryPriceAmountMicros.hashCode,
154167
introductoryPriceCycles.hashCode,
155168
introductoryPricePeriod.hashCode,
156169
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,68 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:in_app_purchase_android/billing_client_wrappers.dart';
3+
// Copyright 2013 The Flutter Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style license that can be
5+
// found in the LICENSE file.
6+
7+
// TODO(mvanbeusekom): Remove this file when the deprecated
8+
// `SkuDetailsWrapper.introductoryPriceMicros` field is
9+
// removed.
10+
11+
void main() {
12+
test(
13+
'Deprecated `introductoryPriceMicros` field reflects parameter from constructor',
14+
() {
15+
final SkuDetailsWrapper skuDetails = SkuDetailsWrapper(
16+
description: 'description',
17+
freeTrialPeriod: 'freeTrialPeriod',
18+
introductoryPrice: 'introductoryPrice',
19+
// ignore: deprecated_member_use_from_same_package
20+
introductoryPriceMicros: '990000',
21+
introductoryPriceCycles: 1,
22+
introductoryPricePeriod: 'introductoryPricePeriod',
23+
price: 'price',
24+
priceAmountMicros: 1000,
25+
priceCurrencyCode: 'priceCurrencyCode',
26+
priceCurrencySymbol: r'$',
27+
sku: 'sku',
28+
subscriptionPeriod: 'subscriptionPeriod',
29+
title: 'title',
30+
type: SkuType.inapp,
31+
originalPrice: 'originalPrice',
32+
originalPriceAmountMicros: 1000,
33+
);
34+
35+
expect(skuDetails, isNotNull);
36+
expect(skuDetails.introductoryPriceAmountMicros, 0);
37+
// ignore: deprecated_member_use_from_same_package
38+
expect(skuDetails.introductoryPriceMicros, '990000');
39+
});
40+
41+
test(
42+
'`introductoryPriceAmoutMicros` constructor parameter is reflected by deprecated `introductoryPriceMicros` and `introductoryPriceAmountMicros` fields',
43+
() {
44+
final SkuDetailsWrapper skuDetails = SkuDetailsWrapper(
45+
description: 'description',
46+
freeTrialPeriod: 'freeTrialPeriod',
47+
introductoryPrice: 'introductoryPrice',
48+
introductoryPriceAmountMicros: 990000,
49+
introductoryPriceCycles: 1,
50+
introductoryPricePeriod: 'introductoryPricePeriod',
51+
price: 'price',
52+
priceAmountMicros: 1000,
53+
priceCurrencyCode: 'priceCurrencyCode',
54+
priceCurrencySymbol: r'$',
55+
sku: 'sku',
56+
subscriptionPeriod: 'subscriptionPeriod',
57+
title: 'title',
58+
type: SkuType.inapp,
59+
originalPrice: 'originalPrice',
60+
originalPriceAmountMicros: 1000,
61+
);
62+
63+
expect(skuDetails, isNotNull);
64+
expect(skuDetails.introductoryPriceAmountMicros, 990000);
65+
// ignore: deprecated_member_use_from_same_package
66+
expect(skuDetails.introductoryPriceMicros, '990000');
67+
});
68+
}

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)