sorry I'm pretty new to coding so I don't know many of the abbreviations/shorthand stuff.
So I'm working with React and C# trying to use Stripe to handle payments and I've gotten to the point where I am getting back a payment_intent id
, client_secret
, and payment method Id, but when I run the code:
const result = await stripe.confirmCardPayment(this.state.clientSecret, {
payment_method: paymentMethodRQ.paymentMethod.id,
});
I get the error:
No such payment_intent. Which is a 404 for the /v1/payment_intent/confirm
I guess that means the payment intent isn't actually being created since it doesn't show up on the Stripe dashboard either. Not really sure how to fix this. Most of the other similar questions either use different languages or don't address how to solve my particular issue. I followed the documentation for collecting payments then paying out, found at https://stripe.com/docs/connect/collect-then-transfer-guide#setup
This is my React code for the submit:
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
}
}
};
I am passing in an amount and currency for the PaymentIntentCreateOptions
from React.
and this is my controller for the payment intent in 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);
}
You have to make sure that your public key you declare in the frontend matches your public key in your stripe account otherwise you will get this error.