出现Stripe错误:没有这样的payment_intent:'我的付款意图ID'

时间:2020-10-06 00:24:41

标签: c# reactjs stripe-payments http-status-code-404

对不起,我是编码的新手,所以我不知道很多缩写/速记材料。 因此,我正在与React和C#一起尝试使用Stripe来处理付款,现在我回到了payment_intent idclient_secret和付款方式ID的地步,但是当我运行代码:

const result = await stripe.confirmCardPayment(this.state.clientSecret, {
      payment_method: paymentMethodRQ.paymentMethod.id,
    });

我得到了错误:

没有这样的付款意图。 / v1 / payment_intent / confirm是404

我猜这意味着实际上没有创建付款意图,因为它也没有显示在Stripe仪表板上。不太确定如何解决此问题。其他大多数类似的问题或者使用不同的语言,也没有解决如何解决我的特定问题。我按照https://stripe.com/docs/connect/collect-then-transfer-guide#setup

上的说明收集付款然后付款的文档

这是我提交的React代码:

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

    const { stripe, elements } = this.props;

    if (!stripe || !elements) {
      _logger("Stripe.js has not yet loaded.");
      // Make  sure to disable form submission until Stripe.js has loaded.
      return;
    }
    const paymentMethodRQ = await stripe.createPaymentMethod({
      type: "card",
      card: elements.getElement(CardElement),
    });

    const result = await stripe.confirmCardPayment(this.state.clientSecret, {
      payment_method: paymentMethodRQ.paymentMethod.id,
    });

    if (result.error) {
      toast.error("payment not processed");
      _logger(result.error.message, "payment not processed");
    } else {
      toast.success("The payment processing!");
      if (result.paymentIntent.status === "succeeded") {
        _logger("payument successful");
        // havent gotten to this part yet
      }
    }
  };

我正在从 React 输入PaymentIntentCreateOptions的金额和货币。 这是我在 Visual Studio 中用于付款意向的控制器:

[HttpPost("paymentintent")]
        public async Task<IActionResult> PaymentIntent(PaymentIntentCreateOptions options)
        {
            StripeConfiguration.ApiKey = "my test secret key";

            ItemResponse<PaymentIntentModel> response = new ItemResponse<PaymentIntentModel>();
            var service = new PaymentIntentService();
            var paymentIntent = service.Create(options);

            Logger.LogInformation(paymentIntent.ToString());

            var paymentIntentModel = new PaymentIntentModel();
            paymentIntentModel.Id = paymentIntent.Id;
            paymentIntentModel.ClientSecretKey = paymentIntent.ClientSecret;
            response.Item = paymentIntentModel;

            return Ok200(response);
        }

1 个答案:

答案 0 :(得分:0)

您必须确保在前端声明的公钥与您的条带化帐户中的公钥匹配,否则会出现此错误。