我尝试在flutter应用中使用stripe_payment包实现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方法时,为什么Payment Sheet没有初始化(或保持初始化)?
3条答案
按热度按时间g0czyy6m1#
Paymentsheet在Android上可以用,但在我的iPhone上不行。我花了几个小时才找到这个答案(也很难)。需要在stripe文档中更新,但初始化Stripe时,您需要初始化Stripe.publishableKey和Stripe.merchantIdentifier
示例
首先你需要在你的主函数中初始化Stripe。(如下所示)。
然后付款单将显示,但不显示
No payment sheet has been initialized yet
pbossiut2#
如果有人在未来结束在这里,你已经尝试了一切,包括添加额外的设置在您的主文件中,也尝试改变您的
Stripe.instance.initPaymentSheet
字段中的Stripe.instance.initPaymentSheet
为null
或一些现有的ID。我发现,对于android它很容易工作,但与iOS它需要一个适当的customerId或空。bzzcjhmw3#
条带版本
添加属性“customFlow”解决了我的问题