flutter 条纹错误,客户未在抖动中输入其付款方式

zi8p0yeb  于 2023-03-13  发布在  Flutter
关注(0)|答案(2)|浏览(157)

我已经使用Firebase CLI在flutter应用程序中集成了flutter_stripe 2.0.1插件。从Firebase提供的URL获得paymentIntent的成功响应。但在Stripe Jmeter 板中,支付状态为未完成
下面是我的node.js代码index.js文件

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: 1,
        currency: 'usd'
    },
        function(err, paymentIntent) {
            if(err != null){
                console.log(err);
            } else {
                res.json({
                    paymentIntent: paymentIntent.client_secret,
                })
            }
        }
    )

});

下面是我的Flutter代码

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  Stripe.publishableKey = stripePublishableKey;
  Stripe.merchantIdentifier = 'merchant.flutter.stripe.test'; //any string works
  await Stripe.instance.applySettings();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
      return MaterialApp(
        home: DashboradPage(),
      );
  }
}

class DashboradPage extends StatefulWidget {
  const DashboradPage({Key? key}) : super(key: key);

  @override
  _DashboradPageState createState() => _DashboradPageState();
}

class _DashboradPageState extends State<DashboradPage> {
  Map<String, dynamic>? paymentIntentData;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Stripe Examples'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            makePayment();
          },
          child: Text('Pay Amount'),
        ),
      ),
    );
  }

  Future<void> makePayment() async {
    final url = Uri.parse(
        'https://us-central1-stripeflutterdemo.cloudfunctions.net/stripePayment');

    final header = {'Content-Type': 'application/json'};
    try {
      final response = await http.get(url, headers: header);
      paymentIntentData = json.decode(response.body);
      await Stripe.instance.initPaymentSheet(
            paymentSheetParameters: SetupPaymentSheetParameters(
          paymentIntentClientSecret: paymentIntentData?['paymentIntent'] ?? '',
          applePay: true,
          googlePay: true,
          style: ThemeMode.light,
          merchantCountryCode: 'US',
          merchantDisplayName: 'Flutter Stripe Store Demo',
        ));
        setState(() {});
       displayPaymentSheet();
    } catch (e) {
      print(e);
      displaySnackbar(e.toString());
    }
  }

  Future<void> displayPaymentSheet() async {
    try {
      await Stripe.instance.presentPaymentSheet();
      // await Stripe.instance.presentPaymentSheet(
      //   parameters: PresentPaymentSheetParameters(
      //     clientSecret: paymentIntentData?['paymentIntent'] ?? '',
      //     confirmPayment: true,
      //   ),
      // );

      setState(() {
        paymentIntentData = null;
      });
      displaySnackbar('Payment succesfully completed');
    } catch (e) {
      print(e);
      displaySnackbar(e.toString());
    }
  }

  void displaySnackbar(String msg) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(msg),
      ),
    );
  }
}

下面是makePayment()中提到的URL的 Postman 响应

我使用了付款单,当我点击付款按钮时,它将重定向到webview(身份验证完成),但在条纹 Jmeter 板中,付款状态为未完成
条带控制面板付款事件数据付款意向状态:要求付款方法,付款意向状态:要求操作

From Stripe
payment_intent.payment_failed
View event detail
Event data
{
  "id": "pi_3JpZh7SIKwX0CSUQ0sUoM9wK",
  "object": "payment_intent",
  "last_payment_error": {
    "message": "As per Indian regulations, export transactions require a description. More info here: https://stripe.com/docs/india-exports",
    "param": "description",
    "payment_method": {
      "id": "pm_1JpZijSIKwX0CSUQ7u91wths",
      "object": "payment_method",
      "billing_details": {
        "address": {
          "city": null,
          "country": "US",
          "line1": null,
          "line2": null,
          "postal_code": "45612",
          "state": null
        },
        "email": null,
        "name": null,
        "phone": null
      },
      "card": {
        "brand": "visa",
        "checks": {
          "address_line1_check": null,
          "address_postal_code_check": "unchecked",
          "cvc_check": "unchecked"
        },
        "country": "US",
        "exp_month": 4,
        "exp_year": 2044,
        "fingerprint": "EK9VAoccqqCLBqQk",
        "funding": "credit",
        "generated_from": null,
        "last4": "4242",
        "networks": {
          "available": [
            "visa"
          ],
          "preferred": null
        },
        "three_d_secure_usage": {
          "supported": true
        },
        "wallet": null
      },
      "created": 1635431806,
      "customer": null,
      "livemode": false,
      "metadata": {
      },
      "type": "card"
    },
    "type": "invalid_request_error"
  },
  "livemode": false,
  "next_action": null,
  "status": "requires_payment_method",
  "amount": 1,
  "amount_capturable": 0,
  "amount_received": 0,
  "application": null,
  "application_fee_amount": null,
  "canceled_at": null,
  "cancellation_reason": null,
  "capture_method": "automatic",
  "charges": {
    "object": "list",
    "data": [
    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/charges?payment_intent=pi_3JpZh7SIKwX0CSUQ0sUoM9wK"
  },
  "client_secret": "pi_3JpZh7SIKwX0CSUQ0sUoM9wK_secret_oVhK5CmrcHjImvFMyoo51GCXy",
  "confirmation_method": "automatic",
  "created": 1635431705,
  "currency": "usd",
  "customer": null,
  "description": null,
  "invoice": null,
  "metadata": {
  },
  "on_behalf_of": null,
  "payment_method": null,
  "payment_method_options": {
    "card": {
      "installments": null,
      "network": null,
      "request_three_d_secure": "automatic"
    }
  },
  "payment_method_types": [
    "card"
  ],
  "receipt_email": null,
  "review": null,
  "setup_future_usage": "off_session",
  "shipping": null,
  "source": null,
  "statement_descriptor": null,
  "statement_descriptor_suffix": null,
  "transfer_data": null,
  "transfer_group": null
}

以下是iPhone截图

fnatzsnv

fnatzsnv1#

根据条纹documentationrequired_payment_method消息status表示您尚未将付款方式附加到付款意向:
创建PaymentIntent后,在附加付款方法之前,它的状态为requires_payment_method。
有一个官方的document解释了如何将Stripe payments与Firebase后端集成。它提供了正确设置Stripe payments所需的所有代码和步骤。在index.js文件中的示例代码中,它们包括了使用stripe.paymentIntents.create()创建payment intent时的其他对象

const payment = await stripe.paymentIntents.create(
    {
      amount,
      currency,
      customer,
      Payment_method, //payment method when creating the payment intent
      off_session: false,
      confirm: true,
      confirmation_method: 'manual',
    },
    { idempotencyKey }
  );

由于您的示例缺少支付方式,这可以解释您收到的错误,因为PaymentIntent是在没有支付方式的情况下创建的。我建议您按照指南来完成所有必需的步骤,以避免可能出现的进一步错误。您还可以查看完整的示例代码,该代码已记录在案,可以根据您的用例和flutter_stripe库进行定制。

pdsfdshx

pdsfdshx2#

我正在使用flutter_stripe包,并有完全相同的问题。在应用程序日志中获得成功,但在条带日志中,支付不完整,因为没有支付方式添加。一直在寻找一段时间关于这个问题,我通过添加Stripe.instance.confirmPaymentSheetPayment();await Stripe.instance.presentPaymentSheet()修复它,如下所示:

await Stripe.instance.presentPaymentSheet().then((e) {
      Stripe.instance.confirmPaymentSheetPayment();
    });

我发现他们的文档非常混乱,特别是在Stripe服务器端。
希望能有所帮助!

相关问题