openPayerMax static method
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,
- dynamic onPaymentSuccess()?,
- dynamic onPaymentFailure()?,
- 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,
);
}
}