Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion packages/in_app_purchase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.2.0

* Migrate from platform channels to Dart FFI using the pigeon C++ FFI generator (git ref 1e63f1b5).
* Apply clang-format-16 formatting.

## 0.1.9
Expand Down
2 changes: 1 addition & 1 deletion packages/in_app_purchase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This package is not an _endorsed_ implementation of `in_app_purchase`. Therefore
```yaml
dependencies:
in_app_purchase: ^3.3.0
in_app_purchase_tizen: ^0.1.9
in_app_purchase_tizen: ^0.2.0
```

Then you can import `in_app_purchase` and `in_app_purchase_tizen` in your Dart code:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter_test/flutter_test.dart';
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:in_app_purchase_tizen/in_app_purchase_tizen.dart';
import 'package:integration_test/integration_test.dart';

void main() {
Expand All @@ -13,4 +16,51 @@ void main() {
final InAppPurchase iapInstance = InAppPurchase.instance;
expect(iapInstance, isNotNull);
});

test('FFI host API smoke test', () async {
final InAppPurchase iap = InAppPurchase.instance;
final InAppPurchaseTizenPlatformAddition addition = iap
.getPlatformAddition<InAppPurchaseTizenPlatformAddition>();
addition.setRequestParameters(appId: 'test', pageSize: 15, pageNum: 1, securityKey: 'test');

Object? asyncError;
bool? available;
try {
available = await iap.isAvailable().timeout(const Duration(seconds: 15));
} catch (error) {
asyncError = error;
}
expect(
asyncError,
isNot(isA<TimeoutException>()),
reason: 'isAvailable() never completed: FFI reply never arrived',
);
final asyncErrorText = '$asyncError';
expect(asyncErrorText, isNot(contains('Failed to lookup symbol')));
expect(asyncErrorText, isNot(contains('has not been set up')));
expect(asyncErrorText, isNot(contains('BinaryMessenger is not supported')));
if (available == null && asyncError == null) {
fail('isAvailable() produced neither a value nor an error');
}

Object? queryError;
ProductDetailsResponse? response;
try {
response = await iap.queryProductDetails(<String>{}).timeout(const Duration(seconds: 30));
} catch (error) {
queryError = error;
}
expect(
queryError,
isNot(isA<TimeoutException>()),
reason: 'queryProductDetails() never completed: FFI reply never arrived',
);
final queryErrorText = '$queryError';
expect(queryErrorText, isNot(contains('Failed to lookup symbol')));
expect(queryErrorText, isNot(contains('has not been set up')));
expect(queryErrorText, isNot(contains('BinaryMessenger is not supported')));
if (response == null && queryError == null) {
fail('queryProductDetails() produced neither a value nor an error');
}
});
}
5 changes: 5 additions & 0 deletions packages/in_app_purchase/lib/src/billing_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class BillingManager {
/// Interface for calling host-side code.
final InAppPurchaseApi _hostApi;

/// Resets pending native replies left over from a previous Dart isolate.
void initialize() {
_hostApi.initialize();
}

/// get country code
Future<String> getCountryCode() async {
return _hostApi.getCountryCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class InAppPurchaseTizenPlatform extends InAppPurchasePlatform {
// Register the platform-specific implementation of the idiomatic
// InAppPurchase API.
InAppPurchasePlatform.instance = InAppPurchaseTizenPlatform();

if (RootIsolateToken.instance != null) {
billingManager.initialize();
}
}

static final StreamController<List<PurchaseDetails>> _purchaseUpdatedController =
Expand Down
Loading