generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4fae3b
commit 5298209
Showing
13 changed files
with
665 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { createWebhookHandler } from "../handler-factory"; | ||
import { updateClerkMetadata } from "@/lib/services/clerk"; | ||
import { trackLoopsEvent } from "@/lib/services/loops"; | ||
import Stripe from "stripe"; | ||
|
||
export const handleInvoicePaymentFailed = createWebhookHandler( | ||
async (event) => { | ||
const invoice = event.data.object as Stripe.Invoice; | ||
const userId = invoice.metadata?.userId; | ||
|
||
if (!userId) { | ||
console.warn("No userId found in invoice metadata"); | ||
return { success: true, message: "Skipped invoice without userId" }; | ||
} | ||
|
||
await updateClerkMetadata({ | ||
userId, | ||
customerId: invoice.customer?.toString() || "", | ||
status: "payment_failed", | ||
paymentStatus: invoice.status, | ||
product: "subscription", | ||
plan: "none", | ||
lastPayment: new Date(), | ||
}); | ||
|
||
if (invoice.customer_email) { | ||
await trackLoopsEvent({ | ||
email: invoice.customer_email, | ||
userId, | ||
eventName: "invoice_payment_failed", | ||
data: { | ||
amount: invoice.amount_due, | ||
status: invoice.status, | ||
}, | ||
}); | ||
} | ||
|
||
return { | ||
success: true, | ||
message: `Successfully processed failed payment for ${userId}`, | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.