From d07c8ccd1c2b9619dcead8924cc300bca0f3b28a Mon Sep 17 00:00:00 2001 From: d-stoll Date: Mon, 19 Jan 2026 20:21:56 +0100 Subject: [PATCH 1/2] feat: add user and org extraction from invoice metadata - Updated processEvent to include invoice metadata. - Extend handleInvoiceCreated to validate optional metadata fields (orgId, userId). --- src/client/index.ts | 1 + src/component/private.ts | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client/index.ts b/src/client/index.ts index b60bdfb..c317f8b 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -570,6 +570,7 @@ async function processEvent( amountDue: invoice.amount_due, amountPaid: invoice.amount_paid, created: invoice.created, + metadata: invoice.metadata || {}, }); break; } diff --git a/src/component/private.ts b/src/component/private.ts index e95926f..671b6d5 100644 --- a/src/component/private.ts +++ b/src/component/private.ts @@ -280,6 +280,7 @@ export const handleInvoiceCreated = mutation({ amountDue: v.number(), amountPaid: v.number(), created: v.number(), + metadata: v.optional(v.any()), }, returns: v.null(), handler: async (ctx, args) => { @@ -292,10 +293,10 @@ export const handleInvoiceCreated = mutation({ if (!existing) { // Look up orgId/userId from the subscription if available - let orgId: string | undefined; - let userId: string | undefined; + let orgId: string | undefined = args.metadata?.orgId as string | undefined; + let userId: string | undefined = args.metadata?.userId as string | undefined; - if (args.stripeSubscriptionId) { + if ((!orgId || !userId) && args.stripeSubscriptionId) { const subscription = await ctx.db .query("subscriptions") .withIndex("by_stripe_subscription_id", (q) => From 2f9a8f600d303aef3c1e9a431f0eb35b6beabf84 Mon Sep 17 00:00:00 2001 From: d-stoll Date: Sat, 24 Jan 2026 09:58:27 +0100 Subject: [PATCH 2/2] feat: add invoice creation support to StripeSubscriptions - Introduced invoiceCreation option to enable invoice generation for payments. - Added invoiceMetadata for attaching additional data to invoices. - Updated session parameters to handle invoice creation and metadata. --- src/client/index.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/client/index.ts b/src/client/index.ts index c317f8b..d41564c 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -166,6 +166,10 @@ export class StripeSubscriptions { subscriptionMetadata?: Record; /** Metadata to attach to the payment intent (only for mode: "payment") */ paymentIntentMetadata?: Record; + /** Whether to create an invoice for the payment (only for mode: "payment") */ + invoiceCreation?: boolean; + /** Metadata to attach to the invoice (only for mode: "payment" and invoiceCreation: true) */ + invoiceMetadata?: Record; }, ) { const stripe = new StripeSDK(this.apiKey); @@ -201,6 +205,19 @@ export class StripeSubscriptions { }; } + // Add invoice creation metadata for linking userId/orgId + if (args.mode === "payment" && args.invoiceCreation) { + sessionParams.invoice_creation = { + enabled: true, + }; + + if (args.invoiceMetadata) { + sessionParams.invoice_data = { + metadata: args.invoiceMetadata, + }; + } + } + const session = await stripe.checkout.sessions.create(sessionParams); return {