mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 15:23:25 +08:00
[in_app_purchase_android] Bump com.android.billingclient:billing from 5.2.0 to 6.0.0. (#4390)
Takeover of https://github.com/flutter/packages/pull/3988/ Conflicts had built up and it required some additional changes so I figured it would be easier to just make my own new branch to fix. Changes from last PR 1. I made the particular ProrationMode enum value we were using a constant and put the deprecation suppression on that constant. 2. I made a helper to wrap the other deprecated method (`setReplaceProrationMode`). 3. Added todos with links to the issue for replacing the deprecated classes/methods.
This commit is contained in:
@ -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).
|
||||
|
@ -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'
|
||||
|
@ -22,7 +22,6 @@ import com.android.billingclient.api.AcknowledgePurchaseParams;
|
||||
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;
|
||||
@ -67,6 +66,14 @@ class MethodCallHandlerImpl
|
||||
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";
|
||||
@ -156,7 +163,7 @@ class MethodCallHandlerImpl
|
||||
(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:
|
||||
@ -273,7 +280,7 @@ class MethodCallHandlerImpl
|
||||
}
|
||||
|
||||
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.",
|
||||
@ -322,15 +329,24 @@ class MethodCallHandlerImpl
|
||||
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;
|
||||
|
@ -416,7 +416,11 @@ public class MethodCallHandlerTest {
|
||||
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";
|
||||
@ -453,7 +457,11 @@ public class MethodCallHandlerTest {
|
||||
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";
|
||||
@ -487,7 +495,11 @@ public class MethodCallHandlerTest {
|
||||
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";
|
||||
|
@ -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"
|
||||
|
Reference in New Issue
Block a user