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.

handle case when no invoice

Kiran Ke102998b03af
diff --git a/apps/web/app/api/campaigns/webhooks/stripe/checkout-session-completed.ts b/apps/web/app/api/campaigns/webhooks/stripe/checkout-session-completed.ts
index 1f4755fac8..5c4844675a 100644
--- a/apps/web/app/api/campaigns/webhooks/stripe/checkout-session-completed.ts
+++ b/apps/web/app/api/campaigns/webhooks/stripe/checkout-session-completed.ts
@@ -37,22 +37,26 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
return;
}
- // Skip if invoice id is already processed
- const ok = await redis.set(`dub_sale_events:invoiceId:${invoiceId}`, 1, {
- ex: 60 * 60 * 24 * 7,
- nx: true,
- });
+ if (invoiceId) {
+ // Skip if invoice id is already processed
+ const ok = await redis.set(`dub_sale_events:invoiceId:${invoiceId}`, 1, {
+ ex: 60 * 60 * 24 * 7,
+ nx: true,
+ });
- if (!ok) {
- console.info(
- "[Stripe Webhook] Skipping already processed invoice.",
- invoiceId,
- );
- return;
+ if (!ok) {
+ console.info(
+ "[Stripe Webhook] Skipping already processed invoice.",
+ invoiceId,
+ );
+ return;
+ }
}
// Retrieve subscription if available
- const subscription = await retrieveSubscription(subscriptionId);
+ const subscription = subscriptionId
+ ? await retrieveSubscription(subscriptionId)
+ : null;
// Record sale
await recordSale({
@@ -61,7 +65,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
payment_processor: "stripe",
amount: charge.amount_total!,
currency: charge.currency!,
- invoice_id: invoiceId,
+ invoice_id: invoiceId || "",
recurring: subscription?.recurring || 0,
product_id: subscription?.productId || "",
recurring_interval: subscription?.recurringInterval || "",
diff --git a/packages/tinybird/endpoints/get_lead_event.pipe b/packages/tinybird/endpoints/get_lead_event.pipe
index 71518ac2a6..45e65c6947 100644
--- a/packages/tinybird/endpoints/get_lead_event.pipe
+++ b/packages/tinybird/endpoints/get_lead_event.pipe
@@ -8,6 +8,17 @@ DESCRIPTION >
undefined
SQL >
- % SELECT * FROM dub_lead_events WHERE customer_id = {{ customerId }} LIMIT 1
-
\ No newline at end of file
+%
+SELECT *
+FROM dub_lead_events
+WHERE
+ customer_id
+ = {{
+ String(
+ customerId,
+ "Otgts60IekQ17PMZ",
+ description="The unique ID for a given customer.",
+ required=True,
+ )
+ }}
\ No newline at end of file