【问题标题】:Why not displaying card为什么不显示卡
【发布时间】:2023-02-18 04:12:49
【问题描述】:

我想 intigrate 条纹支付,但我得到了这个错误 ** 在调用 presentPaymentOptions() 之前,必须使用 configureWithPaymentIntent() 或 configureWithSetupIntent() 成功初始化 FlowController** 如何解决这个错误也没有显示任何卡片

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, );
    }
  }

【问题讨论】:

  • 您是否设置了 Android 端代码?我们必须更改 MainActivity.kt 同样在 Main 函数中确保您已添加条带可发布密钥
  • 如何更改 MainActivity.kt?
  • 我已经更改 MainActivity.kt 但问题是一样的

标签: flutter stripe-payments


【解决方案1】:

您需要在服务器端而不是在您的 flutter 应用程序中创建 PaymentIntent。

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'
          }
      );

不要像上面的代码那样直接调用 Stripe API,你应该调用你自己的 API 并生成一个 Payment Intent 并将 client_secret 发送到你的 flutter App,否则你会暴露你的密钥并因此授予访问权限到你的数据。这是描述here

一旦你完成了这个服务器端部分,剩下的就在 here 中解释了。

【讨论】:

    猜你喜欢
    • 2018-06-19
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    相关资源
    最近更新 更多