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.

Find customer by workspace ID when linking a Stripe customer ID

Rafifb1f6e9ab863
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts
index db03c2187d..613e5d5d4f 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts
@@ -196,7 +196,7 @@ export async function checkoutSessionCompleted({
*/
if (dubCustomerExternalId) {
customer = await updateCustomerWithStripeCustomerId({
- stripeAccountId,
+ workspaceId: workspace.id,
dubCustomerExternalId,
stripeCustomerId,
});
@@ -263,7 +263,7 @@ export async function checkoutSessionCompleted({
if (connectedCustomerDubCustomerExternalId) {
dubCustomerExternalId = connectedCustomerDubCustomerExternalId;
customer = await updateCustomerWithStripeCustomerId({
- stripeAccountId,
+ workspaceId: workspace.id,
dubCustomerExternalId,
stripeCustomerId,
});
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/utils/update-customer-with-stripe-customer-id.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/utils/update-customer-with-stripe-customer-id.ts
index 06f63e8b46..7cf02adfcd 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/utils/update-customer-with-stripe-customer-id.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/utils/update-customer-with-stripe-customer-id.ts
@@ -1,26 +1,27 @@
import { prisma } from "@/lib/prisma";
export async function updateCustomerWithStripeCustomerId({
- stripeAccountId,
+ workspaceId,
dubCustomerExternalId,
stripeCustomerId,
}: {
- stripeAccountId?: string | null;
+ workspaceId: string;
dubCustomerExternalId: string;
stripeCustomerId?: string | null;
}) {
- // if stripeCustomerId or stripeAccountId is not provided, return null
- // (same logic as in getConnectedCustomer)
- if (!stripeCustomerId || !stripeAccountId) {
+ // if stripeCustomerId is not provided, return null
+ if (!stripeCustomerId) {
return null;
}
try {
// Update customer with stripeCustomerId if exists – for future events
+ // Match on projectId, not projectConnectId. projectConnectId is null for
+ // customers that were created before the workspace connected Stripe.
return await prisma.customer.update({
where: {
- projectConnectId_externalId: {
- projectConnectId: stripeAccountId,
+ projectId_externalId: {
+ projectId: workspaceId,
externalId: dubCustomerExternalId,
},
},