Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement registerPlatform method
  • Loading branch information
mvanbeusekom committed May 11, 2021
commit 68dac7f0aba2ae84f679cf4ad85048eeda9a6b89
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform {
.add(await _getPurchaseDetailsFromResult(resultWrapper));
});

androidPlatformAddition = InAppPurchaseAndroidPlatformAddition(
billingClient,
);
InAppPurchasePlatformAddition.instance = androidPlatformAddition;
// Register [InAppPurchaseAndroidPlatformAddition].
InAppPurchasePlatformAddition.instance =
InAppPurchaseAndroidPlatformAddition(billingClient);

_readyFuture = _connect();
_purchaseUpdatedController = StreamController.broadcast();
}

/// Returns the singleton instance of the [InAppPurchaseAndroidPlatform].
static InAppPurchaseAndroidPlatform get instance => _getOrCreateInstance();
static InAppPurchaseAndroidPlatform? _instance;
/// Registers this class as the default instance of [InAppPurchasePlatform].
static void registerPlatform() {
// Register the platform instance with the plugin platform
// interface.
InAppPurchasePlatform.setInstance(InAppPurchaseAndroidPlatform._());
}

static late StreamController<List<PurchaseDetails>>
_purchaseUpdatedController;
Expand All @@ -62,13 +64,6 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform {
@visibleForTesting
late final BillingClient billingClient;

/// The [InAppPurchaseAndroidPlatformAddition] containing Android specific
/// features which don't fit in the platform agnostic interface.
///
/// This field should not be used out of test code.
@visibleForTesting
late final InAppPurchaseAndroidPlatformAddition androidPlatformAddition;

late Future<void> _readyFuture;
static Set<String> _productIdsToConsume = Set<String>();

Expand Down Expand Up @@ -224,22 +219,6 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform {
_purchaseUpdatedController.add(pastPurchases);
}

/// Resets the connection instance.
///
/// The next call to [instance] will create a new instance. Should only be
/// used in tests.
@visibleForTesting
static void reset() => _instance = null;

static InAppPurchaseAndroidPlatform _getOrCreateInstance() {
if (_instance != null) {
return _instance!;
}

_instance = InAppPurchaseAndroidPlatform._();
return _instance!;
}

Future<void> _connect() =>
billingClient.startConnection(onBillingServiceDisconnected: () {});

Expand All @@ -251,7 +230,9 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform {
}

final BillingResultWrapper billingResult =
await androidPlatformAddition.consumePurchase(purchaseDetails);
await (InAppPurchasePlatformAddition.instance
as InAppPurchaseAndroidPlatformAddition)
.consumePurchase(purchaseDetails);
final BillingResponse consumedResponse = billingResult.responseCode;
if (consumedResponse != BillingResponse.ok) {
purchaseDetails.status = PurchaseStatus.error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ void main() {
setUp(() {
widgets.WidgetsFlutterBinding.ensureInitialized();

InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();

const String debugMessage = 'dummy message';
final BillingResponse responseCode = BillingResponse.ok;
final BillingResultWrapper expectedBillingResult = BillingResultWrapper(
Expand All @@ -45,16 +43,20 @@ void main() {
name: startConnectionCall,
value: buildBillingResultMap(expectedBillingResult));
stubPlatform.addResponse(name: endConnectionCall, value: null);
iapAndroidPlatform = InAppPurchaseAndroidPlatform.instance;

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

tearDown(() {
stubPlatform.reset();
InAppPurchaseAndroidPlatform.reset();
});

group('connection management', () {
test('connects on initialization', () {
//await iapAndroidPlatform.isAvailable();
expect(stubPlatform.countPreviousCalls(startConnectionCall), equals(1));
});
});
Expand Down