Skip to content

[in_app_purchase_android] Bump com.android.billingclient:billing from 5.2.0 to 6.0.0. #4390

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 6 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0+9

* Bumps com.android.billingclient:billing from 5.2.0 to 6.0.0.

## 0.3.0+8

* Adds a [guide for migrating](migration_guide.md) to [0.3.0](#0.3.0).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dependencies {
// org.jetbrains.kotlin:kotlin-bom artifact purpose is to align kotlin stdlib and related code versions.
// See: https://youtrack.jetbrains.com/issue/KT-55297/kotlin-stdlib-should-declare-constraints-on-kotlin-stdlib-jdk8-and-kotlin-stdlib-jdk7
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.22"))
implementation 'com.android.billingclient:billing:5.2.0'
implementation 'com.android.billingclient:billing:6.0.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20230618'
testImplementation 'org.mockito:mockito-core:5.4.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingClientStateListener;
import com.android.billingclient.api.BillingFlowParams;
import com.android.billingclient.api.BillingFlowParams.ProrationMode;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.ConsumeParams;
import com.android.billingclient.api.ConsumeResponseListener;
Expand Down Expand Up @@ -67,6 +66,14 @@ static final class MethodNames {
private MethodNames() {}
}

// TODO(gmackall): Replace uses of deprecated ProrationMode enum values with new
// ReplacementMode enum values.
// https://github.com/flutter/flutter/issues/128957.
@SuppressWarnings(value = "deprecation")
private static final int PRORATION_MODE_UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY =
com.android.billingclient.api.BillingFlowParams.ProrationMode
.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY;

private static final String TAG = "InAppPurchasePlugin";
private static final String LOAD_PRODUCT_DOC_URL =
"https://github.com/flutter/packages/blob/main/packages/in_app_purchase/in_app_purchase/README.md#loading-products-for-sale";
Expand Down Expand Up @@ -156,7 +163,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
(String) call.argument("purchaseToken"),
call.hasArgument("prorationMode")
? (int) call.argument("prorationMode")
: ProrationMode.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY,
: PRORATION_MODE_UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY,
result);
break;
case MethodNames.QUERY_PURCHASES_ASYNC:
Expand Down Expand Up @@ -273,7 +280,7 @@ private void launchBillingFlow(
}

if (oldProduct == null
&& prorationMode != ProrationMode.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY) {
&& prorationMode != PRORATION_MODE_UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY) {
result.error(
"IN_APP_PURCHASE_REQUIRE_OLD_PRODUCT",
"launchBillingFlow failed because oldProduct is null. You must provide a valid oldProduct in order to use a proration mode.",
Expand Down Expand Up @@ -322,15 +329,24 @@ private void launchBillingFlow(
BillingFlowParams.SubscriptionUpdateParams.newBuilder();
if (oldProduct != null && !oldProduct.isEmpty() && purchaseToken != null) {
subscriptionUpdateParamsBuilder.setOldPurchaseToken(purchaseToken);
// The proration mode value has to match one of the following declared in
// https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode
subscriptionUpdateParamsBuilder.setReplaceProrationMode(prorationMode);
// Set the prorationMode using a helper to minimize impact of deprecation warning suppression.
setReplaceProrationMode(subscriptionUpdateParamsBuilder, prorationMode);
paramsBuilder.setSubscriptionUpdateParams(subscriptionUpdateParamsBuilder.build());
}
result.success(
fromBillingResult(billingClient.launchBillingFlow(activity, paramsBuilder.build())));
}

// TODO(gmackall): Replace uses of deprecated setReplaceProrationMode.
// https://github.com/flutter/flutter/issues/128957.
@SuppressWarnings(value = "deprecation")
private void setReplaceProrationMode(
BillingFlowParams.SubscriptionUpdateParams.Builder builder, int prorationMode) {
// The proration mode value has to match one of the following declared in
// https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode
builder.setReplaceProrationMode(prorationMode);
}

private void consumeAsync(String purchaseToken, final MethodChannel.Result result) {
if (billingClientError(result)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,11 @@ public void launchBillingFlow_ok_AccountId() {
verify(result, times(1)).success(fromBillingResult(billingResult));
}

// TODO(gmackall): Replace uses of deprecated ProrationMode enum values with new
// ReplacementMode enum values.
// https://github.com/flutter/flutter/issues/128957.
@Test
@SuppressWarnings(value = "deprecation")
public void launchBillingFlow_ok_Proration() {
// Fetch the product details first and query the method call
String productId = "foo";
Expand Down Expand Up @@ -453,7 +457,11 @@ public void launchBillingFlow_ok_Proration() {
verify(result, times(1)).success(fromBillingResult(billingResult));
}

// TODO(gmackall): Replace uses of deprecated ProrationMode enum values with new
// ReplacementMode enum values.
// https://github.com/flutter/flutter/issues/128957.
@Test
@SuppressWarnings(value = "deprecation")
public void launchBillingFlow_ok_Proration_with_null_OldProduct() {
// Fetch the product details first and query the method call
String productId = "foo";
Expand Down Expand Up @@ -487,7 +495,11 @@ public void launchBillingFlow_ok_Proration_with_null_OldProduct() {
verify(result, never()).success(any());
}

// TODO(gmackall): Replace uses of deprecated ProrationMode enum values with new
// ReplacementMode enum values.
// https://github.com/flutter/flutter/issues/128957.
@Test
@SuppressWarnings(value = "deprecation")
public void launchBillingFlow_ok_Full() {
// Fetch the product details first and query the method call
String productId = "foo";
Expand Down
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.0+8
version: 0.3.0+9

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down