payWithCard method
Future<EasyPaymobResponse?>
payWithCard({
- required BuildContext context,
- required String amountInCents,
- void onPayment(
- EasyPaymobResponse response
- List? items,
- EasyPaymobBillingModel? billingData,
Proceed to pay with only calling this function. Opens a WebView at Paymob redirectedURL to accept user payment info.
Implementation
Future<EasyPaymobResponse?> payWithCard(
{
/// BuildContext for navigation to WebView
required BuildContext context,
/// Payment amount in cents EX: 20000 is an 200 EGP
required String amountInCents,
/// Optional Callback if you can use return result of pay function or use this callback
void Function(EasyPaymobResponse response)? onPayment,
/// list of json objects contains the contents of the purchase.
List? items,
/// The billing data related to the customer related to this payment.
EasyPaymobBillingModel? billingData}) async {
if (!_isInitialized) {
throw Exception('PaymobPayment is not initialized call:`PaymobPayment.instance.initialize`');
}
if (_integrationCardID == null || _iFrameID == null) {
throw Exception('PaymobPayment is not initialized integrationCardID And iFrameID');
}
final authToken = await _getAuthToken();
final orderID = await _addOrder(
authToken: authToken,
currency: _currency,
amount: amountInCents,
items: items ?? [],
);
final purchaseToken = await _getPurchaseToken(
authToken: authToken,
currency: _currency,
orderID: orderID,
amount: amountInCents,
integrationId: _integrationCardID!,
billingData: billingData ?? EasyPaymobBillingModel(),
);
if (context.mounted) {
final response = await EasyPaymobIFrameWebView.show(
context: context,
redirectURL: _iFrameURL + purchaseToken,
onPayment: onPayment,
);
return response;
}
return null;
}