Skip to content

Commit 3f4c0f5

Browse files
authored
[in_app_purchase] Add api to expose country code (#6540)
- **Add changelog and version bump** - **dependency override from package tool** Fixes flutter/flutter/issues/141627
1 parent ba1e24b commit 3f4c0f5

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

packages/in_app_purchase/in_app_purchase/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 3.2.0
22

3+
* Adds `countryCode` API.
34
* Updates minimum supported SDK version to Flutter 3.13/Dart 3.1.
45
* Updates support matrix in README to indicate that iOS 11 is no longer supported.
56
* Clients on versions of Flutter that still support iOS 11 can continue to use this

packages/in_app_purchase/in_app_purchase/lib/in_app_purchase.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,20 @@ class InAppPurchase implements InAppPurchasePlatformAdditionProvider {
209209
InAppPurchasePlatform.instance.restorePurchases(
210210
applicationUserName: applicationUserName,
211211
);
212+
213+
/// Returns the user's country.
214+
///
215+
/// Android:
216+
/// Returns Play billing country code based on ISO-3166-1 alpha2 format.
217+
///
218+
/// See: https://developer.android.com/reference/com/android/billingclient/api/BillingConfig
219+
/// See: https://unicode.org/cldr/charts/latest/supplemental/territory_containment_un_m_49.html
220+
///
221+
/// iOS:
222+
/// Returns the country code from SKStoreFrontWrapper.
223+
///
224+
/// See: https://developer.apple.com/documentation/storekit/skstorefront?language=objc
225+
///
226+
///
227+
Future<String> countryCode() => InAppPurchasePlatform.instance.countryCode();
212228
}

packages/in_app_purchase/in_app_purchase/pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: in_app_purchase
22
description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play.
33
repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
5-
version: 3.1.13
5+
version: 3.2.0
66

77
environment:
8-
sdk: ^3.1.0
9-
flutter: ">=3.13.0"
8+
sdk: ^3.2.3
9+
flutter: ">=3.16.6"
1010

1111
flutter:
1212
plugin:
@@ -21,9 +21,9 @@ flutter:
2121
dependencies:
2222
flutter:
2323
sdk: flutter
24-
in_app_purchase_android: ^0.3.0
25-
in_app_purchase_platform_interface: ^1.0.0
26-
in_app_purchase_storekit: ^0.3.4
24+
in_app_purchase_android: ^0.3.4
25+
in_app_purchase_platform_interface: ^1.4.0
26+
in_app_purchase_storekit: ^0.3.14
2727

2828
dev_dependencies:
2929
flutter_test:

packages/in_app_purchase/in_app_purchase/test/in_app_purchase_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ void main() {
5555
]);
5656
});
5757

58+
test('countryCode', () async {
59+
final String country = await inAppPurchase.countryCode();
60+
expect(country, 'USA');
61+
expect(fakePlatform.log, <Matcher>[
62+
isMethodCall('countryCode', arguments: null),
63+
]);
64+
});
65+
5866
test('purchaseStream', () async {
5967
final bool isEmptyStream = await inAppPurchase.purchaseStream.isEmpty;
6068
expect(isEmptyStream, true);
@@ -192,4 +200,10 @@ class MockInAppPurchasePlatform extends Fake
192200
log.add(const MethodCall('restorePurchases'));
193201
return Future<void>.value();
194202
}
203+
204+
@override
205+
Future<String> countryCode() {
206+
log.add(const MethodCall('countryCode'));
207+
return Future<String>.value('USA');
208+
}
195209
}

0 commit comments

Comments
 (0)