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.

Small improvements to Stripe webhooks

Steven Teyc038277630b6
diff --git a/apps/web/app/api/stripe/integration/webhook/customer-created.ts b/apps/web/app/api/stripe/integration/webhook/customer-created.ts
index 1be941f234..91c77b381c 100644
--- a/apps/web/app/api/stripe/integration/webhook/customer-created.ts
+++ b/apps/web/app/api/stripe/integration/webhook/customer-created.ts
@@ -41,10 +41,12 @@ export async function customerCreated(event: Stripe.Event) {
// Check the customer is not already created
// Find customer using projectConnectId and externalId (the customer's ID in the client app)
- const customerFound = await prisma.customer.findFirst({
+ const customerFound = await prisma.customer.findUnique({
where: {
- projectConnectId: stripeAccountId,
- externalId,
+ projectConnectId_externalId: {
+ projectConnectId: stripeAccountId,
+ externalId,
+ },
},
});
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 289cacb692..1950ccaa0f 100644
--- a/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts
+++ b/apps/web/app/api/stripe/integration/webhook/invoice-paid.ts
@@ -12,14 +12,12 @@ import type Stripe from "stripe";
// Handle event "invoice.paid"
export async function invoicePaid(event: Stripe.Event) {
const invoice = event.data.object as Stripe.Invoice;
- const stripeAccountId = event.account as string;
const stripeCustomerId = invoice.customer as string;
const invoiceId = invoice.id;
// Find customer using projectConnectId and stripeCustomerId
- const customer = await prisma.customer.findFirst({
+ const customer = await prisma.customer.findUnique({
where: {
- projectConnectId: stripeAccountId,
stripeCustomerId,
},
});