Skip to content

Commit

Permalink
[in_app_purchase] Deprecated the `InAppPurchaseAndroidPlatformAdditio…
Browse files Browse the repository at this point in the history
…n.enablePendingPurchases` method. (flutter#4527)
  • Loading branch information
mvanbeusekom authored Nov 29, 2021
1 parent 6bc9a2b commit 3990aaf
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 73 deletions.
5 changes: 3 additions & 2 deletions packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ interface BillingClientFactory {
*
* @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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
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);
Expand Down Expand Up @@ -319,12 +316,9 @@ public void onPurchaseHistoryResponse(
});
}

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ public class MethodCallHandlerTest {
@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);
}
Expand Down Expand Up @@ -153,7 +150,6 @@ public void startConnection() {
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);
Expand Down Expand Up @@ -191,7 +187,6 @@ public void endConnection() {
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);
Expand Down Expand Up @@ -865,7 +860,6 @@ public void launchPriceChangeConfirmationFlow_withoutBillingClient_returnsUnavai
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);
Expand All @@ -880,7 +874,6 @@ private void establishConnectedBillingClient(
if (arguments == null) {
arguments = new HashMap<>();
arguments.put("handle", 1);
arguments.put("enablePendingPurchases", true);
}
if (result == null) {
result = mock(Result.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ void main() {

testWidgets('Can create InAppPurchaseAndroid instance',
(WidgetTester tester) async {
InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();
InAppPurchaseAndroidPlatform.registerPlatform();
final InAppPurchasePlatform androidPlatform =
InAppPurchasePlatform.instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ import 'consumable_store.dart';
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ typedef void PurchasesUpdatedListener(PurchasesResultWrapper purchasesResult);
/// 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);
Expand Down Expand Up @@ -82,14 +80,12 @@ class BillingClient {

/// 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
Expand All @@ -105,8 +101,6 @@ class BillingClient {
Future<BillingResultWrapper> startConnection(
{required OnBillingServiceDisconnected
onBillingServiceDisconnected}) async {
assert(_enablePendingPurchases,
'enablePendingPurchases() must be called before calling startConnection');
List<Function> disconnectCallbacks =
_callbacks[_kOnBillingServiceDisconnected] ??= [];
disconnectCallbacks.add(onBillingServiceDisconnected);
Expand All @@ -115,7 +109,6 @@ class BillingClient {
"BillingClient#startConnection(BillingClientStateListener)",
<String, dynamic>{
'handle': disconnectCallbacks.length - 1,
'enablePendingPurchases': _enablePendingPurchases
})) ??
<String, dynamic>{});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,29 @@ class InAppPurchaseAndroidPlatformAddition
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;
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/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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ void main() {

setUp(() {
billingClient = BillingClient((PurchasesResultWrapper _) {});
billingClient.enablePendingPurchases();
stubPlatform.reset();
});

Expand Down Expand Up @@ -90,10 +89,7 @@ void main() {
);
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ void main() {
setUp(() {
widgets.WidgetsFlutterBinding.ensureInitialized();

InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();

const String debugMessage = 'dummy message';
final BillingResponse responseCode = BillingResponse.ok;
final BillingResultWrapper expectedBillingResult = BillingResultWrapper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:flutter_test/flutter_test.dart';
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';
Expand Down Expand Up @@ -42,7 +41,6 @@ void main() {
value: buildBillingResultMap(expectedBillingResult));
stubPlatform.addResponse(name: endConnectionCall, value: null);

InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();
InAppPurchaseAndroidPlatform.registerPlatform();
iapAndroidPlatform =
InAppPurchasePlatform.instance as InAppPurchaseAndroidPlatform;
Expand Down

0 comments on commit 3990aaf

Please sign in to comment.