Skip to content

Commit

Permalink
🐛 (stripe) add back subscription delete webhook handler
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Oct 11, 2022
1 parent e8baaca commit d1cc918
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions apps/builder/pages/api/stripe/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Cors from 'micro-cors'
import { buffer } from 'micro'
import prisma from 'libs/prisma'
import { withSentry } from '@sentry/nextjs'
import { Plan } from 'db'

if (!process.env.STRIPE_SECRET_KEY || !process.env.STRIPE_WEBHOOK_SECRET)
throw new Error('STRIPE_SECRET_KEY or STRIPE_WEBHOOK_SECRET missing')
Expand Down Expand Up @@ -66,6 +67,24 @@ const webhookHandler = async (req: NextApiRequest, res: NextApiResponse) => {
})
return res.status(200).send({ message: 'workspace upgraded in DB' })
}
case 'customer.subscription.deleted': {
const subscription = event.data.object as Stripe.Subscription
await prisma.workspace.update({
where: {
stripeId: subscription.customer as string,
},
data: {
plan: Plan.FREE,
additionalChatsIndex: 0,
additionalStorageIndex: 0,
chatsLimitFirstEmailSentAt: null,
chatsLimitSecondEmailSentAt: null,
storageLimitFirstEmailSentAt: null,
storageLimitSecondEmailSentAt: null,
},
})
return res.send({ message: 'workspace downgraded in DB' })
}
default: {
return res.status(304).send({ message: 'event not handled' })
}
Expand Down

5 comments on commit d1cc918

@vercel
Copy link

@vercel vercel bot commented on d1cc918 Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on d1cc918 Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on d1cc918 Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app
docs.typebot.io

@vercel
Copy link

@vercel vercel bot commented on d1cc918 Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2-alpha – ./apps/viewer

bt.id8rs.com
8jours.top
bot.aws.bj
yobot.me
minipost.uk
247987.com
ns8.vn
bot.aipr.kr
sat.cr8.ai
finplex.be
bot.enreso.org
am.nigerias.io
an.nigerias.io
vhpage.cr8.ai
bot.lalmon.com
ar.nigerias.io
bot.krdfy.com
ticketfute.com
apo.nigerias.io
apr.nigerias.io
bot.artiweb.app
eventhub.com.au
bot.tc-mail.com
games.klujo.com
bot.ageenda.com
aso.nigerias.io
sakuranembro.it
chat.sureb4.com
typebot.aloe.do
bot.piccinato.co
clo.closeer.work
bot.upfunnel.art
botc.ceox.com.br
faqs.nigerias.io
form.syncwin.com
kw.wpwakanda.com
feedback.ofx.one
myrentalhost.com
stan.vselise.com
typebot.aloe.bot
app.chatforms.net
voicehelp.cr8.ai
bot.agfunnel.tech
bot.hostnation.de
bot.phuonghub.com
cares.urlabout.me
bot.reviewzer.com
bot.maitempah.com
gentleman-shop.fr
fmm.wpwakanda.com
lb.ticketfute.com
k1.kandabrand.com
ov1.wpwakanda.com
ov2.wpwakanda.com
andreimayer.com.br
bot.megafox.com.br
1988.bouclidom.com
ov3.wpwakanda.com
bots.robomotion.io
bot.neferlopez.com
cadu.uninta.edu.br
dicanatural.online
goalsettingbot.com
positivobra.com.br
survey.digienge.io
zap.techadviser.in
bot.digitalbled.com
bot.eventhub.com.au
carsalesenquiry.com
forms.webisharp.com
kbsub.wpwakanda.com
this-is-a-test.com
demo.botscientis.us
live.botscientis.us
mentoria.omelhor.vc
nutrisamirbayde.com
quest.wpwakanda.com
order.maitempah.com
test.botscientis.us
typebot.stillio.com
bot.ansuraniphone.my
bot.cotemeuplano.com
chatbee.agfunnel.com
bium.gratirabbit.com
chat.hayurihijab.com
click.sevenoways.com
get.freebotoffer.xyz
connect.growthguy.in
kuiz.sistemniaga.com
offer.botscientis.us
uppity.wpwakanda.com
abutton.wpwakanda.com
tenorioadvogados.com
aidigitalmarketing.kr
talkbot.agfunnel.com
bbutton.wpwakanda.com
bot.incusservices.com
bot.meuesocial.com.br
bot.ramonmatos.com.br
cdd.searchcube.com.sg

@vercel
Copy link

@vercel vercel bot commented on d1cc918 Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
app.typebot.io
builder-v2-git-main-typebot-io.vercel.app

Please sign in to comment.