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.

improve one-time payment support

Steven Teyb14de0e619f8
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 75d23e51db..8413f5f445 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
@@ -153,7 +153,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
leadEvent = {
...rest,
event_id: nanoid(16),
- event_name: "Checkout session completed",
+ event_name: "Sign up",
customer_id: customer.id,
metadata: "",
};
@@ -174,6 +174,10 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
return `Checkout session completed for Stripe customer ${stripeCustomerId} with invoice ID ${invoiceId} but amount is 0, skipping...`;
}
+ if (charge.mode === "setup") {
+ return `Checkout session completed for Stripe customer ${stripeCustomerId} but mode is setup, skipping...`;
+ }
+
if (invoiceId) {
// Skip if invoice id is already processed
const ok = await redis.set(`dub_sale_events:invoiceId:${invoiceId}`, 1, {
@@ -201,7 +205,9 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
const saleData = {
...leadEvent,
event_id: eventId,
- event_name: "Subscription creation",
+ // if the charge is a one-time payment, we set the event name to "Purchase"
+ event_name:
+ charge.mode === "payment" ? "Purchase" : "Subscription creation",
payment_processor: "stripe",
amount: charge.amount_total!,
currency: charge.currency!,
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 ba73d6c274..4484d56ac7 100644
--- a/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts
+++ b/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts
@@ -57,7 +57,8 @@ export async function invoicePaid(event: Stripe.Event) {
const saleData = {
...leadEvent.data[0],
event_id: eventId,
- event_name: "Invoice paid",
+ // if the invoice has no subscription, it's a one-time payment
+ event_name: !invoice.subscription ? "Purchase" : "Invoice paid",
payment_processor: "stripe",
amount: invoice.amount_paid,
currency: invoice.currency,