Skip to content

Commit f4719ca

Browse files
authored
[in_app_purchase] implement countryCode correctly (#6636)
- **Rename getCountryCode to country code for ios and android IAP** - **Add changelog** fixes flutter/flutter#147230
1 parent 62c08f4 commit f4719ca

File tree

8 files changed

+30
-7
lines changed

8 files changed

+30
-7
lines changed

packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.5
2+
3+
* Replaces `getCountryCode` with `countryCode`.
4+
15
## 0.3.4+1
26

37
* Adds documentation for UserChoice and Alternative Billing.

packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,14 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform {
317317
///
318318
/// See: https://developer.android.com/reference/com/android/billingclient/api/BillingConfig
319319
/// See: https://unicode.org/cldr/charts/latest/supplemental/territory_containment_un_m_49.html
320-
Future<String> getCountryCode() async {
320+
@override
321+
Future<String> countryCode() async {
321322
final BillingConfigWrapper billingConfig = await billingClientManager
322323
.runWithClient((BillingClient client) => client.getBillingConfig());
323324
return billingConfig.countryCode;
324325
}
326+
327+
/// Use countryCode instead.
328+
@Deprecated('Use countryCode')
329+
Future<String> getCountryCode() => countryCode();
325330
}

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/packages/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.3.4+1
5+
version: 0.3.5
66

77
environment:
88
sdk: ^3.1.0

packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,12 @@ void main() {
760760

761761
when(mockApi.getBillingConfigAsync())
762762
.thenAnswer((_) async => platformBillingConfigFromWrapper(expected));
763-
final String countryCode = await iapAndroidPlatform.getCountryCode();
763+
final String countryCode = await iapAndroidPlatform.countryCode();
764764

765765
expect(countryCode, equals(expectedCountryCode));
766+
// Ensure deprecated code keeps working until removed.
767+
expect(await iapAndroidPlatform.getCountryCode(),
768+
equals(expectedCountryCode));
766769
});
767770
});
768771
}

packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.15
2+
3+
* Replaces `getCountryCode` with `countryCode`.
4+
15
## 0.3.14
26

37
* Adds `countryCode` API.

packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_storekit_platform.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,14 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform {
158158
///
159159
/// Uses the ISO 3166-1 Alpha-3 country code representation.
160160
/// See: https://developer.apple.com/documentation/storekit/skstorefront?language=objc
161-
Future<String?> getCountryCode() async {
162-
return (await _skPaymentQueueWrapper.storefront())?.countryCode;
161+
@override
162+
Future<String> countryCode() async {
163+
return (await _skPaymentQueueWrapper.storefront())?.countryCode ?? '';
163164
}
165+
166+
/// Use countryCode instead.
167+
@Deprecated('Use countryCode')
168+
Future<String?> getCountryCode() => countryCode();
164169
}
165170

166171
enum _TransactionRestoreState {

packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml

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

77
environment:
88
sdk: ^3.2.3

packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,10 @@ void main() {
576576
const String expectedCountryCode = 'CA';
577577
fakeStoreKitPlatform.setStoreFrontInfo(
578578
countryCode: expectedCountryCode, identifier: 'ABC');
579-
final String? countryCode = await iapStoreKitPlatform.getCountryCode();
579+
final String countryCode = await iapStoreKitPlatform.countryCode();
580580
expect(countryCode, expectedCountryCode);
581+
// Ensure deprecated code keeps working until removed.
582+
expect(await iapStoreKitPlatform.countryCode(), expectedCountryCode);
581583
});
582584
});
583585
}

0 commit comments

Comments
 (0)