当提交付款单时,Fightter Strided抛出StripeException
本教程将介绍当提交付款单时,Fightter Strided抛出StripeException的处理方法,这篇教程是从别的地方看到的,然后加了一些国外程序员的疑问与解答,希望能对你有所帮助,好了,下面开始学习吧。
问题描述
我正在尝试使用STRPE_Payment包在我的Ffltter应用程序中实现一个Strive支付系统。在我的代码中,我调用了Stripe.instance.initPaymentSheet(.),但是当我尝试调用Stripe.instance.Present PaymentSheet(.)时,我调用了Stripe.instance.initPaymentSheet(.)。几行之后,我收到以下错误:
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
})
}
})
})
当我尝试使用Present PaymentSheet方法时,为什么付款单没有初始化(或保持初始化)?
推荐答案
工资单在安卓上可以用,但我在iphone上不能用。
我花了几个小时才找到这个答案(也在苦苦挣扎)。
条带文档中需要进行更新,但在初始化条带时,您不仅需要初始化Stripe.PublishableKey,还需要初始化Stripe.MerchantIdentifier
示例
首先,您需要在主函数中初始化条纹。(如下所示)。
void main() async {
WidgetsFlutterBinding.ensureInitialized();
Stripe.publishableKey = stripePublishableKey;
Stripe.merchantIdentifier = 'any string works';
await Stripe.instance.applySettings();
runApp(const App());
}
然后显示工资单,不显示No payment sheet has been initialized yet
好了关于当提交付款单时,Fightter Strided抛出StripeException的教程就到这里就结束了,希望趣模板源码网找到的这篇技术文章能帮助到大家,更多技术教程可以在站内搜索。