Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

update in customer.subscription.updated as well

Steven Teyd53774768e36
diff --git a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts
index 434464680b..99083b2bf1 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-updated.ts
@@ -29,6 +29,7 @@ export async function customerSubscriptionUpdated(event: Stripe.Event) {
paymentFailedAt: true,
payoutsLimit: true,
foldersUsage: true,
+ defaultProgramId: true,
users: {
select: {
user: {
diff --git a/apps/web/app/(ee)/api/stripe/webhook/utils.ts b/apps/web/app/(ee)/api/stripe/webhook/utils.ts
index 8094dc4c90..8d2f9aeb2e 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/utils.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/utils.ts
@@ -1,5 +1,6 @@
import { deleteWorkspaceFolders } from "@/lib/api/folders/delete-workspace-folders";
import { tokenCache } from "@/lib/auth/token-cache";
+import { getPlanCapabilities } from "@/lib/plan-capabilities";
import { WorkspaceProps } from "@/lib/types";
import { webhookCache } from "@/lib/webhook/cache";
import { sendEmail } from "@dub/email";
@@ -52,7 +53,11 @@ export async function updateWorkspacePlan({
}: {
workspace: Pick<
WorkspaceProps,
- "id" | "paymentFailedAt" | "payoutsLimit" | "foldersUsage"
+ | "id"
+ | "paymentFailedAt"
+ | "payoutsLimit"
+ | "foldersUsage"
+ | "defaultProgramId"
> & {
plan: string;
restrictedTokens: {
@@ -115,6 +120,23 @@ export async function updateWorkspacePlan({
({ hashedKey }) => hashedKey,
),
}),
+
+ // disable/enable program messaging if workspace has a program
+ ...(workspace.defaultProgramId
+ ? [
+ prisma.program.update({
+ where: {
+ id: workspace.defaultProgramId,
+ },
+ data: {
+ messagingEnabledAt: getPlanCapabilities(workspace.plan)
+ .canMessagePartners
+ ? new Date()
+ : null,
+ },
+ }),
+ ]
+ : []),
]);
// Disable the webhooks if the new plan does not support webhooks