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.

Fix datetimeFieldsUpdated logic in updateWorkspacePlan (#4002)

Steven Tey06a981e8e78b
diff --git a/apps/web/app/(ee)/api/stripe/webhook/utils/update-workspace-plan.ts b/apps/web/app/(ee)/api/stripe/webhook/utils/update-workspace-plan.ts
index 5c08d23c74..80a6d016b9 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/utils/update-workspace-plan.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/utils/update-workspace-plan.ts
@@ -76,11 +76,13 @@ export async function updateWorkspacePlan({
const cancellationFields = getSubscriptionCancellationFields(subscription);
const planPeriod = getPlanPeriodFromStripeSubscription(subscription);
- const billingOrCancellationChanged =
+ const datetimeFieldsUpdated =
workspace.billingCycleEndsAt?.getTime() !==
cancellationFields.billingCycleEndsAt?.getTime() ||
workspace.subscriptionCanceledAt?.getTime() !==
- cancellationFields.subscriptionCanceledAt?.getTime();
+ cancellationFields.subscriptionCanceledAt?.getTime() ||
+ (trialEndsAt !== undefined &&
+ workspace.trialEndsAt?.getTime() !== trialEndsAt?.getTime());
// Update workspace plan / limits / subscription details if:
// - workspace upgrades/downgrades their subscription
@@ -312,15 +314,20 @@ export async function updateWorkspacePlan({
`Sent thank you emails to ${workspaceOwners.length} workspace owners for workspace ${workspace.slug}.`,
);
}
- } else if (billingOrCancellationChanged) {
+ } else if (datetimeFieldsUpdated) {
await prisma.project.update({
where: {
id: workspace.id,
},
- data: cancellationFields,
+ data: {
+ ...cancellationFields,
+ ...(trialEndsAt !== undefined && { trialEndsAt }),
+ },
});
+ console.log(`Updated workspace ${workspace.id} datetime fields`);
+ } else {
console.log(
- `Updated workspace ${workspace.id} billing cycle / cancellation fields.`,
+ `No plan or datetime field updates for workspace ${workspace.id}, skipping...`,
);
}
}