[in_app_purchase] Deprecated the `InAppPurchaseAndroidPlatformAddition.enablePendingPurchases` method. (#4527)
diff --git a/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md b/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
index 4198d93..9bce54c 100644
--- a/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
+++ b/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
@@ -1,6 +1,7 @@
-## NEXT
+## 0.2.1
-* Updates compileSdkVersion to 31.
+* Deprecated the `InAppPurchaseAndroidPlatformAddition.enablePendingPurchases()` method and `InAppPurchaseAndroidPlatformAddition.enablePendingPurchase` property. Since Google Play no longer accepts App submissions that don't support pending purchases it is no longer necessary to acknowledge this through code.
+* Updates example app Android compileSdkVersion to 31.
## 0.2.0
diff --git a/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/BillingClientFactory.java b/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/BillingClientFactory.java
index 7b21cbf..81fdf27 100644
--- a/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/BillingClientFactory.java
+++ b/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/BillingClientFactory.java
@@ -17,10 +17,7 @@
*
* @param context The context used to create the {@link BillingClient}.
* @param channel The method channel used to create the {@link BillingClient}.
- * @param enablePendingPurchases Whether to enable pending purchases. Throws an exception if it is
- * false.
* @return The {@link BillingClient} object that is created.
*/
- BillingClient createBillingClient(
- @NonNull Context context, @NonNull MethodChannel channel, boolean enablePendingPurchases);
+ BillingClient createBillingClient(@NonNull Context context, @NonNull MethodChannel channel);
}
diff --git a/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/BillingClientFactoryImpl.java b/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/BillingClientFactoryImpl.java
index c256d2c..6d26398 100644
--- a/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/BillingClientFactoryImpl.java
+++ b/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/BillingClientFactoryImpl.java
@@ -12,12 +12,9 @@
final class BillingClientFactoryImpl implements BillingClientFactory {
@Override
- public BillingClient createBillingClient(
- Context context, MethodChannel channel, boolean enablePendingPurchases) {
- BillingClient.Builder builder = BillingClient.newBuilder(context);
- if (enablePendingPurchases) {
- builder.enablePendingPurchases();
- }
+ public BillingClient createBillingClient(Context context, MethodChannel channel) {
+ BillingClient.Builder builder = BillingClient.newBuilder(context).enablePendingPurchases();
+
return builder.setListener(new PluginPurchaseListener(channel)).build();
}
}
diff --git a/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/MethodCallHandlerImpl.java b/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/MethodCallHandlerImpl.java
index 5b58808..23b9cb6 100644
--- a/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/MethodCallHandlerImpl.java
+++ b/packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/MethodCallHandlerImpl.java
@@ -110,10 +110,7 @@
isReady(result);
break;
case InAppPurchasePlugin.MethodNames.START_CONNECTION:
- startConnection(
- (int) call.argument("handle"),
- (boolean) call.argument("enablePendingPurchases"),
- result);
+ startConnection((int) call.argument("handle"), result);
break;
case InAppPurchasePlugin.MethodNames.END_CONNECTION:
endConnection(result);
@@ -319,12 +316,9 @@
});
}
- private void startConnection(
- final int handle, final boolean enablePendingPurchases, final MethodChannel.Result result) {
+ private void startConnection(final int handle, final MethodChannel.Result result) {
if (billingClient == null) {
- billingClient =
- billingClientFactory.createBillingClient(
- applicationContext, methodChannel, enablePendingPurchases);
+ billingClient = billingClientFactory.createBillingClient(applicationContext, methodChannel);
}
billingClient.startConnection(
diff --git a/packages/in_app_purchase/in_app_purchase_android/android/src/test/java/io/flutter/plugins/inapppurchase/MethodCallHandlerTest.java b/packages/in_app_purchase/in_app_purchase_android/android/src/test/java/io/flutter/plugins/inapppurchase/MethodCallHandlerTest.java
index 6f9256c..d676bf3 100644
--- a/packages/in_app_purchase/in_app_purchase_android/android/src/test/java/io/flutter/plugins/inapppurchase/MethodCallHandlerTest.java
+++ b/packages/in_app_purchase/in_app_purchase_android/android/src/test/java/io/flutter/plugins/inapppurchase/MethodCallHandlerTest.java
@@ -90,10 +90,7 @@
@Before
public void setUp() {
MockitoAnnotations.openMocks(this);
- factory =
- (@NonNull Context context,
- @NonNull MethodChannel channel,
- boolean enablePendingPurchases) -> mockBillingClient;
+ factory = (@NonNull Context context, @NonNull MethodChannel channel) -> mockBillingClient;
methodChannelHandler = new MethodCallHandlerImpl(activity, context, mockMethodChannel, factory);
when(mockActivityPluginBinding.getActivity()).thenReturn(activity);
}
@@ -153,7 +150,6 @@
public void startConnection_multipleCalls() {
Map<String, Object> arguments = new HashMap<>();
arguments.put("handle", 1);
- arguments.put("enablePendingPurchases", true);
MethodCall call = new MethodCall(START_CONNECTION, arguments);
ArgumentCaptor<BillingClientStateListener> captor =
ArgumentCaptor.forClass(BillingClientStateListener.class);
@@ -191,7 +187,6 @@
final int disconnectCallbackHandle = 22;
Map<String, Object> arguments = new HashMap<>();
arguments.put("handle", disconnectCallbackHandle);
- arguments.put("enablePendingPurchases", true);
MethodCall connectCall = new MethodCall(START_CONNECTION, arguments);
ArgumentCaptor<BillingClientStateListener> captor =
ArgumentCaptor.forClass(BillingClientStateListener.class);
@@ -865,7 +860,6 @@
private ArgumentCaptor<BillingClientStateListener> mockStartConnection() {
Map<String, Object> arguments = new HashMap<>();
arguments.put("handle", 1);
- arguments.put("enablePendingPurchases", true);
MethodCall call = new MethodCall(START_CONNECTION, arguments);
ArgumentCaptor<BillingClientStateListener> captor =
ArgumentCaptor.forClass(BillingClientStateListener.class);
@@ -880,7 +874,6 @@
if (arguments == null) {
arguments = new HashMap<>();
arguments.put("handle", 1);
- arguments.put("enablePendingPurchases", true);
}
if (result == null) {
result = mock(Result.class);
diff --git a/packages/in_app_purchase/in_app_purchase_android/example/integration_test/in_app_purchase_test.dart b/packages/in_app_purchase/in_app_purchase_android/example/integration_test/in_app_purchase_test.dart
index 8b65530..bb0e167 100644
--- a/packages/in_app_purchase/in_app_purchase_android/example/integration_test/in_app_purchase_test.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/example/integration_test/in_app_purchase_test.dart
@@ -12,7 +12,6 @@
testWidgets('Can create InAppPurchaseAndroid instance',
(WidgetTester tester) async {
- InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();
InAppPurchaseAndroidPlatform.registerPlatform();
final InAppPurchasePlatform androidPlatform =
InAppPurchasePlatform.instance;
diff --git a/packages/in_app_purchase/in_app_purchase_android/example/lib/main.dart b/packages/in_app_purchase/in_app_purchase_android/example/lib/main.dart
index 1267341..a53e9b3 100644
--- a/packages/in_app_purchase/in_app_purchase_android/example/lib/main.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/example/lib/main.dart
@@ -15,11 +15,6 @@
void main() {
WidgetsFlutterBinding.ensureInitialized();
- // For play billing library 2.0 on Android, it is mandatory to call
- // [enablePendingPurchases](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder.html#enablependingpurchases)
- // as part of initializing the app.
- InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();
-
// When using the Android plugin directly it is mandatory to register
// the plugin as default instance as part of initializing the app.
InAppPurchaseAndroidPlatform.registerPlatform();
diff --git a/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.dart b/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.dart
index 0e7024a..29441fb 100644
--- a/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.dart
@@ -53,8 +53,6 @@
/// some minor changes to account for language differences. Callbacks have been
/// converted to futures where appropriate.
class BillingClient {
- bool _enablePendingPurchases = false;
-
/// Creates a billing client.
BillingClient(PurchasesUpdatedListener onPurchasesUpdated) {
channel.setMethodCallHandler(callHandler);
@@ -82,14 +80,12 @@
/// Enable the [BillingClientWrapper] to handle pending purchases.
///
- /// Play requires that you call this method when initializing your application.
- /// It is to acknowledge your application has been updated to support pending purchases.
- /// See [Support pending transactions](https://developer.android.com/google/play/billing/billing_library_overview#pending)
- /// for more details.
- ///
- /// Failure to call this method before any other method in the [startConnection] will throw an exception.
+ /// **Deprecation warning:** it is no longer required to call
+ /// [enablePendingPurchases] when initializing your application.
+ @Deprecated(
+ 'The requirement to call `enablePendingPurchases()` has become obsolete since Google Play no longer accepts app submissions that don\'t support pending purchases.')
void enablePendingPurchases() {
- _enablePendingPurchases = true;
+ // No-op, until it is time to completely remove this method from the API.
}
/// Calls
@@ -105,8 +101,6 @@
Future<BillingResultWrapper> startConnection(
{required OnBillingServiceDisconnected
onBillingServiceDisconnected}) async {
- assert(_enablePendingPurchases,
- 'enablePendingPurchases() must be called before calling startConnection');
List<Function> disconnectCallbacks =
_callbacks[_kOnBillingServiceDisconnected] ??= [];
disconnectCallbacks.add(onBillingServiceDisconnected);
@@ -115,7 +109,6 @@
"BillingClient#startConnection(BillingClientStateListener)",
<String, dynamic>{
'handle': disconnectCallbacks.length - 1,
- 'enablePendingPurchases': _enablePendingPurchases
})) ??
<String, dynamic>{});
}
diff --git a/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform_addition.dart b/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform_addition.dart
index 11b105a..dd6fe37 100644
--- a/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform_addition.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform_addition.dart
@@ -14,30 +14,29 @@
extends InAppPurchasePlatformAddition {
/// Creates a [InAppPurchaseAndroidPlatformAddition] which uses the supplied
/// `BillingClient` to provide Android specific features.
- InAppPurchaseAndroidPlatformAddition(this._billingClient) {
- assert(
- _enablePendingPurchase,
- 'enablePendingPurchases() must be called when initializing the application and before you access the [InAppPurchase.instance].',
- );
-
- _billingClient.enablePendingPurchases();
- }
+ InAppPurchaseAndroidPlatformAddition(this._billingClient);
/// Whether pending purchase is enabled.
///
+ /// **Deprecation warning:** it is no longer required to call
+ /// [enablePendingPurchases] when initializing your application. From now on
+ /// this is handled internally and the [enablePendingPurchase] property will
+ /// always return `true`.
+ ///
+ // ignore: deprecated_member_use_from_same_package
/// See also [enablePendingPurchases] for more on pending purchases.
- static bool get enablePendingPurchase => _enablePendingPurchase;
- static bool _enablePendingPurchase = false;
+ @Deprecated(
+ 'The requirement to call `enablePendingPurchases()` has become obsolete since Google Play no longer accepts app submissions that don\'t support pending purchases.')
+ static bool get enablePendingPurchase => true;
/// Enable the [InAppPurchaseConnection] to handle pending purchases.
///
- /// This method is required to be called when initialize the application.
- /// It is to acknowledge your application has been updated to support pending purchases.
- /// See [Support pending transactions](https://developer.android.com/google/play/billing/billing_library_overview#pending)
- /// for more details.
- /// Failure to call this method before access [instance] will throw an exception.
+ /// **Deprecation warning:** it is no longer required to call
+ /// [enablePendingPurchases] when initializing your application.
+ @Deprecated(
+ 'The requirement to call `enablePendingPurchases()` has become obsolete since Google Play no longer accepts app submissions that don\'t support pending purchases.')
static void enablePendingPurchases() {
- _enablePendingPurchase = true;
+ // No-op, until it is time to completely remove this method from the API.
}
final BillingClient _billingClient;
diff --git a/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml b/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml
index 7d5c610..63bfa13 100644
--- a/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml
+++ b/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml
@@ -2,7 +2,7 @@
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/plugins/tree/master/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.2.0
+version: 0.2.1
environment:
sdk: ">=2.14.0 <3.0.0"
diff --git a/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/billing_client_wrapper_test.dart b/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/billing_client_wrapper_test.dart
index 1a2a0e4..ba6e755 100644
--- a/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/billing_client_wrapper_test.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/billing_client_wrapper_test.dart
@@ -22,7 +22,6 @@
setUp(() {
billingClient = BillingClient((PurchasesResultWrapper _) {});
- billingClient.enablePendingPurchases();
stubPlatform.reset();
});
@@ -90,10 +89,7 @@
);
await billingClient.startConnection(onBillingServiceDisconnected: () {});
final MethodCall call = stubPlatform.previousCallMatching(methodName);
- expect(
- call.arguments,
- equals(
- <dynamic, dynamic>{'handle': 0, 'enablePendingPurchases': true}));
+ expect(call.arguments, equals(<dynamic, dynamic>{'handle': 0}));
});
test('handles method channel returning null', () async {
diff --git a/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_addition_test.dart b/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_addition_test.dart
index ecefc4d..112300d 100644
--- a/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_addition_test.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_addition_test.dart
@@ -29,8 +29,6 @@
setUp(() {
widgets.WidgetsFlutterBinding.ensureInitialized();
- InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();
-
const String debugMessage = 'dummy message';
final BillingResponse responseCode = BillingResponse.ok;
final BillingResultWrapper expectedBillingResult = BillingResultWrapper(
diff --git a/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart b/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart
index 12cca69..9f00bc7 100644
--- a/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart
+++ b/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart
@@ -10,7 +10,6 @@
import 'package:in_app_purchase_android/billing_client_wrappers.dart';
import 'package:in_app_purchase_android/in_app_purchase_android.dart';
import 'package:in_app_purchase_android/src/channel.dart';
-import 'package:in_app_purchase_android/src/in_app_purchase_android_platform_addition.dart';
import 'package:in_app_purchase_platform_interface/in_app_purchase_platform_interface.dart';
import 'billing_client_wrappers/purchase_wrapper_test.dart';
@@ -42,7 +41,6 @@
value: buildBillingResultMap(expectedBillingResult));
stubPlatform.addResponse(name: endConnectionCall, value: null);
- InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();
InAppPurchaseAndroidPlatform.registerPlatform();
iapAndroidPlatform =
InAppPurchasePlatform.instance as InAppPurchaseAndroidPlatform;