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.

Add `stripeCustomerId` to customer creation flow

Steven Tey2f0cd3e340c6
diff --git a/apps/web/app/(ee)/api/customers/route.ts b/apps/web/app/(ee)/api/customers/route.ts
index f4fd4e3490..f8b589a5d0 100644
--- a/apps/web/app/(ee)/api/customers/route.ts
+++ b/apps/web/app/(ee)/api/customers/route.ts
@@ -140,9 +140,8 @@ export const GET = withWorkspace(
// POST /api/customers – Create a customer
export const POST = withWorkspace(
async ({ req, workspace }) => {
- const { email, name, avatar, externalId } = createCustomerBodySchema.parse(
- await parseRequestBody(req),
- );
+ const { email, name, avatar, externalId, stripeCustomerId } =
+ createCustomerBodySchema.parse(await parseRequestBody(req));
const customerId = createId({ prefix: "cus_" });
const finalCustomerName = name || email || generateRandomName();
@@ -159,6 +158,7 @@ export const POST = withWorkspace(
email,
avatar: finalCustomerAvatar,
externalId,
+ stripeCustomerId,
projectId: workspace.id,
projectConnectId: workspace.stripeConnectId,
},
diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.ts
index edc06decc6..c0203a0358 100644
--- a/apps/web/lib/zod/schemas/customers.ts
+++ b/apps/web/lib/zod/schemas/customers.ts
@@ -98,6 +98,12 @@ export const createCustomerBodySchema = z.object({
externalId: z
.string()
.describe("Unique identifier for the customer in the client's app."),
+ stripeCustomerId: z
+ .string()
+ .nullish()
+ .describe(
+ "The customer's Stripe customer ID. Useful for attribution recurring sale events to the partner who referred the customer.",
+ ),
});
export const updateCustomerBodySchema = createCustomerBodySchema.partial();
diff --git a/apps/web/ui/modals/add-customer-modal.tsx b/apps/web/ui/modals/add-customer-modal.tsx
index 07e61847a5..6a3d22f6d3 100644
--- a/apps/web/ui/modals/add-customer-modal.tsx
+++ b/apps/web/ui/modals/add-customer-modal.tsx
@@ -34,6 +34,7 @@ const AddCustomerModal = ({
name: null,
email: null,
externalId: "",
+ stripeCustomerId: null,
},
});
@@ -131,6 +132,24 @@ const AddCustomerModal = ({
})}
/>
</div>
+
+ <div>
+ <label className="text-sm font-normal text-neutral-500">
+ Stripe Customer ID
+ </label>
+ <input
+ type="text"
+ autoComplete="off"
+ className="mt-2 block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ placeholder="cus_NffrFeUfNV2Hib"
+ {...register("stripeCustomerId", {
+ setValueAs: (value) => (value === "" ? null : value),
+ })}
+ />
+ <p className="mt-2 text-xs text-neutral-500">
+ The customer's Stripe customer ID (optional)
+ </p>
+ </div>
</div>
<div className="flex items-center justify-end border-t border-neutral-200 px-4 py-4 sm:px-6">