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 guides as well

Steven Tey92f3ea1061a7
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 289f4e6566..b188d80c88 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
@@ -239,10 +239,12 @@ export async function checkoutSessionCompleted(
mode,
});
- if (connectedCustomer?.metadata.dubCustomerId) {
- dubCustomerExternalId =
- connectedCustomer.metadata.dubCustomerExternalId ||
- connectedCustomer.metadata.dubCustomerId;
+ const connectedCustomerDubCustomerExternalId =
+ connectedCustomer?.metadata.dubCustomerExternalId ||
+ connectedCustomer?.metadata.dubCustomerId;
+
+ if (connectedCustomerDubCustomerExternalId) {
+ dubCustomerExternalId = connectedCustomerDubCustomerExternalId;
customer = await updateCustomerWithStripeCustomerId({
stripeAccountId,
dubCustomerExternalId,
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts
index 4f90716634..5230ed3447 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts
@@ -18,7 +18,9 @@ import type Stripe from "stripe";
export async function createNewCustomer(event: Stripe.Event) {
const stripeCustomer = event.data.object as Stripe.Customer;
const stripeAccountId = event.account as string;
- const dubCustomerExternalId = stripeCustomer.metadata?.dubCustomerId;
+ const dubCustomerExternalId =
+ stripeCustomer.metadata?.dubCustomerExternalId ||
+ stripeCustomer.metadata?.dubCustomerId;
const clickId = stripeCustomer.metadata?.dubClickId;
// The client app should always send dubClickId (dub_id) via metadata
diff --git a/apps/web/guides/stripe-checkout.md b/apps/web/guides/stripe-checkout.md
index 3c71736c76..4ada49a5fa 100644
--- a/apps/web/guides/stripe-checkout.md
+++ b/apps/web/guides/stripe-checkout.md
@@ -6,7 +6,7 @@ Under the hood, Dub records the user as a customer and associates them with the
Then, when the user makes a purchase, Dub will automatically associate the checkout session details (invoice amount, currency, etc.) with the customer – and by extension, the original click event.
-Then, when you [create a checkout session](https://docs.stripe.com/api/checkout/sessions/create), pass your customer's unique user ID in your database as the `dubCustomerId` value in the `metadata` field.
+Then, when you [create a checkout session](https://docs.stripe.com/api/checkout/sessions/create), pass your customer's unique user ID in your database as the `dubCustomerExternalId` value in the `metadata` field.
```javascript
import { stripe } from "@/lib/stripe";
@@ -26,7 +26,7 @@ const stripeSession = await stripe.checkout.sessions.create({
mode: "subscription",
client_reference_id: user.teamId,
metadata: {
- dubCustomerId: user.id, // the unique user ID of the customer in your database
+ dubCustomerExternalId: user.id, // the unique user ID of the customer in your database
},
});
```
diff --git a/apps/web/guides/stripe-customers.md b/apps/web/guides/stripe-customers.md
index 4a0795e590..19e0d98a4f 100644
--- a/apps/web/guides/stripe-customers.md
+++ b/apps/web/guides/stripe-customers.md
@@ -1,6 +1,6 @@
Alternatively, if you don't use Stripe's checkout session creation flow, you can also pass the user ID and the click event ID (`dub_id`) in the [Stripe customer creation flow](https://docs.stripe.com/api/customers/create).
-When you [create a Stripe customer](https://docs.stripe.com/api/customers/create), pass the user's unique user ID in your database as the `dubCustomerId` value in the `metadata` field.
+When you [create a Stripe customer](https://docs.stripe.com/api/customers/create), pass the user's unique user ID in your database as the `dubCustomerExternalId` value in the `metadata` field.
```javascript
import { stripe } from "@/lib/stripe";
@@ -17,13 +17,13 @@ await stripe.customers.create({
email: user.email,
name: user.name,
metadata: {
- dubCustomerId: user.id,
+ dubCustomerExternalId: user.id,
dubClickId: dub_id,
},
});
```
-Alternatively, you can also pass the `dubCustomerId` and `dubClickId` values in the `metadata` field of the [Stripe customer update flow](https://docs.stripe.com/api/customers/update):
+Alternatively, you can also pass the `dubCustomerExternalId` and `dubClickId` values in the `metadata` field of the [Stripe customer update flow](https://docs.stripe.com/api/customers/update):
```javascript
import { stripe } from "@/lib/stripe";
@@ -38,7 +38,7 @@ const dub_id = req.headers.get("dub_id");
await stripe.customers.update(user.id, {
metadata: {
- dubCustomerId: user.id,
+ dubCustomerExternalId: user.id,
dubClickId: dub_id,
},
});