Skip to content

Commit

Permalink
[in_app_purchase] implement countryCode correctly (flutter#6636)
Browse files Browse the repository at this point in the history
- **Rename getCountryCode to country code for ios and android IAP**
- **Add changelog**
fixes flutter/flutter#147230
  • Loading branch information
reidbaker authored May 2, 2024
1 parent 62c08f4 commit f4719ca
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.5

* Replaces `getCountryCode` with `countryCode`.

## 0.3.4+1

* Adds documentation for UserChoice and Alternative Billing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,14 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform {
///
/// 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<String> getCountryCode() async {
@override
Future<String> countryCode() async {
final BillingConfigWrapper billingConfig = await billingClientManager
.runWithClient((BillingClient client) => client.getBillingConfig());
return billingConfig.countryCode;
}

/// Use countryCode instead.
@Deprecated('Use countryCode')
Future<String> getCountryCode() => countryCode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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.4+1
version: 0.3.5

environment:
sdk: ^3.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,12 @@ void main() {

when(mockApi.getBillingConfigAsync())
.thenAnswer((_) async => platformBillingConfigFromWrapper(expected));
final String countryCode = await iapAndroidPlatform.getCountryCode();
final String countryCode = await iapAndroidPlatform.countryCode();

expect(countryCode, equals(expectedCountryCode));
// Ensure deprecated code keeps working until removed.
expect(await iapAndroidPlatform.getCountryCode(),
equals(expectedCountryCode));
});
});
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.15

* Replaces `getCountryCode` with `countryCode`.

## 0.3.14

* Adds `countryCode` API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,14 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform {
///
/// Uses the ISO 3166-1 Alpha-3 country code representation.
/// See: https://developer.apple.com/documentation/storekit/skstorefront?language=objc
Future<String?> getCountryCode() async {
return (await _skPaymentQueueWrapper.storefront())?.countryCode;
@override
Future<String> countryCode() async {
return (await _skPaymentQueueWrapper.storefront())?.countryCode ?? '';
}

/// Use countryCode instead.
@Deprecated('Use countryCode')
Future<String?> getCountryCode() => countryCode();
}

enum _TransactionRestoreState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.14
version: 0.3.15

environment:
sdk: ^3.2.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,10 @@ void main() {
const String expectedCountryCode = 'CA';
fakeStoreKitPlatform.setStoreFrontInfo(
countryCode: expectedCountryCode, identifier: 'ABC');
final String? countryCode = await iapStoreKitPlatform.getCountryCode();
final String countryCode = await iapStoreKitPlatform.countryCode();
expect(countryCode, expectedCountryCode);
// Ensure deprecated code keeps working until removed.
expect(await iapStoreKitPlatform.countryCode(), expectedCountryCode);
});
});
}

0 comments on commit f4719ca

Please sign in to comment.