diff --git a/README.md b/README.md index acd1e12..357bd2a 100644 --- a/README.md +++ b/README.md @@ -419,6 +419,7 @@ Props: - `className`: (Optional) CSS class name - `subscriptionId`: (Optional) ID of a subscription to upgrade. It must be on a free pricing. +- `metadata`: (Optional) Metadata for additional information to the checkout #### CustomerPortalLink diff --git a/src/client/index.ts b/src/client/index.ts index ab82f7d..30b1943 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -105,6 +105,7 @@ export class Polar< origin, successUrl, subscriptionId, + metadata, }: { productIds: string[]; userId: string; @@ -112,6 +113,7 @@ export class Polar< origin: string; successUrl: string; subscriptionId?: string; + metadata?: Record; }, ): Promise { const dbCustomer = await ctx.runQuery( @@ -146,6 +148,7 @@ export class Polar< subscriptionId, embedOrigin: origin, successUrl, + metadata, ...(productIds.length === 1 ? { products: productIds } : { products: productIds }), @@ -309,6 +312,7 @@ export class Polar< origin: v.string(), successUrl: v.string(), subscriptionId: v.optional(v.string()), + metadata: v.optional(v.record(v.string(), v.string())), }, returns: v.object({ url: v.string(), @@ -322,6 +326,7 @@ export class Polar< subscriptionId: args.subscriptionId, origin: args.origin, successUrl: args.successUrl, + metadata: args.metadata, }); return { url }; }, diff --git a/src/react/index.tsx b/src/react/index.tsx index c5c68bd..252536b 100644 --- a/src/react/index.tsx +++ b/src/react/index.tsx @@ -40,12 +40,14 @@ export const CheckoutLink = ({ children, className, subscriptionId, + metadata, theme = "dark", embed = true, }: PropsWithChildren<{ polarApi: Pick; productIds: string[]; subscriptionId?: string; + metadata?: Record; className?: string; theme?: "dark" | "light"; embed?: boolean; @@ -60,10 +62,11 @@ export const CheckoutLink = ({ void generateCheckoutLink({ productIds, subscriptionId, + metadata, origin: window.location.origin, successUrl: window.location.href, }).then(({ url }) => setCheckoutLink(url)); - }, [productIds, subscriptionId, embed, generateCheckoutLink]); + }, [productIds, subscriptionId, metadata, embed, generateCheckoutLink]); return (