#Adi
1 messages · Page 1 of 1 (latest)
Hi
What is the difference between the userId metadata and the custom metadata you want to add ?
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
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
No you can't propagate metadata from Checkout Session to PaymentIntent
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
Yes you'll get the customerId
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} });
}
can I have priceId as well? so that depending on priceId I can set credits
$50 plan has 2k credits and $100 plan has 10k credits
can I have priceId as well? so that depending on priceId I can set credits
Not in PaymentIntent event
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
You can set all the fields when Creating the Checkout Session.
that could happen for async payment methods
sorry like what ?? any example
Check the last link I shared above.
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 ??
you should definitely use checkout.session.completed instead of the payment_intent.* events where possible, yes