openPayerMax static method

Future<void> openPayerMax({
  1. required num amount,
  2. num? coins,
  3. String? coinPlanId,
  4. String? orderId,
  5. String? subject,
  6. String? appId,
  7. String? merchantNo,
  8. String? apiUrl,
  9. String? privateKeyBase64,
  10. String? frontCallbackUrl,
  11. String? notifyUrl,
  12. String? upiId,
  13. String currency = "USD",
  14. String country = "US",
  15. String userId = "USER_01",
  16. String paymentGatewayName = "PayerMax",
  17. bool testMode = false,
  18. bool openHostedCashierDirectly = true,
  19. dynamic onPaymentSuccess()?,
  20. dynamic onPaymentFailure()?,
  21. dynamic onShowToast()?,
})

Opens the PayerMax checkout (WebView or UPI bottom sheet) using GetX

Implementation

static Future<void> openPayerMax({
  required num amount,
  num? coins,
  String? coinPlanId,
  String? orderId,
  String? subject,
  String? appId,
  String? merchantNo,
  String? apiUrl,
  String? privateKeyBase64,
  String? frontCallbackUrl,
  String? notifyUrl,
  String? upiId,
  String currency = "USD",
  String country = "US",
  String userId = "USER_01",
  String paymentGatewayName = "PayerMax",
  bool testMode = false,
  bool openHostedCashierDirectly = true,
  Function()? onPaymentSuccess,
  Function()? onPaymentFailure,
  Function()? onShowToast,
}) async {
  final controller = Get.isRegistered<PayerMaxController>()
      ? Get.find<PayerMaxController>()
      : Get.put(PayerMaxController());

  // 1. Show Loading dialog
  Get.dialog(
    Center(
      child: Container(
        padding: const EdgeInsets.all(24),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(20),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            const CircularProgressIndicator(color: Colors.deepPurple),
            const SizedBox(height: 16),
            const Text(
              "Creating PayerMax Order...",
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
            ),
            const SizedBox(height: 4),
            Text(
              testMode
                  ? "Connecting to Sandbox Gateway"
                  : "Connecting to Gateway",
              style: const TextStyle(color: Colors.grey, fontSize: 12),
            ),
          ],
        ),
      ),
    ),
    barrierDismissible: false,
  );

  final success = await controller.createOrder(
    amountVal: amount,
    coinsVal: coins,
    coinPlanId: coinPlanId,
    orderId: orderId,
    subject: subject,
    appId: appId,
    merchantNo: merchantNo,
    apiUrl: apiUrl,
    privateKeyBase64: privateKeyBase64,
    frontCallbackUrl: frontCallbackUrl,
    notifyUrl: notifyUrl,
    upiId: upiId,
    currencyCode: currency,
    countryCode: country,
    userId: userId,
    paymentGatewayName: paymentGatewayName,
    testMode: testMode,
    openHostedCashierDirectly: openHostedCashierDirectly,
    onSuccess: onPaymentSuccess,
    onFailure: onPaymentFailure,
    onToast: onShowToast,
  );

  if (Get.isDialogOpen == true) {
    Get.back();
  }

  if (!success) {
    return;
  }

  // 2. Open Hosted Cashier WebView OR UPI BottomSheet
  final shouldOpenWebView =
      openHostedCashierDirectly || currency.toUpperCase() != "INR";
  if (shouldOpenWebView) {
    await Get.to(() => PayerMaxWebViewPage(controller: controller));
  } else {
    await Get.bottomSheet(
      PayerMaxBottomSheet(controller: controller),
      isScrollControlled: true,
    );
  }
}