callGenerateLinkAPI function
Future<void>
callGenerateLinkAPI(
- BuildContext context,
- String bankIds,
- String tranNos,
- String referrerId,
Implementation
Future<void> callGenerateLinkAPI(BuildContext context, String bankIds,
String tranNos, String referrerId) async {
showDialog(
context: context,
barrierDismissible: false,
barrierColor: Colors.transparent,
builder: (
BuildContext context,
) {
return Center(
child: CircularProgressIndicator(
backgroundColor: Colors.transparent,
color: loadingColor,
),
);
},
);
bool? isProduction = B24PaymentSdk.storeIsProduction;
bool? darkMode = B24PaymentSdk.storeDarkMode;
final urlGenerate =
isProduction == false ? envDemo().UrlGenerate : envPro().UrlGenerate;
final Map<String, dynamic> data = {
"bank_id": bankIds,
"tran_id": tranNos,
};
final Map<String, String> headers = {
'token':
//'342jjdfenfwnf',
envDemo().token,
'X-Referrer-Key': referrerId,
'Content-Type': 'application/json',
};
final response = await http.post(
Uri.parse(urlGenerate),
body: jsonEncode(data),
headers: headers,
);
Navigator.of(context, rootNavigator: true).pop();
if (response.statusCode != 200) {
showMessagePopup(
context,
bgColor: Color(0XFFFDEDEE),
iconColor: Color(0XFFEE4D61),
textColor: Color(0XFF131C18),
content: translation.getTranslation('errorGetData'),
icons: Icons.info_rounded,
);
}
if (response.statusCode == 200) {
final decodedResponse = json.decode(response.body);
final mobileDeepLink = decodedResponse['data']['mobile_deep_link'];
final webPaymentUrl = decodedResponse['data']['web_payment_url'];
final ulrMobileDeepLink = Uri.parse(mobileDeepLink);
final messange = decodedResponse['message'];
final messangeKh = decodedResponse['message_kh'];
//Navigator.of(context, rootNavigator: true).pop();
if (mobileDeepLink == null && webPaymentUrl == null ||
mobileDeepLink.isEmpty && webPaymentUrl.isEmpty) {
showMessagePopup(
context,
bgColor: Color(0XFFFDEDEE),
iconColor: Color(0XFFEE4D61),
textColor: Color(0XFF131C18),
content: translation.getTranslation(
languages == 'km'
? messangeKh ?? "ប្រព័ន្ធមានបញ្ហា !"
: messange ?? "System error !",
),
icons: Icons.info_rounded,
);
} else if (!kIsWeb && (mobileDeepLink == null || mobileDeepLink.isEmpty)) {
final url = webPaymentUrl;
Navigator.of(context).pop();
Bottomsheets.show(
context,
Column(
children: [
Container(
alignment: Alignment.center,
margin: const EdgeInsets.only(top: 10.0),
height: heightLine,
width: widthLine,
decoration: BoxDecoration(
color: darkMode == false
? ThemeLight().indicatorColor
: ThemeDark().indicatorColor,
borderRadius: BorderRadius.circular(29.0),
),
),
SizedBox(height: 17.0),
// Expanded(
// child: WebView(
// debuggingEnabled: true,
// initialUrl: url,
// javascriptMode: JavascriptMode.unrestricted,
// gestureRecognizers: Set()
// ..add(Factory<VerticalDragGestureRecognizer>(
// () => VerticalDragGestureRecognizer())),
// ),
// ),
Expanded(
child: WebViewWidget(
gestureRecognizers: Set()
..add(Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer())),
controller: WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..loadRequest(Uri.parse(url))))
],
),
);
} else if (UniversalPlatform.isIOS) {
await launchUrl(ulrMobileDeepLink, mode: LaunchMode.externalApplication);
} else if (UniversalPlatform.isAndroid) {
await launchUrl(ulrMobileDeepLink);
} else if (UniversalPlatform.isWeb) {
html.window.open(webPaymentUrl, '_self');
}
} else {
print('Failed to call GenerateLink API: ${response.statusCode}');
}
}