本文介绍了当提交付款单时,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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 04:05