add method
dynamic
add(})
Implementation
add(
BuildContext context, {
required void Function(Create create) onCreate,
///The Function And The Result Of Data If The User Cancelled The Payment.
required void Function(Map<String, dynamic> payStatus) onCancelled,
///The Function And The Result Of Data If The User Cancelled The Payment.
required void Function(Map<String, dynamic> payStatus) onPaid,
///The Function And The Reason Of The Error, If Any Error Happen.
required void Function(Map error)? onError,
}) {
String url = isTestMode
? "https://uatcheckout.thawani.om/api/v1/checkout/session"
: "https://checkout.thawani.om/api/v1/checkout/session";
Request.post(url: url, data: {
"customer_id": userCustomerID,
"save_card_on_success": true,
"client_reference_id": userClintID,
"mode": "payment",
"products": userProducts.map((e) => e.toJson()).toList(),
"success_url":
userSuccessUrl ?? 'https://abom.me/package/thawani/suc.php',
"cancel_url": userCancelUrl ?? "https://abom.me/package/thawani/can.php",
"metadata": userMetadata,
}, headers: {
'Content-Type': "application/json",
'thawani-api-key': userApiKey
}).then((value) => {
if (value['data']['code'] == 2004)
{
onCreate(Create.fromJson(value['data'])),
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PayWidget(
api: userApiKey,
uri: value['data']['data']['session_id'],
url: isTestMode == true
? 'https://uatcheckout.thawani.om/pay/${value['data']['data']['session_id']}?key=$userPKey'
: 'https://checkout.thawani.om/pay/${value['data']['data']['session_id']}?key=$userPKey',
paid: (statusClass) {
onPaid(statusClass);
},
unpaid: (statusClass) {
onCancelled(statusClass);
},
testMode: isTestMode,
))),
}
else if (value['data']['code'] != 2004)
{onError!(value)}
else if (value['data']['code'] == null)
{onError!(value['data'])}
});
}