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

[in_app_purchase] Ensure the introductoryPriceMicros field is transported as a String. #4370

Merged
merged 5 commits into from
Sep 28, 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.1.5

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

## 0.1.4+7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was published; it shouldn't be removed from the changelog.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right and fixed it.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class SkuDetailsWrapper {
required this.description,
required this.freeTrialPeriod,
required this.introductoryPrice,
required this.introductoryPriceMicros,
@Deprecated('Use `introductoryPriceAmountMicros` parameter instead')
String introductoryPriceMicros = '',
this.introductoryPriceAmountMicros = 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the better option here is to make this int introductoryPriceAmountMicros,, and have the constructor body do:

introductoryPriceAmountMicros = introductoryPriceAmountMicros ?? int.tryParse(introductoryPriceMicros) ?? 0

Then you don't need all the complicated logic in the getter, or _introductoryPriceMicros.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that will work as the introductoryPriceAmountMicros parameter a not nullable and should always have a value. We could make it nullable but that means we need to later make it non-nullable again when we introduce the breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll be changing it to required at that point presumably to match everything else, and it will already be a breaking change in general, so that doesn't seem like a significant issue. But it's not a big deal either way.

required this.introductoryPriceCycles,
required this.introductoryPricePeriod,
required this.price,
Expand All @@ -45,7 +47,9 @@ class SkuDetailsWrapper {
required this.type,
required this.originalPrice,
required this.originalPriceAmountMicros,
});
}) : _introductoryPriceMicros = introductoryPriceMicros;

final String _introductoryPriceMicros;

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

/// [introductoryPrice] in micro-units 990000
@JsonKey(name: 'introductoryPriceAmountMicros', defaultValue: '')
final String introductoryPriceMicros;
/// [introductoryPrice] in micro-units 990000.
///
/// Returns 0 if the SKU is not a subscription or doesn't have an introductory
/// period.
@JsonKey(name: 'introductoryPriceAmountMicros', defaultValue: 0)
final int introductoryPriceAmountMicros;

/// String representation of [introductoryPrice] in micro-units 990000
@Deprecated('Use `introductoryPriceAmountMicros` instead.')
@JsonKey(ignore: true)
String get introductoryPriceMicros => _introductoryPriceMicros.isEmpty
? introductoryPriceAmountMicros.toString()
: _introductoryPriceMicros;

/// The number of subscription billing periods for which the user will be given the introductory price, such as 3.
/// Returns 0 if the SKU is not a subscription or doesn't have an introductory period.
Expand Down Expand Up @@ -131,7 +145,7 @@ class SkuDetailsWrapper {
other.description == description &&
other.freeTrialPeriod == freeTrialPeriod &&
other.introductoryPrice == introductoryPrice &&
other.introductoryPriceMicros == introductoryPriceMicros &&
other.introductoryPriceAmountMicros == introductoryPriceAmountMicros &&
other.introductoryPriceCycles == introductoryPriceCycles &&
other.introductoryPricePeriod == introductoryPricePeriod &&
other.price == price &&
Expand All @@ -150,7 +164,7 @@ class SkuDetailsWrapper {
description.hashCode,
freeTrialPeriod.hashCode,
introductoryPrice.hashCode,
introductoryPriceMicros.hashCode,
introductoryPriceAmountMicros.hashCode,
introductoryPriceCycles.hashCode,
introductoryPricePeriod.hashCode,
price.hashCode,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.1.4+7
version: 0.1.5

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(mvanbeusekom): Remove this file when the deprecated
// `SkuDetailsWrapper.introductoryPriceMicros` field is
// removed.

import 'package:flutter_test/flutter_test.dart';
import 'package:in_app_purchase_android/billing_client_wrappers.dart';

void main() {
test(
'Deprecated `introductoryPriceMicros` field reflects parameter from constructor',
() {
final SkuDetailsWrapper skuDetails = SkuDetailsWrapper(
description: 'description',
freeTrialPeriod: 'freeTrialPeriod',
introductoryPrice: 'introductoryPrice',
// ignore: deprecated_member_use_from_same_package
introductoryPriceMicros: '990000',
introductoryPriceCycles: 1,
introductoryPricePeriod: 'introductoryPricePeriod',
price: 'price',
priceAmountMicros: 1000,
priceCurrencyCode: 'priceCurrencyCode',
priceCurrencySymbol: r'$',
sku: 'sku',
subscriptionPeriod: 'subscriptionPeriod',
title: 'title',
type: SkuType.inapp,
originalPrice: 'originalPrice',
originalPriceAmountMicros: 1000,
);

expect(skuDetails, isNotNull);
expect(skuDetails.introductoryPriceAmountMicros, 0);
// ignore: deprecated_member_use_from_same_package
expect(skuDetails.introductoryPriceMicros, '990000');
});

test(
'`introductoryPriceAmoutMicros` constructor parameter is reflected by deprecated `introductoryPriceMicros` and `introductoryPriceAmountMicros` fields',
() {
final SkuDetailsWrapper skuDetails = SkuDetailsWrapper(
description: 'description',
freeTrialPeriod: 'freeTrialPeriod',
introductoryPrice: 'introductoryPrice',
introductoryPriceAmountMicros: 990000,
introductoryPriceCycles: 1,
introductoryPricePeriod: 'introductoryPricePeriod',
price: 'price',
priceAmountMicros: 1000,
priceCurrencyCode: 'priceCurrencyCode',
priceCurrencySymbol: r'$',
sku: 'sku',
subscriptionPeriod: 'subscriptionPeriod',
title: 'title',
type: SkuType.inapp,
originalPrice: 'originalPrice',
originalPriceAmountMicros: 1000,
);

expect(skuDetails, isNotNull);
expect(skuDetails.introductoryPriceAmountMicros, 990000);
// ignore: deprecated_member_use_from_same_package
expect(skuDetails.introductoryPriceMicros, '990000');
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final SkuDetailsWrapper dummySkuDetails = SkuDetailsWrapper(
description: 'description',
freeTrialPeriod: 'freeTrialPeriod',
introductoryPrice: 'introductoryPrice',
introductoryPriceMicros: 'introductoryPriceMicros',
introductoryPriceAmountMicros: 990000,
introductoryPriceCycles: 1,
introductoryPricePeriod: 'introductoryPricePeriod',
price: 'price',
Expand Down Expand Up @@ -134,7 +134,7 @@ Map<String, dynamic> buildSkuMap(SkuDetailsWrapper original) {
'description': original.description,
'freeTrialPeriod': original.freeTrialPeriod,
'introductoryPrice': original.introductoryPrice,
'introductoryPriceAmountMicros': original.introductoryPriceMicros,
'introductoryPriceAmountMicros': original.introductoryPriceAmountMicros,
'introductoryPriceCycles': original.introductoryPriceCycles,
'introductoryPricePeriod': original.introductoryPricePeriod,
'price': original.price,
Expand Down