#Adi

1 messages · Page 1 of 1 (latest)

royal steepleBOT
lament surge
#

Hi
What is the difference between the userId metadata and the custom metadata you want to add ?

kindred jay
#

It may happen that checkout is completed and payment intent is not in that case credits should not be set. $50 plan has 2k credits and $100 plan has 10k credits

#

sorry I mean I am setting userId and priceId metadata in checkout session object

lament surge
#

Yeah and what you want to achieve ?

#

,You set the metadata at Checkout Session?

kindred jay
#

if checkout completed I set priceId, subscription, customer Id on user object based on userId

#

now I want to set additional field i.e credits only on payment intent success

lament surge
#

No you can't propagate metadata from Checkout Session to PaymentIntent

kindred jay
#

ok got it. But if I set customer id in checkout.session.completed webhook
can I use customer id to query user and add credits in payment_intent.succeeded webhook?

#

I see customer field is common

lament surge
#

Yes you'll get the customerId

kindred jay
#

code:

else if (event.type === 'checkout.session.completed') {
            const eventData = event.data.object;

            const { customer, subscription, metadata } = eventData;
            const { userId, priceId } = metadata;
            let credits = 500;

            // $39 plan
            if (priceId === 'price_1M6msdF') {
                credits = 2000
            } // $129 plan 
            else if (priceId === 'price_1MdOoJE') {
                credits = 10000
            }
            await usersCollection.updateOne({ userId: userId }, { $set: { "subscription": subscription, "customer": customer, "trial": false} });

        } 
kindred jay
#

$50 plan has 2k credits and $100 plan has 10k credits

lament surge
#

can I have priceId as well? so that depending on priceId I can set credits
Not in PaymentIntent event

kindred jay
#

so should I set all these fields in checkout session completed?

#

can it happen that checkout session completed event success but payment.intent.failed then my logic of updating user object will not work

lament surge
kindred jay
lament surge
#

Check the last link I shared above.

kindred jay
#

ok so want to confirm only one thing is it ok if I add all the custom fields like customer id, subscription id, priceId and credits in checkout.session.completed webhook instead of payment_intent.succeeded ??

rapid pulsar
#

you should definitely use checkout.session.completed instead of the payment_intent.* events where possible, yes