diff --git a/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md b/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md index c77ce6fbc98b..20d700ac410d 100644 --- a/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md +++ b/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.4 + +* Adds `countryCode` API. + ## 0.3.3+1 * Moves alternative billing listener creation to BillingClientFactoryImpl. diff --git a/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart b/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart index 9663aa414d5d..9b9e2f1b1ea2 100644 --- a/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart +++ b/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart @@ -11,6 +11,7 @@ import 'package:in_app_purchase_platform_interface/in_app_purchase_platform_inte import '../billing_client_wrappers.dart'; import '../in_app_purchase_android.dart'; +import 'billing_client_wrappers/billing_config_wrapper.dart'; /// [IAPError.code] code for failed purchases. const String kPurchaseErrorCode = 'purchase_error'; @@ -311,4 +312,14 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform { ]; } } + + /// 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 + Future getCountryCode() async { + final BillingConfigWrapper billingConfig = await billingClientManager + .runWithClient((BillingClient client) => client.getBillingConfig()); + return billingConfig.countryCode; + } } diff --git a/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform_addition.dart b/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform_addition.dart index e8c6f07a0bc7..c0ca171ad6d2 100644 --- a/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform_addition.dart +++ b/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform_addition.dart @@ -167,6 +167,7 @@ class InAppPurchaseAndroidPlatformAddition /// /// 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 + @Deprecated('Use InAppPurchasePlatfrom.getCountryCode') Future getCountryCode() async { final BillingConfigWrapper billingConfig = await _billingClientManager .runWithClient((BillingClient client) => client.getBillingConfig()); diff --git a/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml b/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml index 4d5f491d3fa1..6950533f1caf 100644 --- a/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml +++ b/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml @@ -2,7 +2,8 @@ name: in_app_purchase_android description: An implementation for the Android platform of the Flutter `in_app_purchase` plugin. This uses the Android BillingClient APIs. repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22 -version: 0.3.3+1 + +version: 0.3.4 environment: sdk: ^3.1.0 @@ -20,7 +21,7 @@ dependencies: collection: ^1.15.0 flutter: sdk: flutter - in_app_purchase_platform_interface: ^1.3.0 + in_app_purchase_platform_interface: ^1.4.0 json_annotation: ^4.8.0 dev_dependencies: diff --git a/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart b/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart index c4e92602d983..c5e5d628ef81 100644 --- a/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart +++ b/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart @@ -9,10 +9,12 @@ import 'package:flutter/widgets.dart' as widgets; import 'package:flutter_test/flutter_test.dart'; import 'package:in_app_purchase_android/billing_client_wrappers.dart'; import 'package:in_app_purchase_android/in_app_purchase_android.dart'; +import 'package:in_app_purchase_android/src/billing_client_wrappers/billing_config_wrapper.dart'; import 'package:in_app_purchase_android/src/messages.g.dart'; import 'package:in_app_purchase_platform_interface/in_app_purchase_platform_interface.dart'; import 'package:mockito/mockito.dart'; +import 'billing_client_wrappers/billing_client_wrapper_test.dart'; import 'billing_client_wrappers/billing_client_wrapper_test.mocks.dart'; import 'billing_client_wrappers/product_details_wrapper_test.dart'; import 'billing_client_wrappers/purchase_wrapper_test.dart'; @@ -747,4 +749,20 @@ void main() { expect(await completer.future, equals(expectedBillingResult)); }); }); + + group('billingConfig', () { + test('getCountryCode success', () async { + const String expectedCountryCode = 'US'; + const BillingConfigWrapper expected = BillingConfigWrapper( + countryCode: expectedCountryCode, + responseCode: BillingResponse.ok, + debugMessage: 'dummy message'); + + when(mockApi.getBillingConfigAsync()) + .thenAnswer((_) async => platformBillingConfigFromWrapper(expected)); + final String countryCode = await iapAndroidPlatform.getCountryCode(); + + expect(countryCode, equals(expectedCountryCode)); + }); + }); } diff --git a/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md b/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md index fce36eb13a6b..114dc9e8df59 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md +++ b/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.14 + +* Adds `countryCode` API. + ## 0.3.13+1 * Handle translation of errors nested in dictionaries. diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_storekit_platform.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_storekit_platform.dart index 9dbdc4785788..acdc4a2979c5 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_storekit_platform.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_storekit_platform.dart @@ -153,6 +153,14 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform { ); return productDetailsResponse; } + + /// Returns the country code from SKStoreFrontWrapper. + /// + /// Uses the ISO 3166-1 Alpha-3 country code representation. + /// See: https://developer.apple.com/documentation/storekit/skstorefront?language=objc + Future getCountryCode() async { + return (await _skPaymentQueueWrapper.storefront())?.countryCode; + } } enum _TransactionRestoreState { diff --git a/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml b/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml index 08ba026a014a..d20cdec6ff15 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml +++ b/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml @@ -2,7 +2,7 @@ name: in_app_purchase_storekit description: An implementation for the iOS and macOS platforms of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework. repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_storekit issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22 -version: 0.3.13+1 +version: 0.3.14 environment: sdk: ^3.2.3 @@ -23,7 +23,7 @@ dependencies: collection: ^1.15.0 flutter: sdk: flutter - in_app_purchase_platform_interface: ^1.3.0 + in_app_purchase_platform_interface: ^1.4.0 json_annotation: ^4.3.0 dev_dependencies: diff --git a/packages/in_app_purchase/in_app_purchase_storekit/test/fakes/fake_storekit_platform.dart b/packages/in_app_purchase/in_app_purchase_storekit/test/fakes/fake_storekit_platform.dart index 8fff5754eb77..f5a755d83b55 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/test/fakes/fake_storekit_platform.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/test/fakes/fake_storekit_platform.dart @@ -27,6 +27,8 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { bool queueIsActive = false; Map discountReceived = {}; bool isPaymentQueueDelegateRegistered = false; + String _countryCode = 'USA'; + String _countryIdentifier = 'LL'; void reset() { transactionList = []; @@ -53,6 +55,8 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { queueIsActive = false; discountReceived = {}; isPaymentQueueDelegateRegistered = false; + _countryCode = 'USA'; + _countryIdentifier = 'LL'; } SKPaymentTransactionWrapper createPendingTransaction(String id, @@ -163,9 +167,16 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { } } + void setStoreFrontInfo( + {required String countryCode, required String identifier}) { + _countryCode = countryCode; + _countryIdentifier = identifier; + } + @override SKStorefrontMessage storefront() { - throw UnimplementedError(); + return SKStorefrontMessage( + countryCode: _countryCode, identifier: _countryIdentifier); } @override diff --git a/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart b/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart index e268c23bdaa4..97d13509fdbb 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart @@ -570,4 +570,14 @@ void main() { expect(fakeStoreKitPlatform.queueIsActive, false); }); }); + + group('billing configuration', () { + test('country_code', () async { + const String expectedCountryCode = 'CA'; + fakeStoreKitPlatform.setStoreFrontInfo( + countryCode: expectedCountryCode, identifier: 'ABC'); + final String? countryCode = await iapStoreKitPlatform.getCountryCode(); + expect(countryCode, expectedCountryCode); + }); + }); }