我已经集成了 RazorPay 自定义结帐,在那里我为良好的用户体验创建了自定义设计。
我在inappwebview
Flutter插件中打开这个定制的网络应用程序。Web 应用程序可以正确打开,但是一旦 Razorpay 的 SDK 功能createPayment(data)
运行,它就会打开一个窗口弹出窗口。这个弹出窗口现在在 webview 中不可见。
调用 webview 的 Flutter 代码:
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: _handleBackPress,
child: SafeArea(
child: Scaffold(
body: InAppWebView(
initialUrlRequest: URLRequest(
url: Uri.parse(Strings.checkoutUrl),
),
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
clearCache: true,
javaScriptCanOpenWindowsAutomatically: true, // I thought this will help, but not working
mediaPlaybackRequiresUserGesture: false,
),
android: AndroidInAppWebViewOptions(useHybridComposition: true),
ios: IOSInAppWebViewOptions(allowsInlineMediaPlayback: true),
),
onWebViewCreated: (controller) async {
_controller = controller;
_controller.clearCache();
_controller.addJavaScriptHandler(
handlerName: 'PaymentHandle',
callback: (data) {
// ... Will do somthing
},
);
},
onLoadStop: (_, __) async {
await _controller.evaluateJavascript(source: '''
window.parent.postMessage(${widget.paymentJsonData}, "*");
''');
},
),
),
),
);
}
调用代码createPayment()
:当用户单击按钮时,在 webapp 上调用此函数。
async makePayment() {
try {
const data = {
callback_url: '<Callback URL>',
redirect: true,
amount: 50000,
email: 'gaurav.kumar@example.com',
contact: '9123456780',
order_id: 'order_<order_hash>',
method: 'upi',
upi: {
vpa: this.vpa, // Fetch from input field
flow: 'collect,',
},
};
window.rz.createPayment(data);
window.rz.focus(); // Found in RazorPay's document to bring the window in focus. Not working on Webview
} catch (e) {
console.error(e);
}
},
PS - RazorPay 的初始化工作正常。我们在浏览器上单独运行 Webview。弹出窗口正在正确打开