setCheckoutCallback method
void
setCheckoutCallback({
- required PPApprovalCallback onApprove,
- required PPShippingChangeCallback onShippingChange,
- required PPErrorCallback onError,
- required dynamic onCancel(),
override
Implementation
@override
void setCheckoutCallback({
required PPApprovalCallback onApprove,
required PPShippingChangeCallback onShippingChange,
required PPErrorCallback onError,
required Function() onCancel,
}) {
methodChannel.setMethodCallHandler((call) async {
try {
final data = call.arguments as Map?;
if (data == null) {
return onCancel();
}
switch (MethodNativeInvoke.from(call.method.camelCase)) {
case MethodNativeInvoke.onApprove:
final approvalDataJson = data['approvalData'];
final approvalData = jsonDecode(approvalDataJson);
final approval = PPApprovalData.fromJson(approvalData);
return onApprove(approval);
case MethodNativeInvoke.onShippingChange:
final shippingChangeDataJson = data['shippingChangeData'];
final shippingChangeData = jsonDecode(shippingChangeDataJson);
final shippingChange =
PPShippingChangeData.fromJson(shippingChangeData);
return onShippingChange(shippingChange);
case MethodNativeInvoke.onError:
final errorDataJson = data['errorInfo'];
final errorData = jsonDecode(errorDataJson);
final error = PPErrorInfo.fromJson(errorData);
return onError(error);
case MethodNativeInvoke.onCancel:
return onCancel();
}
} catch (e) {
debugPrint(':::: ERROR setCheckoutCallback: $e');
}
});
}