The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix stripe webhooks
Steven Teye60b2c6e2efe
diff --git a/apps/web/app/api/stripe/webhook/checkout-session-completed.ts b/apps/web/app/api/stripe/webhook/checkout-session-completed.tsindex a4fd1a8530..3df83fbb0d 100644--- a/apps/web/app/api/stripe/webhook/checkout-session-completed.ts+++ b/apps/web/app/api/stripe/webhook/checkout-session-completed.ts@@ -84,15 +84,6 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {},});- await prisma.restrictedToken.updateMany({- where: {- projectId: workspaceId,- },- data: {- rateLimit: plan.limits.api,- },- });-const users = workspace.users.map(({ user }) => ({id: user.id,name: user.name,@@ -115,6 +106,24 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {}),);}),+ // update rate limits for restricted tokens for the workspace+ prisma.restrictedToken.updateMany({+ where: {+ projectId: workspaceId,+ },+ data: {+ rateLimit: plan.limits.api,+ },+ }),+ // enable dub.link premium default domain for the workspace+ prisma.defaultDomains.update({+ where: {+ projectId: workspaceId,+ },+ data: {+ dublink: true,+ },+ }),]);}diff --git a/apps/web/app/api/stripe/webhook/customer-subscription-deleted.ts b/apps/web/app/api/stripe/webhook/customer-subscription-deleted.tsindex 36151ae249..427ff63846 100644--- a/apps/web/app/api/stripe/webhook/customer-subscription-deleted.ts+++ b/apps/web/app/api/stripe/webhook/customer-subscription-deleted.ts@@ -100,6 +100,16 @@ export async function customerSubscriptionDeleted(event: Stripe.Event) {},}),+ // disable dub.link premium default domain for the workspace+ prisma.defaultDomains.update({+ where: {+ projectId: workspace.id,+ },+ data: {+ dublink: false,+ },+ }),+// remove root domain link for all domains from MySQLprisma.link.updateMany({where: {diff --git a/apps/web/app/api/stripe/webhook/customer-subscription-updated.ts b/apps/web/app/api/stripe/webhook/customer-subscription-updated.tsindex 00bd060457..4310417b81 100644--- a/apps/web/app/api/stripe/webhook/customer-subscription-updated.ts+++ b/apps/web/app/api/stripe/webhook/customer-subscription-updated.ts@@ -61,29 +61,30 @@ export async function customerSubscriptionUpdated(event: Stripe.Event) {// If a workspace upgrades/downgrades their subscription, update their usage limit in the database.if (workspace.plan !== newPlan) {- await prisma.project.update({- where: {- stripeId,- },- data: {- plan: newPlan,- usageLimit: plan.limits.clicks!,- linksLimit: plan.limits.links!,- domainsLimit: plan.limits.domains!,- aiLimit: plan.limits.ai!,- tagsLimit: plan.limits.tags!,- usersLimit: plan.limits.users!,- },- });-- prisma.restrictedToken.updateMany({- where: {- projectId: workspace.id,- },- data: {- rateLimit: plan.limits.api,- },- });+ await Promise.allSettled([+ prisma.project.update({+ where: {+ stripeId,+ },+ data: {+ plan: newPlan,+ usageLimit: plan.limits.clicks!,+ linksLimit: plan.limits.links!,+ domainsLimit: plan.limits.domains!,+ aiLimit: plan.limits.ai!,+ tagsLimit: plan.limits.tags!,+ usersLimit: plan.limits.users!,+ },+ }),+ prisma.restrictedToken.updateMany({+ where: {+ projectId: workspace.id,+ },+ data: {+ rateLimit: plan.limits.api,+ },+ }),+ ]);}const subscriptionCanceled =