繁体   English   中英

React Stripe api 不能在现场工作,但在本地工作正常

[英]React Stripe api not working on live but fine on local

我以为我在回家的路上然后砰! 回到地球! 而我自己的最后期限就快到了!

Final 使用条纹支付表格在本地完成所有工作,并推送到现场,不知何故我从我的 api 代码中收到一条消息说

控制台错误:

POST https://example.com/api/charge 400 (Bad Request)

{ "message":"缺少必需的参数:数量。" },

这一切都很新,但任何帮助都会很棒! 下面发布的代码

我的charges.js 文件

import Stripe from "stripe";
const stripe = new Stripe(process.env.SECRET_KEY);

export default async (req, res) => {
  const { id, amount } = req.body;

  try {
    const payment = await stripe.paymentIntents.create({
      amount,
      currency: "AUD",
      description: "Delicious empanadas",
      payment_method: id,
      confirm: true,
    });

    console.log(payment);

    return res.status(200).json({
      confirm: "abc123",
    });
  } catch (error) {
    console.log(error);
    return res.status(400).json({
      message: error.message,
    });
  }
};

我的 checkoutform.js

const CheckoutForm = ({ success }) => {
  const stripe = useStripe();
  const elements = useElements();
  const [isProcessing, setProcessingTo] = useState(false);
  const [checkoutError, setCheckoutError] = useState();

  const handleSubmit = async (event) => {
    event.preventDefault();

    const { error, paymentMethod } = await stripe.createPaymentMethod({
      type: "card",
      card: elements.getElement(CardElement),
      billing_details: {
        name: event.target.name.value,
        address: {
          city: event.target.city.value,
          line1: event.target.line1.value,
          line2: event.target.line2.value,
        },
      },
    });

    setProcessingTo(true);

    if (!error) {
      const { id } = paymentMethod;

      try {
        const { data } = await axios.post("/api/charge", { id, amount: 2000 });
        console.log(data);
        success();
      } catch (error) {
        console.log(error);
      }
    }
  };

消息说您没有传递参数amount ,这是强制性的。

文档: https://stripe.com/docs/api/payment_intents/create

const payment = await stripe.paymentIntents.create({
  amount: 100,
  currency: "AUD",
  description: "Delicious empanadas",
  payment_method: id,
  confirm: true,
});

暂无
暂无

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

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