openPaystack static method
Opens Pay stack checkout screen with provided details
Parameters:
context
: BuildContext required for checkoutsecretKey
: Pay stack Secret KeycustomerEmail
: Customer emailamount
: Amount in kobo (₦200 = 20000)currency
: Default NGNcallbackUrl
: Optional callback URLpaymentGatewayName
: (Optional) Gateway name for default toast/logonShowToast
: (Optional) User can override default toastonPaymentSuccess
: Callback when payment succeedsonPaymentFailure
: Callback when payment fails
Implementation
static Future<void> openPaystack({
required BuildContext context,
required String secretKey,
required String customerEmail,
required num amount,
String currency = "NGN",
String? callbackUrl,
String paymentGatewayName = "Pay stack",
Function()? onShowToast,
Function()? onPaymentSuccess,
Function()? onPaymentFailure,
}) async {
try {
final uniqueTransRef = PayWithPayStack().generateUuidV4();
await PayWithPayStack().now(
context: context,
secretKey: secretKey,
customerEmail: customerEmail,
reference: uniqueTransRef,
currency: currency,
amount: double.parse(amount.toString()),
callbackUrl: callbackUrl ?? "https://google.com",
transactionCompleted: (paymentData) {
final successResponse = IncodesPaymentResponse(
"Payment Successful",
true,
paymentData.reference ?? uniqueTransRef,
);
if (onShowToast != null) {
onShowToast();
} else {
IncodesListener().onSuccess(
response: successResponse,
paymentGatewayName: paymentGatewayName,
isShowToast: true,
);
}
onPaymentSuccess?.call();
log("Pay stack Payment Successful: ${paymentData.toString()}");
},
transactionNotCompleted: (reason) {
final failureResponse = IncodesPaymentResponse(
"Payment Failed: $reason",
false,
uniqueTransRef,
);
if (onShowToast != null) {
onShowToast();
} else {
IncodesListener().onFailure(
response: failureResponse,
paymentGatewayName: paymentGatewayName,
isShowToast: true,
);
}
onPaymentFailure?.call();
log("Pay stack Payment Failed: $reason");
},
);
} catch (e) {
log("Pay stack Exception => $e");
}
return;
}