#saintlike_payment-intent-updates
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1400255513073160222
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- saintlike_code, 6 hours ago, 12 messages
- saintlike_code, 9 hours ago, 29 messages
- saintlike_code, 1 day ago, 36 messages
Is it possible to change metadata of payment intent / customer objects after initial creation?
Yes
Are your requests failing?
Hi there
No, i tried it out with setting it in the success page, not sure if that is the right thing to do and then tried accessing that payment intent in a webhook for payment_intent.succeeded but it returned a payment intent without the metadata
return (
<form id="payment-form" onSubmit={handleSubmit}>
<input type="email" placeholder="Email" value={email} onChange={(e) => setEmail(e.target.value)} />
<input type="text" placeholder="Name" value={name} onChange={(e) => setName(e.target.value)} />
<input type="text" placeholder="Product Title" value={productTitle} onChange={(e) => setProductTitle(e.target.value)} />
<input type="text" placeholder="Product Description" value={productDescription} onChange={(e) => setProductDescription(e.target.value)} />
<input type="text" placeholder="Product Price" value={productPrice} onChange={(e) => setProductPrice(e.target.value)} />
<input type="text" placeholder="Product URL" value={productUrl} onChange={(e) => setProductUrl(e.target.value)} />
<PaymentElement options={paymentElementOptions} />
<button disabled={isLoading} type="submit">
Pay now
</button>
{message && <div>{message}</div>}
</form>
)```
here's my form
here's the success page
```js
const { payment_intent: paymentIntentId } = await searchParams
if (!paymentIntentId) redirect('/')
const paymentIntent = await stripe.paymentIntents.retrieve(paymentIntentId)
if (!paymentIntent) redirect('/')
const newPaymentIntent = await stripe.paymentIntents.update(paymentIntentId, {
metadata: {
test: 'test'
}
})
const { status } = newPaymentIntent
const { customer } = newPaymentIntent```
then this is my webhook
```js
let event
try {
const rawBody = await req.text()
const signature = (await headers()).get('stripe-signature')
event = stripe.webhooks.constructEvent(
rawBody,
signature,
process.env.STRIPE_WEBHOOK_SECRET
)
...
console.log(`Payment status from webhook: ${data.metadata}`) // empty```
The webhook will not contain this metadata unless you set it before confirming the payment intent
At least, if you are listening for payment_intent.succeeded. That event is generated as part of processing the successful confirmation
do you have any idea of how i could implement that? since I initialize stripe (@/lib/stripe.js) as server-only, i cant really use it in my form submission function
i tried this out though but functions cannot be passed to client components directly
const handleChangeMetadata = async () => {
await stripe.paymentIntents.update(paymentIntentId, {
metadata: {
test: 'test from handle change metadata'
}
})
}```
i then passed it from page.jsx where i create payment intent to checkout form (client-side) and the hope was to change it on form submit
```js
<CheckoutForm clientSecret={clientSecret} handleChangeMetadata={handleChangeMetadata} />```
I'm not sure about how you have designed you front-end but, at the point where you have the necessary information, you would need to send a message to your server to trigger the update prior to confirmation.
is there a webhook i could take a look that that might occur right before confirming payment or do i just create an api endpoint that changes the metadata? not sure which approach would be a better practice
The only webhook events related to the payment intent would be .created, .updated, .payment_succeeded and .payment_failed
I don't know how you are designing your server but I would expose and endpoint my client could hit and pass the new metadata
yeah that sounds like the best approach, thanks for help ๐ค
Happy to shed what ๐ก I can ๐