#saintlike_payment-intent-updates

1 messages ยท Page 1 of 1 (latest)

warm salmonBOT
#

๐Ÿ‘‹ 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.

modest crown
#

Is it possible to change metadata of payment intent / customer objects after initial creation?

Yes

#

Are your requests failing?

unborn dome
#

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```
modest crown
#

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

unborn dome
#

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} />```
modest crown
#

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.

unborn dome
#

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

modest crown
#

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

unborn dome
modest crown
#

Happy to shed what ๐Ÿ’ก I can ๐Ÿ™‚