Stripe - PaymentIntent requires payment method issues in Node.js
P粉441076405
2023-09-03 13:55:13
<p>I'm trying to integrate stripe into my project but I'm getting the "<strong>PaymentIntent requires a payment method</strong>" message. The payment status code in the log is 200. But in the payment dashboard it says "Incomplete" because "<strong>The customer has not yet entered their payment method.</strong>"</p>
<p><strong>Here is my Stripe backend code</strong></p>
<pre class="brush:php;toolbar:false;">exports.StripePayment = (req, res) => {
const { amount, token } = req.body;
const idempotencyKey = uuid();
return stripe.customers
.create({
email: token.email,
source: token.id,
})
.then((customer) => {
stripe.paymentIntents
.create(
{
amount: amount,
currency: "INR",
payment_method_types: ["card"],
customer: customer.id,
receipt_email: token.email,
shipping: {
name: token.card.name,
address: {
line_1: token.card.address_1,
line_2: token.card.address_2,
city: token.card.address_city,
country: token.card.address_country,
postal_code: token.card.address_zip,
},
},
},
{ idempotencyKey }
)
.then((result) => {
console.log("Result", result);
return res.status(200).json(result);
})
.catch((err) => console.log(err));
});
};</pre>
<p>Need help fixing. Thanks in advance</p>
This is expected behavior. The code you shared only creates a payment intent, it does not persist during its lifecycle中推进该意图一个>.
You currently do not provide a payment method that has been created, nor a way for customers to provide their payment method details. This information is required for Stripe to process the payment.
Creating a payment intent is just the first step in Stripe integration. This guide from Stripe covers everything you need to use their service to process payments and is a great starting point for building an integration:
https://stripe.com/docs/ payments/accept- a- payment?platform=web&ui=elements
This guide will walk you through the rest of what you need to build, including providing a UI for your customers to provide their payment method details and confirm payment intent.