我想集成条带支付,但收到此错误在调用presentPaymentOptions()之前,必须使用configureWithPaymentIntent()或configureWithSetupIntent()成功初始化流量控制器如何解决此错误以及它不显示任何卡
Center(
child: ElevatedButton(
onPressed: () {
intpayment(email: "email,amount: 50.0);
},
child: Text("Pay20\$"),
),
),
Future<void> intpayment(
{required String email, required double amount})async{
try{
final response= await http.post(Uri.parse("https://api.stripe.com/v1/payment_intents")
,body:{
"receipt_email": email,
"amount": amount.toInt().toString(),
"currency": "usd"
},
headers: {
'Authorization': 'Bearer ' + 'key',
'Content-Type': 'application/x-www-form-urlencoded'
}
);
final jsonresponse=jsonDecode(response.body); Stripe.instance.initPaymentSheet(paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: jsonresponse['paymentIntent'],
merchantDisplayName: 'Zohaib',
));
await Stripe.instance.presentPaymentSheet();
Fluttertoast.showToast(
msg: "payment successfully",
);
}
catch(e){
if (e is StripeException) {
Fluttertoast.showToast(
msg: "Stripe error $e",
);
}
Fluttertoast.showToast(
msg: "$e",
toastLength: Toast.LENGTH_SHORT, );
}
}
1条答案
按热度按时间fd3cxomn1#
您需要在服务器端创建PaymentIntent,而不是在flutter应用中。
您不应该像上面的代码那样直接调用Stripe API,而应该调用自己的API并生成一个支付意向,然后将
client_secret
发送到flutter应用,否则您将暴露自己的密钥,从而获得对数据的访问权限。完成服务器端部分后,下面将介绍其余部分。