payWithWallet method

Future<EasyPaymobResponse?> payWithWallet({
  1. required BuildContext context,
  2. required String amountInCents,
  3. required String phoneNumber,
  4. void onPayment(
    1. EasyPaymobResponse response
    )?,
  5. List? items,
  6. EasyPaymobBillingModel? billingData,
})

Proceed to pay with only calling this function. Opens a WebView at Paymob redirectedURL to accept user payment info.

Implementation

Future<EasyPaymobResponse?> payWithWallet({
  /// BuildContext for navigation to WebView
  required BuildContext context,

  /// Payment amount in cents EX: 20000 is an 200 EGP
  required String amountInCents,

  /// Payment Number Cash EX:01273308123
  required String phoneNumber,

  /// 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 (_integrationCashID == null) {
    throw Exception('PaymobPayment is not initialized integrationCashID');
  }

  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: _integrationCashID!,
    billingData: billingData ?? EasyPaymobBillingModel(),
  );

  final response = await _dio.post(
    'acceptance/payments/pay',
    data: {
      "source": {
        "identifier": phoneNumber,
        "subtype": "WALLET",
      },
      "payment_token": purchaseToken,
    },
  );
  final message = response.data['message'];
  if (message != null) {
    throw Exception(message);
  }
  String redirectUrl = response.data["redirect_url"].toString();

  if (context.mounted) {
    final response = await EasyPaymobIFrameWebView.show(
      context: context,
      redirectURL: redirectUrl,
      onPayment: onPayment,
    );
    return response;
  }
  return null;
}