Skip to content

[in_app_purchase] Update Play Billing library to 7.1.1 #8218

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c23348b
Upgrade Play Billing library to 7.1.1
mchudy Nov 21, 2024
0078d50
Remove proration mode references
mchudy Nov 21, 2024
ab5e118
Add InstallmentPlanDetails model
mchudy Nov 21, 2024
2c6f0ee
Add installment plan details wrapper model
mchudy Nov 22, 2024
4312cf7
Remove ProrationMode enum
mchudy Nov 25, 2024
ce29380
Update Android tests
mchudy Nov 26, 2024
dbc0161
Add PendingPurchaseUpdate model
mchudy Nov 26, 2024
cc9c473
Fix formatting
mchudy Nov 26, 2024
a67edf9
Adds support for pending prepaid plans
mchudy Dec 2, 2024
3acbb0f
Fix CHANGELOG formatting
mchudy Dec 2, 2024
ac183c4
Add native tests and fix formatting
mchudy Dec 3, 2024
fbaa88c
Update CHANGELOG
mchudy Dec 3, 2024
a88dfdd
Update pubspec.yaml
mchudy Dec 3, 2024
12ba75d
Update CHANGELOG and remove unnecessary ?
mchudy Dec 3, 2024
d1d33b0
Fix tests
mchudy Dec 4, 2024
0234a7c
Update CHANGELOG
mchudy Dec 4, 2024
58a9151
Revert CHANGELOG formatting change
mchudy Jan 6, 2025
e62c70c
CHANGELOG and comments nits
mchudy Jan 6, 2025
0a926bc
Add docs links
mchudy Jan 6, 2025
798d305
Rename PendingPurchasesParams to PlatformPendingPurchasesParams and m…
mchudy Jan 6, 2025
5c89a99
Fix typo in class name
mchudy Jan 6, 2025
682bb0e
Fix comments
mchudy Jan 6, 2025
a9c5677
Fix tests
mchudy Jan 6, 2025
75b21e9
Fix formatting
mchudy Jan 6, 2025
e630285
Bump min Flutter SDK version for in_app_purchase
mchudy Jan 9, 2025
dc4425c
Remove JsonSerializable from PendingPurchasesParamsWrapper
mchudy Jan 16, 2025
b584ff2
Remove JSON serialization from other classes
mchudy Jan 16, 2025
e9d8907
Introduce Pigeon enums to avoid using hardcoded ints in Dart code
mchudy Jan 17, 2025
faec504
Bump in_app_purchase version
mchudy Jan 17, 2025
9df2100
Fix formatting
mchudy Jan 17, 2025
16df184
User patch version update
mchudy Jan 17, 2025
7ab27c7
Remove json_serializable dependencies
mchudy Jan 20, 2025
ae5ccbd
Revert in_app_purchase changes
mchudy Jan 20, 2025
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
11 changes: 11 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,14 @@
## 0.4.0

* Updates Google Play Billing Library from 6.2.0 to 7.1.1.
* **BREAKING CHANGES**:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are doing a breaking change, this seems like a good opportunity to rip out all the pre-Pigeon JsonSerializable code that was deprecated previously. @gmackall is there any reason not to include that here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea, I have one question though. E.g. BillingResponseConverter was used to map from raw ints (Android defined constants) to public-facing BillingResponse enum. Naive approach would be to introduce a new function in pigeon_converters.dart:

BillingResponse billingResponseFromPlatformResponseCode(int responseCode) {
  return switch (responseCode) {
    -3 => BillingResponse.serviceTimeout,
    -2 => BillingResponse.featureNotSupported,
    -1 => BillingResponse.serviceDisconnected,
    0 => BillingResponse.ok,
    1 => BillingResponse.userCanceled,
    2 => BillingResponse.serviceUnavailable,
    3 => BillingResponse.billingUnavailable,
    4 => BillingResponse.itemUnavailable,
    5 => BillingResponse.developerError,
    6 => BillingResponse.error,
    7 => BillingResponse.itemAlreadyOwned,
    8 => BillingResponse.itemNotOwned,
    12 => BillingResponse.networkError,
    _ => BillingResponse.error,
  };
}

That looks a bit sketchy to me though as we have to deal with those hardcoded constants in Dart. Should we perhaps change the definition of PlatformBillingResult in Pigeon contract and introduce a new PlatformBillingResponse enum as part of this refactoring? If the mapping is performed on Java side we can refer to constants defined in the library so the code is more maintainable. Correct me if I'm wrong please.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we perhaps change the definition of PlatformBillingResult in Pigeon contract and introduce a new PlatformBillingResponse enum as part of this refactoring? If the mapping is performed on Java side we can refer to constants defined in the library so the code is more maintainable.

Yes, that's definitely what we want to do. The fact that we are still using BillingResponseConverter().fromJson in pigeon_converters.dart was a mistake on my part; I did an initial shallow conversion from manual method channels to Pigeon and then went back and converted objects more deeply to Pigeon structures in follow-ups, but missed this. We strongly prefer the clarity and safety of doing a Java constant -> Pigeon enum conversion in Java, then Pigeon enum -> Dart enum conversion in Dart, even though doing so is more verbose.

Copy link
Contributor Author

@mchudy mchudy Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored this and introduced new enums in Pigeon contracts. I also noticed that the representation of https://developer.android.com/reference/com/android/billingclient/api/BillingClient.FeatureType was very outdated so I made it match the current API. As it removes two variants it's another breaking changes, but I think it would be good to include this with those other breaking changes.

* Removes the deprecated `ProrationMode` enum. `ReplacementMode` should be used instead.
* Removes the deprecated `BillingClientWrapper.enablePendingPurchases` method.
* Removes JSON serialization from Dart wrapper classes.
* Removes `subscriptionsOnVR` and `inAppItemsOnVR` from `BillingClientFeature`.
* Adds `installmentPlanDetails` to `SubscriptionOfferDetailsWrapper`.
* Adds APIs to support pending transactions for subscription prepaid plans (`PendingPurchasesParams`).

## 0.3.6+13

* Updates androidx.annotation:annotation to 1.9.1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ android {
compileSdk 34

defaultConfig {
minSdk 19
minSdk 21
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand Down Expand Up @@ -60,7 +60,7 @@ android {

dependencies {
implementation 'androidx.annotation:annotation:1.9.1'
implementation 'com.android.billingclient:billing:6.2.0'
implementation 'com.android.billingclient:billing:7.1.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20250107'
testImplementation 'org.mockito:mockito-core:5.4.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ interface BillingClientFactory {
* @param callbackApi The callback API to be used by the {@link BillingClient}.
* @param billingChoiceMode Enables the ability to offer alternative billing or Google Play
* billing.
* @param pendingPurchasesParams Parameters to enable pending purchases. See {@link
* com.android.billingclient.api.PendingPurchasesParams}.
* @return The {@link BillingClient} object that is created.
*/
BillingClient createBillingClient(
@NonNull Context context,
@NonNull Messages.InAppPurchaseCallbackApi callbackApi,
PlatformBillingChoiceMode billingChoiceMode);
PlatformBillingChoiceMode billingChoiceMode,
Messages.PlatformPendingPurchasesParams pendingPurchasesParams);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package io.flutter.plugins.inapppurchase;

import static io.flutter.plugins.inapppurchase.Translator.fromUserChoiceDetails;
import static io.flutter.plugins.inapppurchase.Translator.toPendingPurchasesParams;

import android.content.Context;
import androidx.annotation.NonNull;
Expand All @@ -21,8 +22,11 @@ final class BillingClientFactoryImpl implements BillingClientFactory {
public BillingClient createBillingClient(
@NonNull Context context,
@NonNull Messages.InAppPurchaseCallbackApi callbackApi,
PlatformBillingChoiceMode billingChoiceMode) {
BillingClient.Builder builder = BillingClient.newBuilder(context).enablePendingPurchases();
PlatformBillingChoiceMode billingChoiceMode,
Messages.PlatformPendingPurchasesParams pendingPurchasesParams) {
BillingClient.Builder builder =
BillingClient.newBuilder(context)
.enablePendingPurchases(toPendingPurchasesParams(pendingPurchasesParams));
switch (billingChoiceMode) {
case ALTERNATIVE_BILLING_ONLY:
// https://developer.android.com/google/play/billing/alternative/alternative-billing-without-user-choice-in-app
Expand Down
Loading
Loading