简体   繁体   English

React Native,Stripe 与 python 后端集成

[英]React Native, Stripe Integration with python backend

I want to integrate Stripe with my react native app however i keep getting the error "localizedMessage": "You must provide paymentMethodType", even though i added the payementMethod this is my backend:我想将 Stripe 与我的 React 本机应用程序集成,但是我不断收到错误“localizedMessage”:“您必须提供 paymentMethodType”,即使我添加了 payementMethod 这是我的后端:

@app.route("/create-payment-intent-native", methods=["POST"])
def create_payment_native():
    stripe.api_key = key
    try:
        data = json.loads(request.data)
        if "amount" in data:
            try:
                intent = stripe.PaymentIntent.create(
                    amount=int(data["amount"]* 100),
                    currency=data["currency"],
                    payment_method_types=['card'],
                )
                return jsonify({"clientSecret": intent["client_secret"]})
            except ValueError as e:
                return jsonify(error=str(e))
        else:
            return jsonify(error="No amount to pay in request")
    except Exception as e:
        return jsonify(error=str(e))

and this is how i'm send the request:这就是我发送请求的方式:

 const fetchPaymentIntentClientSecret = async () => {
  const response = await fetch(`https://api.click-n.com/create-payment-intent-native`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      currency: 'CAD',
      amount: totalPrice,
    }),
  });
  const { clientSecret } = await response.json();
  return clientSecret;
};

const { confirmPayment, loading } = useConfirmPayment();
const handlePayPress = async () => {
    const clientSecret = await fetchPaymentIntentClientSecret();
    const billingDetails = {
    email: 'email@stripe.com',
    phone: '+48888000888',
    addressCity: 'Houston',
    addressCountry: 'US',
    addressLine1: '1459  Circle Drive',
    addressLine2: 'Texas',
    addressPostalCode: '77063',
  };
    const { error, paymentIntent } = await confirmPayment(clientSecret, {
    type: 'Card',
    billingDetails,
  });
    if (error) {
    console.log(error)
  } else if (paymentIntent) {
    console.log(paymentIntent)
  }
};

i'm not sure what i'm doing wrong我不确定我做错了什么

You are specifying type in the your call to confirmPayment .您在调用confirmPayment时指定type The expected parameter is paymentMethodType .预期参数是paymentMethodType Also you will need to nest the billingDetails inside a paymentMethodData parameter.此外,您还需要将billingDetails嵌套在paymentMethodData参数中。

You can see the expected function signature in the code snippet here您可以在此处的代码片段中看到预期的函数签名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM