-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[in_app_purchase] Add play country code api #5941
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
Changes from 13 commits
5be7c0a
5d6f1cc
e19b644
3f5a4e3
337a7d7
99af529
fdc42cd
88ccd2a
036e2f2
91950f3
7d4af42
5cd0acb
894473c
e33f22c
1dc004b
319ffe7
28e95ad
3c263a8
4cd74ec
d7934fc
5252d6e
5e363fc
62477c4
a514dc1
f047aac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| ## NEXT | ||
| ## 0.3.0+18 | ||
|
|
||
| * Adds country code api for android. | ||
| * Updates compileSdk version to 34. | ||
|
|
||
| ## 0.3.0+17 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:json_annotation/json_annotation.dart'; | ||
|
|
||
| import '../../billing_client_wrappers.dart'; | ||
|
|
||
| // WARNING: Changes to `@JsonSerializable` classes need to be reflected in the | ||
| // below generated file. Run `flutter packages pub run build_runner watch` to | ||
| // rebuild and watch for further changes. | ||
| part 'billing_config_wrapper.g.dart'; | ||
|
|
||
| /// The error message shown when the map represents billing config is invalid from method channel. | ||
| /// | ||
| /// This usually indicates a serious underlining code issue in the plugin. | ||
| @visibleForTesting | ||
| const String kInvalidBillingConfigErrorMessage = | ||
| 'Invalid billing config map from method channel.'; | ||
|
|
||
| /// Params containing the response code and the debug message from the Play Billing API response. | ||
| @JsonSerializable() | ||
| @BillingResponseConverter() | ||
| @immutable | ||
| class BillingConfigWrapper implements HasBillingResponse { | ||
| /// Constructs the object with [responseCode] and [debugMessage]. | ||
| const BillingConfigWrapper( | ||
| {required this.responseCode, this.debugMessage, this.countryCode = ''}); | ||
|
|
||
| /// Constructs an instance of this from a key value map of data. | ||
| /// | ||
| /// The map needs to have named string keys with values matching the names and | ||
| /// types of all of the members on this class. | ||
| factory BillingConfigWrapper.fromJson(Map<String, dynamic>? map) { | ||
| if (map == null || map.isEmpty) { | ||
| return const BillingConfigWrapper( | ||
| responseCode: BillingResponse.error, | ||
| debugMessage: kInvalidBillingConfigErrorMessage, | ||
| ); | ||
| } | ||
| return _$BillingConfigWrapperFromJson(map); | ||
| } | ||
|
|
||
| /// Response code returned in the Play Billing API calls. | ||
| @override | ||
| final BillingResponse responseCode; | ||
|
|
||
| /// Debug message returned in the Play Billing API calls. | ||
| /// | ||
| /// Defaults to `null`. | ||
| /// This message uses an en-US locale and should not be shown to users. | ||
| @JsonKey(defaultValue: '') | ||
| final String? debugMessage; | ||
|
|
||
| /// https://developer.android.com/reference/com/android/billingclient/api/BillingConfig#getCountryCode() | ||
| @JsonKey(defaultValue: '') | ||
| final String countryCode; | ||
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (other.runtimeType != runtimeType) { | ||
| return false; | ||
| } | ||
|
|
||
| return other is BillingConfigWrapper && | ||
| other.responseCode == responseCode && | ||
| other.debugMessage == debugMessage && | ||
| other.countryCode == countryCode; | ||
| } | ||
|
|
||
| @override | ||
| int get hashCode => Object.hash(responseCode, debugMessage, countryCode); | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -146,4 +146,15 @@ class InAppPurchaseAndroidPlatformAddition | |||
| (BillingClient client) => client.isFeatureSupported(feature), | ||||
| ); | ||||
| } | ||||
|
|
||||
| /// 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<String> getBillingConfig() async { | ||||
| return _billingClientManager.runWithClientNonRetryable( | ||||
|
||||
| /// Designed only for operations that do not return a subclass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to keep the exposed api as small as possible so I thought the country code was the right level to expose. I didnt even think about if it should be retryable I just mirrored the other commands. Let me look at what that does and make a call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment still applies
Uh oh!
There was an error while loading. Please reload this page.