|
22 | 22 | import com.android.billingclient.api.BillingClient;
|
23 | 23 | import com.android.billingclient.api.BillingClientStateListener;
|
24 | 24 | import com.android.billingclient.api.BillingFlowParams;
|
25 |
| -import com.android.billingclient.api.BillingFlowParams.ProrationMode; |
26 | 25 | import com.android.billingclient.api.BillingResult;
|
27 | 26 | import com.android.billingclient.api.ConsumeParams;
|
28 | 27 | import com.android.billingclient.api.ConsumeResponseListener;
|
@@ -67,6 +66,14 @@ static final class MethodNames {
|
67 | 66 | private MethodNames() {}
|
68 | 67 | }
|
69 | 68 |
|
| 69 | + // TODO(gmackall): Replace uses of deprecated ProrationMode enum values with new |
| 70 | + // ReplacementMode enum values. |
| 71 | + // https://github.com/flutter/flutter/issues/128957. |
| 72 | + @SuppressWarnings(value = "deprecation") |
| 73 | + private static final int PRORATION_MODE_UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY = |
| 74 | + com.android.billingclient.api.BillingFlowParams.ProrationMode |
| 75 | + .UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY; |
| 76 | + |
70 | 77 | private static final String TAG = "InAppPurchasePlugin";
|
71 | 78 | private static final String LOAD_PRODUCT_DOC_URL =
|
72 | 79 | "https://github.com/flutter/packages/blob/main/packages/in_app_purchase/in_app_purchase/README.md#loading-products-for-sale";
|
@@ -156,7 +163,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
|
156 | 163 | (String) call.argument("purchaseToken"),
|
157 | 164 | call.hasArgument("prorationMode")
|
158 | 165 | ? (int) call.argument("prorationMode")
|
159 |
| - : ProrationMode.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, |
| 166 | + : PRORATION_MODE_UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, |
160 | 167 | result);
|
161 | 168 | break;
|
162 | 169 | case MethodNames.QUERY_PURCHASES_ASYNC:
|
@@ -273,7 +280,7 @@ private void launchBillingFlow(
|
273 | 280 | }
|
274 | 281 |
|
275 | 282 | if (oldProduct == null
|
276 |
| - && prorationMode != ProrationMode.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY) { |
| 283 | + && prorationMode != PRORATION_MODE_UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY) { |
277 | 284 | result.error(
|
278 | 285 | "IN_APP_PURCHASE_REQUIRE_OLD_PRODUCT",
|
279 | 286 | "launchBillingFlow failed because oldProduct is null. You must provide a valid oldProduct in order to use a proration mode.",
|
@@ -322,15 +329,24 @@ private void launchBillingFlow(
|
322 | 329 | BillingFlowParams.SubscriptionUpdateParams.newBuilder();
|
323 | 330 | if (oldProduct != null && !oldProduct.isEmpty() && purchaseToken != null) {
|
324 | 331 | subscriptionUpdateParamsBuilder.setOldPurchaseToken(purchaseToken);
|
325 |
| - // The proration mode value has to match one of the following declared in |
326 |
| - // https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode |
327 |
| - subscriptionUpdateParamsBuilder.setReplaceProrationMode(prorationMode); |
| 332 | + // Set the prorationMode using a helper to minimize impact of deprecation warning suppression. |
| 333 | + setReplaceProrationMode(subscriptionUpdateParamsBuilder, prorationMode); |
328 | 334 | paramsBuilder.setSubscriptionUpdateParams(subscriptionUpdateParamsBuilder.build());
|
329 | 335 | }
|
330 | 336 | result.success(
|
331 | 337 | fromBillingResult(billingClient.launchBillingFlow(activity, paramsBuilder.build())));
|
332 | 338 | }
|
333 | 339 |
|
| 340 | + // TODO(gmackall): Replace uses of deprecated setReplaceProrationMode. |
| 341 | + // https://github.com/flutter/flutter/issues/128957. |
| 342 | + @SuppressWarnings(value = "deprecation") |
| 343 | + private void setReplaceProrationMode( |
| 344 | + BillingFlowParams.SubscriptionUpdateParams.Builder builder, int prorationMode) { |
| 345 | + // The proration mode value has to match one of the following declared in |
| 346 | + // https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode |
| 347 | + builder.setReplaceProrationMode(prorationMode); |
| 348 | + } |
| 349 | + |
334 | 350 | private void consumeAsync(String purchaseToken, final MethodChannel.Result result) {
|
335 | 351 | if (billingClientError(result)) {
|
336 | 352 | return;
|
|
0 commit comments