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 `customer.created/updated` webhooks, add more requiredRoles (#3360)

Steven Tey4fdfe7c14dc1
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/[submissionId]/approve/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/[submissionId]/approve/route.ts
index 19c6953127..5d0d82cb8a 100644
--- a/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/[submissionId]/approve/route.ts
+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/[submissionId]/approve/route.ts
@@ -39,5 +39,6 @@ export const POST = withWorkspace(
},
{
requiredPlan: ["advanced", "enterprise"],
+ requiredRoles: ["owner", "member"],
},
);
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/[submissionId]/reject/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/[submissionId]/reject/route.ts
index 095573f0a2..2111ea9bd1 100644
--- a/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/[submissionId]/reject/route.ts
+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/[submissionId]/reject/route.ts
@@ -41,5 +41,6 @@ export const POST = withWorkspace(
},
{
requiredPlan: ["advanced", "enterprise"],
+ requiredRoles: ["owner", "member"],
},
);
diff --git a/apps/web/app/(ee)/api/campaigns/[campaignId]/route.ts b/apps/web/app/(ee)/api/campaigns/[campaignId]/route.ts
index a09f879cdf..66b82b6109 100644
--- a/apps/web/app/(ee)/api/campaigns/[campaignId]/route.ts
+++ b/apps/web/app/(ee)/api/campaigns/[campaignId]/route.ts
@@ -44,6 +44,7 @@ export const GET = withWorkspace(
},
{
requiredPlan: ["advanced", "enterprise"],
+ requiredRoles: ["owner", "member"],
},
);
@@ -171,6 +172,7 @@ export const PATCH = withWorkspace(
},
{
requiredPlan: ["advanced", "enterprise"],
+ requiredRoles: ["owner", "member"],
},
);
@@ -222,5 +224,6 @@ export const DELETE = withWorkspace(
},
{
requiredPlan: ["advanced", "enterprise"],
+ requiredRoles: ["owner", "member"],
},
);
diff --git a/apps/web/app/(ee)/api/stripe/integration/route.ts b/apps/web/app/(ee)/api/stripe/integration/route.ts
index d593d15e14..e2b5716e89 100644
--- a/apps/web/app/(ee)/api/stripe/integration/route.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/route.ts
@@ -124,6 +124,7 @@ export const PATCH = withWorkspace(
"advanced",
"enterprise",
],
+ requiredRoles: ["owner", "member"],
},
);
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/customer-created.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/customer-created.ts
index 3284249a89..70e4b7105b 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/customer-created.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/customer-created.ts
@@ -14,14 +14,31 @@ export async function customerCreated(event: Stripe.Event) {
return "External ID not found in Stripe customer metadata, skipping...";
}
+ const workspace = await prisma.project.findUnique({
+ where: {
+ stripeConnectId: stripeAccountId,
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ if (!workspace) {
+ return "Workspace not found, skipping...";
+ }
+
// Check the customer is not already created
- // Find customer using projectConnectId and externalId (the customer's ID in the client app)
- const customer = await prisma.customer.findUnique({
+ const customer = await prisma.customer.findFirst({
where: {
- projectConnectId_externalId: {
- projectConnectId: stripeAccountId,
- externalId: dubCustomerExternalId,
- },
+ OR: [
+ {
+ projectId: workspace.id,
+ externalId: dubCustomerExternalId,
+ },
+ {
+ stripeCustomerId: stripeCustomer.id,
+ },
+ ],
},
});
@@ -34,7 +51,9 @@ export async function customerCreated(event: Stripe.Event) {
id: customer.id,
},
data: {
+ externalId: dubCustomerExternalId,
stripeCustomerId: stripeCustomer.id,
+ projectConnectId: stripeAccountId,
},
});
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/customer-updated.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/customer-updated.ts
index 6ad81c4a4b..7571b1cea3 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/customer-updated.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/customer-updated.ts
@@ -14,11 +14,24 @@ export async function customerUpdated(event: Stripe.Event) {
return "External ID not found in Stripe customer metadata, skipping...";
}
+ const workspace = await prisma.project.findUnique({
+ where: {
+ stripeConnectId: stripeAccountId,
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ if (!workspace) {
+ return "Workspace not found, skipping...";
+ }
+
const customer = await prisma.customer.findFirst({
where: {
OR: [
{
- projectConnectId: stripeAccountId,
+ projectId: workspace.id,
externalId: dubCustomerExternalId,
},
{
@@ -35,10 +48,11 @@ export async function customerUpdated(event: Stripe.Event) {
id: customer.id,
},
data: {
- externalId: dubCustomerExternalId,
- stripeCustomerId: stripeCustomer.id,
name: stripeCustomer.name,
email: stripeCustomer.email,
+ externalId: dubCustomerExternalId,
+ stripeCustomerId: stripeCustomer.id,
+ projectConnectId: stripeAccountId,
},
});