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 webhooks

Steven Teybb3c22fde5a1
diff --git a/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.ts b/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.ts
index 0e8cab9fd6..a6d5f00a37 100644
--- a/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.ts
+++ b/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.ts
@@ -22,10 +22,6 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
return "Customer ID not found in Stripe checkout session metadata, skipping...";
}
- if (charge.amount_total === 0) {
- return `Checkout session completed for customer with external ID ${dubCustomerId} and invoice ID ${invoiceId} but amount is 0, skipping...`;
- }
-
let customer: Customer;
try {
// Update customer with stripe customerId if exists
@@ -62,6 +58,10 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
}
}
+ if (charge.amount_total === 0) {
+ return `Checkout session completed for customer with external ID ${dubCustomerId} and invoice ID ${invoiceId} but amount is 0, skipping...`;
+ }
+
// Find lead
const leadEvent = await getLeadEvent({ customerId: customer.id });
if (!leadEvent || leadEvent.data.length === 0) {
diff --git a/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts b/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts
index 8f3b12eb21..289cacb692 100644
--- a/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts
+++ b/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts
@@ -16,10 +16,6 @@ export async function invoicePaid(event: Stripe.Event) {
const stripeCustomerId = invoice.customer as string;
const invoiceId = invoice.id;
- if (invoice.amount_paid === 0) {
- return `Invoice with ID ${invoiceId} has an amount of 0, skipping...`;
- }
-
// Find customer using projectConnectId and stripeCustomerId
const customer = await prisma.customer.findFirst({
where: {
@@ -46,6 +42,10 @@ export async function invoicePaid(event: Stripe.Event) {
return `Invoice with ID ${invoiceId} already processed, skipping...`;
}
+ if (invoice.amount_paid === 0) {
+ return `Invoice with ID ${invoiceId} has an amount of 0, skipping...`;
+ }
+
// Find lead
const leadEvent = await getLeadEvent({ customerId: customer.id });
if (!leadEvent || leadEvent.data.length === 0) {