Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Prev Previous commit
Next Next commit
formatting
  • Loading branch information
Chris Yang committed Dec 7, 2019
commit 61c5771f68d41625d7d4fda7d892dab9bf35e763
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ 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.
* @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, boolean enablePendingPurchases);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
final class BillingClientFactoryImpl implements BillingClientFactory {

@Override
public BillingClient createBillingClient(Context context, MethodChannel channel, boolean enablePendingPurchases) {
public BillingClient createBillingClient(
Context context, MethodChannel channel, boolean enablePendingPurchases) {
BillingClient.Builder builder = BillingClient.newBuilder(context);
if (enablePendingPurchases) {
builder.enablePendingPurchases();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ 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"),
(boolean) call.argument("enablePendingPurchases"),
result);
break;
case InAppPurchasePlugin.MethodNames.END_CONNECTION:
endConnection(result);
Expand Down Expand Up @@ -236,9 +239,12 @@ public void onPurchaseHistoryResponse(
});
}

private void startConnection(final int handle, final boolean enablePendingPurchases, final MethodChannel.Result result) {
private void startConnection(
final int handle, final boolean enablePendingPurchases, final MethodChannel.Result result) {
if (billingClient == null) {
billingClient = billingClientFactory.createBillingClient(applicationContext, methodChannel, enablePendingPurchases);
billingClient =
billingClientFactory.createBillingClient(
applicationContext, methodChannel, enablePendingPurchases);
}

billingClient.startConnection(
Expand Down
1 change: 1 addition & 0 deletions packages/in_app_purchase/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:in_app_purchase/in_app_purchase.dart';
import 'consumable_store.dart';

void main() {
InAppPurchaseConnection.enablePendingPurchases();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Comment here explaining what this is and linking to the Play documentation would be useful.

runApp(MyApp());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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;

BillingClient(PurchasesUpdatedListener onPurchasesUpdated) {
Expand Down Expand Up @@ -98,15 +97,18 @@ class BillingClient {
Future<BillingResultWrapper> startConnection(
{@required
OnBillingServiceDisconnected onBillingServiceDisconnected}) async {
assert(_enablePendingPurchases, 'enablePendingPurchases() must be called before calling startConnection');
assert(_enablePendingPurchases,
'enablePendingPurchases() must be called before calling startConnection');
List<Function> disconnectCallbacks =
_callbacks[_kOnBillingServiceDisconnected] ??= [];
disconnectCallbacks.add(onBillingServiceDisconnected);
return BillingResultWrapper.fromJson(await channel
.invokeMapMethod<String, dynamic>(
"BillingClient#startConnection(BillingClientStateListener)",
<String, dynamic>{'handle': disconnectCallbacks.length - 1,
'enablePendingPurchases': _enablePendingPurchases}));
<String, dynamic>{
'handle': disconnectCallbacks.length - 1,
'enablePendingPurchases': _enablePendingPurchases
}));
}

/// Calls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ abstract class InAppPurchaseConnection {
/// Failure to call this method before access [instance] will throw an exception.
///
/// It is an no-op on iOS.
static void enablePendingPurchases(){_enablePendingPurchase = true;}
static void enablePendingPurchases() {
_enablePendingPurchase = true;
}

/// Query product details for the given set of IDs.
///
Expand Down