request static method
Future<void>
request(
- BuildContext context,
- Payload payload, {
- User? user,
- List<
Item> ? items, - Extra? extra,
- StringCallback? onDone,
- StringCallback? onReady,
- StringCallback? onCancel,
- StringCallback? onError,
Implementation
static Future<void> request(BuildContext context, Payload payload,
{User? user,
List<Item>? items,
Extra? extra,
StringCallback? onDone,
StringCallback? onReady,
StringCallback? onCancel,
StringCallback? onError}) async {
payload.applicationId = Platform.isIOS
? payload.iosApplicationId
: payload.androidApplicationId;
if (user == null) user = User();
if (items == null) items = [];
if (extra == null) extra = Extra();
Map<String, dynamic> params = {
"payload": payload.toJson(),
"params": payload.params ?? {},
"user": user.toJson(),
"items": items.map((v) => v.toJson()).toList(),
"extra": extra.toJson()
};
try {
Map<dynamic, dynamic> result = await _channel.invokeMethod(
"bootpayRequest",
params,
);
// Map<dynamic, dynamic> result = await (_channel.invokeMethod(
// "bootpayRequest",
// params,
// ) as FutureOr<Map<dynamic, dynamic>>);
// print("--- result");
// print(result);
String? method = result["method"];
if (method == null) method = result["action"];
String? message = result["message"];
if (message == null) message = result["msg"];
//confirm 생략
if (method == 'onDone' || method == 'BootpayDone') {
if (onDone != null) onDone(message);
} else if (method == 'onReady' || method == 'BootpayReady') {
if (onReady != null) onReady(message);
} else if (method == 'onCancel' || method == 'BootpayCancel') {
if (onCancel != null) onCancel(message);
} else if (method == 'onError' || method == 'BootpayError') {
if (onError != null) onError(message);
} else if (result['receipt_id'] != null && result['receipt_id'].isNotEmpty) {
// if (onDone != null) onDone(jsonEncode(result));
if (onDone != null) onDone(message);
} else if (method == 'onConfirm' || method == 'BootpayConfirm') {
if (onReady != null) onReady(message);
}
} on PlatformException catch (e) {
print("PlatformException occured!! code: ${e.code}, msg: ${e.message}");
}
}