【发布时间】:2021-11-08 02:11:42
【问题描述】:
我正在尝试使用 stripe_payment 包在我的 Flutter 应用中实现 Stripe 支付系统。在我的代码中,我调用了 Stripe.instance.initPaymentSheet(...),但是当我尝试在几行之后调用 Stripe.instance.presentPaymentSheet(...) 时,我收到了这个错误:
flutter: StripeException(error: LocalizedErrorMessage(code: FailureCode.Failed, localizedMessage: No payment sheet has been initialized yet, message: No payment sheet has been initialized yet, stripeErrorCode: null, declineCode: null, type: null))
这是我的代码:
Future<void> makePayment() async {
final url = Uri.parse(
'${firebaseFunction}');
final response =
await http.get(url, headers: {'Content-Type': 'application/json'});
this.paymentIntentData = json.decode(response.body);
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: paymentIntentData!['paymentIntent'],
applePay: true,
googlePay: true,
style: ThemeMode.dark,
merchantCountryCode: 'UK',
merchantDisplayName: 'Test Payment Service'));
setState(() {});
print('initialised');
try {
await Stripe.instance.presentPaymentSheet();
setState(() {
paymentIntentData = null;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Payment Successful!'),
));
} catch (e) {
print(e);
}
// await displayPaymentSheet();
}
这是我的 node.js 代码(通过 url 访问):
const functions = require("firebase-functions");
const stripe = require('stripe')(functions.config().stripe.testkey);
exports.stripePayment = functions.https.onRequest(async (req, res) => {
const paymentIntent = await stripe.paymentIntents.create({
amount: 170,
currency: 'usd'
},
function(err, paymentIntent) {
if (err != null) {
console.log(err);
} else {
res.json({
paymentIntent: paymentIntent.client_secret
})
}
})
})
当我尝试使用 presentPaymentSheet 方法时,为什么付款表没有初始化(或保持初始化)?
【问题讨论】:
-
@ZackHossian 你解决问题了吗?
-
@ZackHossain 你解决了吗,我也有同样的问题
标签: android ios flutter stripe-payments flutter-dependencies