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

Commit 893ba49

Browse files
authored
[in_app_purchase] Added country code to sk product wrapper (#4122)
1 parent c36c007 commit 893ba49

File tree

9 files changed

+46
-12
lines changed

9 files changed

+46
-12
lines changed

packages/in_app_purchase/in_app_purchase_ios/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.2
2+
3+
* Added countryCode to the SKPriceLocaleWrapper.
4+
15
## 0.1.1+1
26

37
* iOS: Fix treating missing App Store receipt as an exception.

packages/in_app_purchase/in_app_purchase_ios/example/ios/RunnerTests/TranslatorTests.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ - (void)testError {
149149

150150
- (void)testLocaleToMap {
151151
if (@available(iOS 10.0, *)) {
152-
NSLocale *system = NSLocale.systemLocale;
152+
NSLocale *system = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
153153
NSDictionary *map = [FIAObjectTranslator getMapFromNSLocale:system];
154154
XCTAssertEqualObjects(map[@"currencySymbol"], system.currencySymbol);
155+
XCTAssertEqualObjects(map[@"countryCode"], system.countryCode);
155156
}
156157
}
157158

packages/in_app_purchase/in_app_purchase_ios/ios/Classes/FIAObjectTranslator.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ + (NSDictionary *)getMapFromNSLocale:(NSLocale *)locale {
111111
forKey:@"currencySymbol"];
112112
[map setObject:[locale objectForKey:NSLocaleCurrencyCode] ?: [NSNull null]
113113
forKey:@"currencyCode"];
114+
[map setObject:[locale objectForKey:NSLocaleCountryCode] ?: [NSNull null] forKey:@"countryCode"];
114115
return map;
115116
}
116117

packages/in_app_purchase/in_app_purchase_ios/lib/src/store_kit_wrappers/sk_product_wrapper.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,19 @@ class SKProductWrapper {
335335
@JsonSerializable()
336336
class SKPriceLocaleWrapper {
337337
/// Creates a new price locale for `currencySymbol` and `currencyCode`.
338-
SKPriceLocaleWrapper(
339-
{required this.currencySymbol, required this.currencyCode});
338+
SKPriceLocaleWrapper({
339+
required this.currencySymbol,
340+
required this.currencyCode,
341+
required this.countryCode,
342+
});
340343

341344
/// Constructing an instance from a map from the Objective-C layer.
342345
///
343346
/// This method should only be used with `map` values returned by [SKProductWrapper.fromJson] and [SKProductDiscountWrapper.fromJson].
344347
factory SKPriceLocaleWrapper.fromJson(Map<String, dynamic>? map) {
345348
if (map == null) {
346-
return SKPriceLocaleWrapper(currencyCode: '', currencySymbol: '');
349+
return SKPriceLocaleWrapper(
350+
currencyCode: '', currencySymbol: '', countryCode: '');
347351
}
348352
return _$SKPriceLocaleWrapperFromJson(map);
349353
}
@@ -356,6 +360,10 @@ class SKPriceLocaleWrapper {
356360
@JsonKey(defaultValue: '')
357361
final String currencyCode;
358362

363+
///The country code for the locale, e.g. US for US locale.
364+
@JsonKey(defaultValue: '')
365+
final String countryCode;
366+
359367
@override
360368
bool operator ==(Object other) {
361369
if (identical(other, this)) {

packages/in_app_purchase/in_app_purchase_ios/lib/src/store_kit_wrappers/sk_product_wrapper.g.dart

Lines changed: 2 additions & 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_ios/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: in_app_purchase_ios
22
description: An implementation for the iOS platform of the Flutter `in_app_purchase` plugin. This uses the iOS StoreKit Framework.
33
repository: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase/in_app_purchase_ios
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.1+1
5+
version: 0.1.2
66

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

packages/in_app_purchase/in_app_purchase_ios/test/store_kit_wrappers/sk_methodchannel_apis_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ void main() {
4747
productResponseWrapper.products.first.priceLocale.currencyCode,
4848
'USD',
4949
);
50+
expect(
51+
productResponseWrapper.products.first.priceLocale.countryCode,
52+
'US',
53+
);
5054
expect(
5155
productResponseWrapper.invalidProductIdentifiers,
5256
isNotEmpty,

packages/in_app_purchase/in_app_purchase_ios/test/store_kit_wrappers/sk_product_test.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ void main() {
4444
final SKProductDiscountWrapper wrapper =
4545
SKProductDiscountWrapper.fromJson(<String, dynamic>{});
4646
expect(wrapper.price, '');
47-
expect(wrapper.priceLocale,
48-
SKPriceLocaleWrapper(currencyCode: '', currencySymbol: ''));
47+
expect(
48+
wrapper.priceLocale,
49+
SKPriceLocaleWrapper(
50+
currencyCode: '',
51+
currencySymbol: '',
52+
countryCode: '',
53+
));
4954
expect(wrapper.numberOfPeriods, 0);
5055
expect(wrapper.paymentMode, SKProductDiscountPaymentMode.payAsYouGo);
5156
expect(
@@ -69,8 +74,13 @@ void main() {
6974
expect(wrapper.productIdentifier, '');
7075
expect(wrapper.localizedTitle, '');
7176
expect(wrapper.localizedDescription, '');
72-
expect(wrapper.priceLocale,
73-
SKPriceLocaleWrapper(currencyCode: '', currencySymbol: ''));
77+
expect(
78+
wrapper.priceLocale,
79+
SKPriceLocaleWrapper(
80+
currencyCode: '',
81+
currencySymbol: '',
82+
countryCode: '',
83+
));
7484
expect(wrapper.subscriptionGroupIdentifier, null);
7585
expect(wrapper.price, '');
7686
expect(wrapper.subscriptionPeriod, null);

packages/in_app_purchase/in_app_purchase_ios/test/store_kit_wrappers/sk_test_stub_objects.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ final SKPaymentTransactionWrapper dummyTransaction =
3333
error: dummyError,
3434
);
3535

36-
final SKPriceLocaleWrapper dummyLocale =
37-
SKPriceLocaleWrapper(currencySymbol: '\$', currencyCode: 'USD');
36+
final SKPriceLocaleWrapper dummyLocale = SKPriceLocaleWrapper(
37+
currencySymbol: '\$',
38+
currencyCode: 'USD',
39+
countryCode: 'US',
40+
);
3841

3942
final SKProductSubscriptionPeriodWrapper dummySubscription =
4043
SKProductSubscriptionPeriodWrapper(
@@ -70,7 +73,8 @@ final SkProductResponseWrapper dummyProductResponseWrapper =
7073
Map<String, dynamic> buildLocaleMap(SKPriceLocaleWrapper local) {
7174
return {
7275
'currencySymbol': local.currencySymbol,
73-
'currencyCode': local.currencyCode
76+
'currencyCode': local.currencyCode,
77+
'countryCode': local.countryCode,
7478
};
7579
}
7680

0 commit comments

Comments
 (0)