shop app 的stripe 的live mode
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:shop_app/models/Cart.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../constants.dart';
class Paypal extends StatefulWidget {
final String sessionId;
const Paypal({Key key, this.sessionId}) : super(key: key);
@override
_PaypalState createState() => _PaypalState();
}
class _PaypalState extends State<Paypal> {
WebViewController _controller;
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
body: WebView(
initialUrl: initialUrl,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) => _controller = controller,
onPageFinished: (String url) {
if (url == initialUrl) {
print("${initialUrl} is url");
_redirectToStripe();
}
},
navigationDelegate: (NavigationRequest request) {
if (request.url.startsWith("https://success.com")) {
demoCarts.clear();
Navigator.pop(context);
} else if (request.url.startsWith("https://cancel.com")) {
Navigator.of(context).pop("cancel");
}
return NavigationDecision.navigate;
},
),
);
}
String get initialUrl =>
'data:text/html;base64,${base64Encode(Utf8Encoder().convert(kStripeHtmlPage))}';
void _redirectToStripe() {
//<--- prepare the JS in a normal string
final redirectToCheckoutJs = '''
var stripe = Stripe('$apiKey');
stripe.redirectToCheckout({
sessionId: '${widget.sessionId}'
}).then(function (result) {
result.error.message = 'Error'});
''';
_controller.evaluateJavascript(
redirectToCheckoutJs); //<--- call the JS function on controller
}
}
const kStripeHtmlPage = '''
<!DOCTYPE html>
<html>
<script src="https://js.stripe.com/v3/"></script>
<head><title>Stripe checkout</title>
</head>
<body>
<h3>Please wait for a moment...</h3>
</body>
</html>
''';
出現了"uncaught integrationerror: live stripe.js integrations must use https.
我要怎麼把kStripeHtmlPage轉成https?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论