openPayerMax static method

Future<void> openPayerMax({
  1. required num amount,
  2. num? coins,
  3. required String coinPlanId,
  4. String? appId,
  5. String? merchantNo,
  6. String? apiUrl,
  7. String? privateKeyBase64,
  8. String? upiId,
  9. String currency = "INR",
  10. String country = "IN",
  11. String userId = "USER_DEMO_01",
  12. String paymentGatewayName = "PayerMax",
  13. bool testMode = false,
  14. dynamic onPaymentSuccess()?,
  15. dynamic onPaymentFailure()?,
  16. dynamic onShowToast()?,
})

Opens the PayerMax checkout bottom sheet using GetX

Implementation

static Future<void> openPayerMax({
  required num amount,
  num? coins,
  required String coinPlanId,
  String? appId,
  String? merchantNo,
  String? apiUrl,
  String? privateKeyBase64,
  String? upiId,
  String currency = "INR",
  String country = "IN",
  String userId = "USER_DEMO_01",
  String paymentGatewayName = "PayerMax",
  bool testMode = false,
  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: const Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            CircularProgressIndicator(color: Colors.deepPurple),
            SizedBox(height: 16),
            Text(
              "Creating PayerMax Order...",
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
            ),
            SizedBox(height: 4),
            Text(
              "Connecting to Sandbox Gateway",
              style: TextStyle(color: Colors.grey, fontSize: 12),
            ),
          ],
        ),
      ),
    ),
    barrierDismissible: false,
  );

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

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

  if (!success) {
    return;
  }

  // 2. Open PayerMax BottomSheet
  await Get.bottomSheet(
    PayerMaxBottomSheet(controller: controller),
    isScrollControlled: true,
  );
}