#Murali-setup-intent

1 messages · Page 1 of 1 (latest)

potent hawk
#

Hey, what's the issue?

valid crescent
#

I am creating a setupintent & then a customer

#

I m updating setupintent with the customer id

#

StripeInvalidRequestError: You cannot update this SetupIntent because it has already succeeded.

#

I am getting above error message

potent hawk
#

It's right, you can't update the Setup Intent once confirmed. If you need to update it, you should do so before confirming

valid crescent
#

I need solution, I can understand by reading the error message.

potent hawk
#

If you need to update it, you should do so before confirming
That's your solution

#

Why would you want to update the Setup Intent after its confirmed/succeeded? The purpose of a Setup Intent is to setup/save a payment method. Its redundant once succeeded

valid crescent
#

app.get('/secret-key', async (req, res) => {
try {
const setupIntent = await stripe.setupIntents.create();
res.send({
setupIntent:setupIntent,
secretKey: setupIntent.client_secret
});
} catch (error) {
console.log("ERROR IN GET SECRET KEY::",error);
}
});

#

I am creating the setupintent to get the secret_key

#

I am setting the Elements options with this secret key.

#

Reading email, name and card details and creating the customer

potent hawk
#

You should create the Customer before the Setup Intent and pass the customer parameter to setupIntents.create()

valid crescent
#

once customer is created i m trying to update the setupintent with customer id

#

<Elements stripe={stripePromise} options={options}>
<SetupForm />
</Elements>

#

how to read card details without providing the secret_key in the options of <Elements> ?

potent hawk
valid crescent
#

so what do you suggest ?

potent hawk
#

You should create the Customer before the Setup Intent and pass the customer parameter to setupIntents.create()

valid crescent
#

Stripe recommends getting started with the newer Payment Element instead of the Card Element. It allows you to accept multiple payment methods with a single Element. Learn more about when to use the Card Element and Payment Element.

potent hawk
#

Why do you need to save the card details while creating the customer? The Setup Intent will attach the card to the Customer

#

That's the whole purpose of a Setup Intent

#
  • Create the Customer
  • Create the Setup Intent, passing the customer: 'cus_xxx' parameter
  • Initiate Elements/Payment Element with the client_secret
  • confirmSetup
#

You'll then have a reusable Payment Method (pm_xxx) that is saved to that customer

valid crescent
#

I m doing it in a wrong way, I give it a try what you suggested.
thanks for your time.

potent hawk
#

Sure, np!