initializePayment method

Future<PaymentInitializationResult> initializePayment({
  1. required String currency,
  2. required String amountInCents,
  3. List? items,
})

Proceed to pay with only calling this function. Opens a WebView at Paymob redirectedURL to accept user payment info. First step: Get authToken and orderId

Implementation

// ... (existing code)

/// First step: Get authToken and orderId
Future<PaymentInitializationResult> initializePayment({
  required String currency,
  required String amountInCents,
  List? items,
}) async {
  if (!_isInitialized) {
    throw Exception('PaymobPayment is not initialized. Call:`PaymobPayment.instance.initialize`');
  }

  final authToken = await _getAuthToken();
  final orderID = await _addOrder(
    authToken: authToken,
    currency: currency,
    amount: amountInCents,
    items: items ?? [],
  );

  return PaymentInitializationResult(authToken, orderID);
}