【问题标题】:Flutter Stripe paymentsheet is opening webpage (hooks.stripe.com) while processing paymentsFlutter Stripe paymentsheet 在处理付款时打开网页 (hooks.stripe.com)
【发布时间】:2023-02-20 14:47:25
【问题描述】:

我正在开发一个 flutter 应用程序,它使用 stripe 进行支付。我为此使用https://pub.dev/packages/flutter_stripe

一切正常,但每当我开始付款时,我总是会得到一个网页中间件(附上屏幕截图)。我做错了什么?

这是我在 Flutter 中的实现

    Future<void> makePayment(String planName, String type) async { 
    Fluttertoast.showToast(msg: "initiating Payments, Please wait.");
   ApiProvider provider = ApiProvider();
    final tokenResponse = await provider
    .getPaymentToken(PlanPayment(planName: planName, type: type));
    if (tokenResponse != null) {`
    var _service = locator<NavigationService>();
    String secret = tokenResponse.clientSecret;

  // make a get call from this url
  Map<String, dynamic> paymentIntentData = Map();
  await payment.Stripe.instance.initPaymentSheet(
      paymentSheetParameters: payment.SetupPaymentSheetParameters(
    merchantCountryCode: 'IN',
    testEnv: true,
    paymentIntentClientSecret: secret,
    googlePay: true,
  ));
  try {
    // await Stripe.instance.handleCardAction(secret);
    await payment.Stripe.instance.presentPaymentSheet().then((value) {});
    await payment.Stripe.instance
        .confirmPaymentSheetPayment()
        .then((value) async {
      // await _service.pushNamed(paymentStatus, args: {'isSuccess': true});
    });
  } catch (e) {
    // await _service.pushNamed(paymentStatus, args: {'isSuccess': false});

    print("Stripe error" + e.toString());
  }

  await provider
      .confirmPayment(tokenResponse.transactionId)
      .then((value) async {
    await _service
        .pushReplacementNamed(paymentStatus, args: {"isSuccess": value});
  });
}

}

`

【问题讨论】:

  • 你好,你有解决这个问题吗?我也遇到了类似的问题。

标签: flutter dart payment flutter-stripe


【解决方案1】:

也许您的帐户中有一个 webhook?

【讨论】:

  • 我建议不要在答案中出现反问句。他们冒着被误解为根本不是答案的风险。您正在尝试回答本页顶部的问题,对吗?否则请删除此帖。
  • 请将此表述为解释性条件答案,以避免给人留下澄清问题而不是回答的印象(应该使用评论而不是答案,比较meta.stackexchange.com/questions/214173/…)。例如,“如果您的问题是……那么解决方案就是……因为……”。
【解决方案2】:
    1)Provide valid Secret key 
    2)Provide valid Publisable key
    3)Update flutterstripe pacakge
    4)provide valid currency code to create stripe account country  
       ex :- stripe account create india to inr etc..
    
    
    5)Right Way to implemet
    
     - Main.dart to main method run app to implemet
    
           ex :--
              Stripe.publishableKey = "your publishable key ";
    
     - create controller / method
    
    
    code:-
      Map<String, dynamic>? paymentIntentData;
    
    Future<void> makePayment({amount}) async {
        try {
          paymentIntentData =
              await createPaymentIntent(amount: amount, currency: 'INR');
          if (paymentIntentData != null) {
            await Stripe.instance.initPaymentSheet(
                paymentSheetParameters: SetupPaymentSheetParameters(
              // applePay: true,
              googlePay: const PaymentSheetGooglePay(merchantCountryCode: 'INR'),
              merchantDisplayName: "PGA",
              customerId: paymentIntentData!['customer'],
              paymentIntentClientSecret: paymentIntentData!['client_secret'],
              customerEphemeralKeySecret: paymentIntentData!['ephemeralkey'],
            ));
          }
    
          displayPaymentSheet();
        } catch (err) {
          logger.e(err);
        }
       
      }
    
      void displayPaymentSheet() async {
        try {
          await Stripe.instance.presentPaymentSheet();
          Get.snackbar("PaymentInfo", "Payment Successfully");
        } on Exception catch (e) {
          if (e is StripeException) {
            logger.e(e, "Error From Stripe");
          } else {
            logger.e(e, "Unforeseen error");
          }
        } catch (e) {
          logger.e("exeption === $e");
        }
       
      }
    
      var id = "".obs;
      createPaymentIntent({amount, currency}) async {
        try {
          Map<String, dynamic> body = {
            'amount': calculateAmount(amount: amount),
            'currency': currency,
            'payment_method_types[]': 'card'
          };
          var response = await http.post(
            Uri.parse('https://api.stripe.com/v1/payment_intents'),
            headers: {
              'Authorization':
                  'Bearer YourSecretKey',
              'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: body,
          );
          if (response.statusCode == 200) {
            var decode = jsonDecode(response.body);
            logger.e(decode);
    
            id.value = decode['id'];
            return decode;
          }
        } catch (e) {
          logger.e(e, "error charging user");
        }
       
      }
    
      calculateAmount({amount}) {
        logger.e(amount.round());
        final a = (int.parse(amount.toString())) * 100;
        logger.e(a.toString());
        update();
        return a.toString();
      }
    
    
  1.  How to  Access  Stripe payment :-
    

例如:- 任何按钮点击

      ontap : (){
makePayment(
  amount: "200")
}

【讨论】:

    猜你喜欢
    • 2017-01-28
    • 1970-01-01
    • 2021-10-26
    • 2021-11-08
    • 2022-01-27
    • 2017-01-22
    • 2022-01-16
    • 2018-11-14
    • 1970-01-01
    相关资源
    最近更新 更多