launchPaymentGateway method
Implementation
Future<void> launchPaymentGateway(
String url, String transactionid, String amount) async {
BuildContext context = Get.context!;
// url = "youtube://www.youtube.com/watch?v=dQw4w9WgXcQ";
// url = "vnd.youtube://dQw4w9WgXcQ";
debugPrint("=== Payment Gateway Launch Started ===");
debugPrint("URL: $url");
debugPrint("Transaction ID: $transactionid");
debugPrint("Amount: $amount");
try {
final uri = Uri.parse(url);
debugPrint(
"Parsed URI - Scheme: ${uri.scheme}, Host: ${uri.host}, Path: ${uri.path}",
);
debugPrint("Full URI: $uri");
final canLaunch = await canLaunchUrl(uri);
// final canLaunch = false;
debugPrint("Can launch URL: $canLaunch");
if (canLaunch) {
debugPrint("Launching URL...");
paymentmodestatus = 1;
// Helper.progressDialog(Get.context!, "");
await launchUrl(uri);
debugPrint("URL launched successfully");
Future.delayed(const Duration(seconds: 2), () {
startApiPolling(transactionid);
});
} else {
debugPrint("ERROR: Cannot launch URL - canLaunchUrl returned false");
debugPrint("URI scheme: ${uri.scheme}");
debugPrint(
"This may mean the app/scheme handler is not installed or not configured");
paymentmodestatus = 2;
// todo - based on POS API we may need to go to the payment pending screen instead we are calling the create coupon api
callCreateCouponApi(selectedAmount.value, isDeepLinkFailed: true);
// await callPaymentTransactionCreateApi(
// couponTransactionId, "QrCode", amount.toString());
}
} catch (e, stackTrace) {
debugPrint("ERROR: Exception occurred while launching payment gateway");
debugPrint("Error: $e");
debugPrint("Error Type: ${e.runtimeType}");
debugPrint("Stack Trace: $stackTrace");
paymentmodestatus = 2;
// todo - based on POS API we may need to go to the payment pending screen instead we are calling the create coupon api
callCreateCouponApi(selectedAmount.value, isDeepLinkFailed: true);
}
}