#shubhamjha
1 messages · Page 1 of 1 (latest)
Hi! Let me help you with this.
Could you please share an example event ID? evt_xxx
in my case if any event occurs , if a chekout session is compelted webhook api calling twice
Are you sure it's the same event?
This one was only sent once too, at 2023-03-13 11:37:49 UTC.
Could you please share some code of your webhook endpoint?
case 'checkout.session.completed':
session = await event.data.object
const c = await stripe.customers.retrieve(session.customer)
userId = c.metadata.Authtoken
const customerid = c.id
if (session.mode == 'payment') {
data = await getUserData(userId)
const id = _get(data, 'Item.user_subscriptionid', 0)
expiryDate = get(data, 'Item.user_current_plan_expiry', 0)
if (session.metadata.update == 'yes' || session.metadata.subid == id) {
let paylink = await session.metadata.updatelink
if (id == 'plancanceled') {
callWhenUdate({ customerid, expiryDate, paylink })
return
}
if (id.startsWith('sub_sched')) {
await stripe.subscriptionSchedules.release(id)
callWhenUdate({ customerid, expiryDate, paylink })
} else {
const subscription = await stripe.subscriptions.retrieve(id)
await stripe.subscriptions.update(id, {
metadata: { Authtoken: userId, sub: '', s: 'cancel' },
cancel_at_period_end: true,
})
subscriptionid = id
pLink = paylink
retrievePrice = subscription
whenUpgrade({ subscriptionid, pLink, retrievePrice })
}
} else {
const a = await session.amount_total
const amount = a / 100
await addC(userId, amount)
}
} else {
console.log('this ')
console.log(session.metadata.newsubscription)
await addPlan({ plan, subscriptionid, userId, expiryDate })