Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[in_app_purchase] Add api to expose country code #6540

Merged
merged 20 commits into from
Apr 17, 2024
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
3 changes: 2 additions & 1 deletion packages/in_app_purchase/in_app_purchase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 3.2.0

* Adds `countryCode` API.
* Updates minimum supported SDK version to Flutter 3.13/Dart 3.1.
* Updates support matrix in README to indicate that iOS 11 is no longer supported.
* Clients on versions of Flutter that still support iOS 11 can continue to use this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,20 @@ class InAppPurchase implements InAppPurchasePlatformAdditionProvider {
InAppPurchasePlatform.instance.restorePurchases(
applicationUserName: applicationUserName,
);

/// Returns the user's country.
///
/// Android:
/// Returns Play billing country code based on ISO-3166-1 alpha2 format.
///
/// See: https://developer.android.com/reference/com/android/billingclient/api/BillingConfig
/// See: https://unicode.org/cldr/charts/latest/supplemental/territory_containment_un_m_49.html
///
/// iOS:
/// Returns the country code from SKStoreFrontWrapper.
///
/// See: https://developer.apple.com/documentation/storekit/skstorefront?language=objc
///
///
Future<String> countryCode() => InAppPurchasePlatform.instance.countryCode();
}
12 changes: 6 additions & 6 deletions packages/in_app_purchase/in_app_purchase/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: in_app_purchase
description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play.
repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
version: 3.1.13
version: 3.2.0

environment:
sdk: ^3.1.0
flutter: ">=3.13.0"
sdk: ^3.2.3
flutter: ">=3.16.6"

flutter:
plugin:
Expand All @@ -21,9 +21,9 @@ flutter:
dependencies:
flutter:
sdk: flutter
in_app_purchase_android: ^0.3.0
in_app_purchase_platform_interface: ^1.0.0
in_app_purchase_storekit: ^0.3.4
in_app_purchase_android: ^0.3.4
in_app_purchase_platform_interface: ^1.4.0
in_app_purchase_storekit: ^0.3.14

dev_dependencies:
flutter_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ void main() {
]);
});

test('countryCode', () async {
final String country = await inAppPurchase.countryCode();
expect(country, 'USA');
expect(fakePlatform.log, <Matcher>[
isMethodCall('countryCode', arguments: null),
]);
});

test('purchaseStream', () async {
final bool isEmptyStream = await inAppPurchase.purchaseStream.isEmpty;
expect(isEmptyStream, true);
Expand Down Expand Up @@ -192,4 +200,10 @@ class MockInAppPurchasePlatform extends Fake
log.add(const MethodCall('restorePurchases'));
return Future<void>.value();
}

@override
Future<String> countryCode() {
log.add(const MethodCall('countryCode'));
return Future<String>.value('USA');
}
}