处理付款时,Flutter Stripe付款单正在打开网页(hooks.stripe.com

iugsix8n  于 2023-02-25  发布在  Flutter
关注(0)|答案(2)|浏览(186)

我正在开发一个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});
  });
}

}
'

dw1jzc5e

dw1jzc5e1#

也许你有一个webhook放在你的帐户?

t30tvxxf

t30tvxxf2#

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 = "";
          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 = 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();
          }
        
        
 6)      How to  Access  Stripe payment :-
ex :- any button click 
        
          ontap : (){
    makePayment(
      amount: "200")
    }

相关问题