Skip to content

Commit

Permalink
[in_app_purchase] Add api to expose country code (#6540)
Browse files Browse the repository at this point in the history
- **Add changelog and version bump**
- **dependency override from package tool**

Fixes flutter/flutter/issues/141627
  • Loading branch information
reidbaker authored Apr 17, 2024
1 parent ba1e24b commit 3f4c0f5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
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
16 changes: 16 additions & 0 deletions packages/in_app_purchase/in_app_purchase/lib/in_app_purchase.dart
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');
}
}

0 comments on commit 3f4c0f5

Please sign in to comment.