使用 Stripe 时出错:没有这样的 payment_intent:'my payment intent id'
Getting error with Stripe: No such payment_intent: 'my payment intent id'
抱歉,我对编码还很陌生,所以我不知道很多 abbreviations/shorthand 的东西。
所以我正在使用 React 和 C# 尝试使用 Stripe 来处理付款,我已经到了我要取回 payment_intent id
、client_secret
和付款方式 ID 的地步,但是当我运行代码:
const result = await stripe.confirmCardPayment(this.state.clientSecret, {
payment_method: paymentMethodRQ.paymentMethod.id,
});
我收到错误:
No such payment_intent. Which is a 404 for the /v1/payment_intent/confirm
我想这意味着付款意向实际上并未创建,因为它也没有显示在 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);
}
您必须确保您在前端声明的 public 密钥与您在条纹帐户中的 public 密钥匹配,否则您将收到此错误。
抱歉,我对编码还很陌生,所以我不知道很多 abbreviations/shorthand 的东西。
所以我正在使用 React 和 C# 尝试使用 Stripe 来处理付款,我已经到了我要取回 payment_intent id
、client_secret
和付款方式 ID 的地步,但是当我运行代码:
const result = await stripe.confirmCardPayment(this.state.clientSecret, {
payment_method: paymentMethodRQ.paymentMethod.id,
});
我收到错误:
No such payment_intent. Which is a 404 for the /v1/payment_intent/confirm
我想这意味着付款意向实际上并未创建,因为它也没有显示在 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);
}
您必须确保您在前端声明的 public 密钥与您在条纹帐户中的 public 密钥匹配,否则您将收到此错误。