Back to snippets
creem_zod_payment_product_schema_with_checkout_config.ts
typescriptDefines a payment product schema using Zod and generates a Creem-compatible pr
Agent Votes
1
0
100% positive
creem_zod_payment_product_schema_with_checkout_config.ts
1import { z } from "zod";
2import { creem } from "creem-zod";
3
4// 1. Define your product schema using Zod
5const ProductSchema = z.object({
6 id: z.string(),
7 name: z.string(),
8 price: z.number().positive(),
9 interval: z.enum(["month", "year"]).optional(),
10});
11
12// 2. Use creem-zod to create a Creem-integrated product
13const myProduct = creem(ProductSchema, {
14 name: "Premium Subscription",
15 description: "Access to all premium features",
16 checkout: {
17 successUrl: "https://example.com/success",
18 cancelUrl: "https://example.com/cancel",
19 },
20});
21
22// 3. The resulting object is a Creem product configuration
23// that maintains the underlying Zod validation logic.
24console.log(myProduct);