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
58 changes: 36 additions & 22 deletions lib/flutter_poolakey.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export 'sku_details.dart';
/// It only works in the Android platform (Because [Cafebazaar](https://cafebazaar.ir/?l=en) only supports Android)
/// It uses [Poolakey](https://github.com/cafebazaar/Poolakey) SDK under the hood.
class FlutterPoolakey {
static const MethodChannel _channel =
const MethodChannel('ir.cafebazaar.flutter_poolakey');
static const MethodChannel _channel = const MethodChannel(
'ir.cafebazaar.flutter_poolakey',
);

static Future<String> getVersion() async {
return await _channel.invokeMethod('version', {});
Expand All @@ -34,17 +35,23 @@ class FlutterPoolakey {
/// You should listen to [onDisconnected] callback and call [FlutterPoolakey.connect] to reconnect again.
///
/// This function may return an error, you should handle the error and check the stacktrace to resolve it.
static Future<void> connect(String? inAppBillingKey,
{VoidCallback? onSucceed,
VoidCallback? onFailed,
VoidCallback? onDisconnected}) async {
static Future<void> connect(
String? inAppBillingKey, {
VoidCallback? onSucceed,
VoidCallback? onFailed,
VoidCallback? onDisconnected,
}) async {
_registerConnectCallBack(onSucceed, onFailed, onDisconnected);
await _channel
.invokeMethod('connect', {'in_app_billing_key': inAppBillingKey});
await _channel.invokeMethod('connect', {
'in_app_billing_key': inAppBillingKey,
});
}

static void _registerConnectCallBack(VoidCallback? onConnectionSucceed,
VoidCallback? onConnectionFailed, VoidCallback? onDisconnected) {
static void _registerConnectCallBack(
VoidCallback? onConnectionSucceed,
VoidCallback? onConnectionFailed,
VoidCallback? onDisconnected,
) {
if (onConnectionSucceed == null &&
onConnectionFailed == null &&
onDisconnected == null) {
Expand Down Expand Up @@ -92,7 +99,7 @@ class FlutterPoolakey {
final map = await _channel.invokeMethod('purchase', {
'product_id': productId,
'payload': payload,
'dynamicPriceToken': dynamicPriceToken
'dynamicPriceToken': dynamicPriceToken,
});
return PurchaseInfo.fromMap(map);
}
Expand All @@ -117,7 +124,7 @@ class FlutterPoolakey {
final map = await _channel.invokeMethod('subscribe', {
'product_id': productId,
'payload': payload,
'dynamicPriceToken': dynamicPriceToken
'dynamicPriceToken': dynamicPriceToken,
});
return PurchaseInfo.fromMap(map);
}
Expand All @@ -135,8 +142,9 @@ class FlutterPoolakey {
///
/// It returns true if the process is successful
static Future<bool> consume(String purchaseToken) async {
return await _channel
.invokeMethod('consume', {'purchase_token': purchaseToken});
return await _channel.invokeMethod('consume', {
'purchase_token': purchaseToken,
});
}

/// Returns all purchases list
Expand Down Expand Up @@ -176,8 +184,9 @@ class FlutterPoolakey {
///
/// Retrieves list of [PurchaseInfo] which contains all subscribed products in user's inventory.
static Future<List<PurchaseInfo>> getAllSubscribedProducts() async {
final List list =
await _channel.invokeMethod("get_all_subscribed_products");
final List list = await _channel.invokeMethod(
"get_all_subscribed_products",
);
return list.map((map) => PurchaseInfo.fromMap(map)).toList();
}

Expand All @@ -204,9 +213,11 @@ class FlutterPoolakey {
/// You can use this function to get detail of inApp product sku's,
/// [skuIds] Contain all sku id's that you want to get info about it.
static Future<List<SkuDetails>> getInAppSkuDetails(
List<String> skuIds) async {
final List list = await _channel
.invokeMethod("get_in_app_sku_details", {'sku_ids': skuIds});
List<String> skuIds,
) async {
final List list = await _channel.invokeMethod("get_in_app_sku_details", {
'sku_ids': skuIds,
});
return list.map((map) => SkuDetails.fromMap(map)).toList();
}

Expand All @@ -215,9 +226,12 @@ class FlutterPoolakey {
/// You can use this function to get detail of subscription product sku's,
/// [skuIds] Contain all sku id's that you want to get info about it.
static Future<List<SkuDetails>> getSubscriptionSkuDetails(
List<String> skuIds) async {
final List list = await _channel
.invokeMethod("get_subscription_sku_details", {'sku_ids': skuIds});
List<String> skuIds,
) async {
final List list = await _channel.invokeMethod(
"get_subscription_sku_details",
{'sku_ids': skuIds},
);
return list.map((map) => SkuDetails.fromMap(map)).toList();
}
}
Expand Down
22 changes: 12 additions & 10 deletions lib/purchase_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ class PurchaseInfo {
final String dataSignature;

PurchaseInfo(
this.orderId,
this.purchaseToken,
this.payload,
this.packageName,
this.purchaseState,
this.purchaseTime,
this.productId,
this.originalJson,
this.dataSignature);
this.orderId,
this.purchaseToken,
this.payload,
this.packageName,
this.purchaseState,
this.purchaseTime,
this.productId,
this.originalJson,
this.dataSignature,
);

factory PurchaseInfo.fromMap(Map<dynamic, dynamic> typeName) {
return PurchaseInfo(
Expand All @@ -35,7 +36,8 @@ class PurchaseInfo {
}

@override
String toString() => 'orderId: $orderId,'
String toString() =>
'orderId: $orderId,'
'\npurchaseToken: $purchaseToken,'
'\npayload: $payload,'
'\npackageName: $packageName,'
Expand Down
3 changes: 2 additions & 1 deletion lib/sku_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class SkuDetails {
}

@override
String toString() => 'sku: $sku,'
String toString() =>
'sku: $sku,'
'\ntype: $type,'
'\nprice: $price,'
'\ntitle: $title,'
Expand Down
7 changes: 4 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ version: 2.2.0-1.0.0-alpha01
homepage: https://github.com/cafebazaar/flutter_poolakey

environment:
sdk: '>=3.0.6 <4.0.0'
flutter: ">=3.3.0"
sdk: ^3.8.0
flutter: ">=1.17.0"

dependencies:
flutter:
sdk: flutter
plugin_platform_interface: ^2.0.2
plugin_platform_interface: ^2.1.8

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^5.0.0

flutter:
plugin:
Expand Down