payApi method
dynamic
payApi({
- required BuildContext context,
- required String api,
- required String publishKey,
- required String clintID,
- required String customerID,
- required List<
Product> products, - String? successUrl,
- String? cancelUrl,
- required Map<
String, dynamic> metadata, - required bool testMode,
- required void onCreate(
- Create create
- required void onCancelled(),
- required void onPaid(),
- required dynamic onError(
- Map error
Implementation
payApi({
required BuildContext context,
required String api,
required String publishKey,
required String clintID,
required String customerID,
required List<Product> products,
String? successUrl,
String? cancelUrl,
required Map<String, dynamic> metadata,
required bool testMode,
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 Function(Map error)? onError,
}) async {
late Map<String, dynamic> dataBack;
Future<Create> createS() async {
return Create.fromJson(dataBack);
}
// Future<StatusClass> payStatus(dataStatute) async {
// return StatusClass.fromJson(dataStatute);
// }
dataBack = await RequestHelper.postRequest(
api,
{
if (userSaveCard) "customer_id": customerID,
"save_card_on_success": saveCard,
if (expiredInMinuets !=null) "expired_in_minutes": expiredInMinuets,
"client_reference_id": clintID,
"mode": "payment",
"products": products.map((e) => e.toJson()).toList(),
"success_url":
successUrl ?? 'https://abom.me/package/thawani/suc.php',
"cancel_url": cancelUrl ?? "https://abom.me/package/thawani/can.php",
"metadata": metadata,
},
testMode);
if (dataBack['code'] == 2004) {
createS().then((value) => {onCreate(value)});
if (context.mounted) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PayWidget(
api: api,
uri: dataBack['data']['session_id'],
url: testMode == true
? 'https://uatcheckout.thawani.om/pay/${dataBack['data']['session_id']}?key=$publishKey'
: 'https://checkout.thawani.om/pay/${dataBack['data']['session_id']}?key=$publishKey',
paid: (statusClass) {
onPaid(statusClass);
},
unpaid: (statusClass) {
onCancelled(statusClass);
},
testMode: testMode,
)));
}
if (context.mounted) return;
} else if (dataBack['code'] != 2004) {
return onError!(dataBack);
} else if (dataBack['code'] == null) {
return onError!(dataBack);
}
}