/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v4-mini"; import { remap as remap$ } from "../../lib/primitives.js"; import { smartUnion } from "../../types/smartUnion.js"; import { DiscountDuration, DiscountDuration$outboundSchema, } from "./discountduration.js"; export type DiscountPercentageCreateMetadata = | string | number | number | boolean; /** * Schema to create a percentage discount. */ export type DiscountPercentageCreate = { /** * Key-value object allowing you to store additional information. * * @remarks * * The key must be a string with a maximum length of **40 characters**. * The value must be either: * * * A string with a maximum length of **500 characters** * * An integer * * A floating-point number * * A boolean * * You can store up to **50 key-value pairs**. */ metadata?: { [k: string]: string | number | number | boolean } | undefined; /** * Name of the discount. Will be displayed to the customer when the discount is applied. */ name: string; /** * Code customers can use to apply the discount during checkout. Must be between 3 and 256 characters long and contain only alphanumeric characters.If not provided, the discount can only be applied via the API. */ code?: string | null | undefined; /** * Optional timestamp after which the discount is redeemable. */ startsAt?: Date | null | undefined; /** * Optional timestamp after which the discount is no longer redeemable. */ endsAt?: Date | null | undefined; /** * Optional maximum number of times the discount can be redeemed. */ maxRedemptions?: number | null | undefined; products?: Array | null | undefined; /** * The ID of the organization owning the discount. **Required unless you use an organization token.** */ organizationId?: string | null | undefined; type: "percentage"; duration: DiscountDuration; /** * Number of months the discount should be applied. * * @remarks * * Required when `duration` is `repeating`. Must be omitted otherwise. * * For this to work on yearly pricing, you should multiply this by 12. * For example, to apply the discount for 2 years, set this to 24. */ durationInMonths?: number | null | undefined; /** * Discount percentage in basis points. * * @remarks * * A basis point is 1/100th of a percent. * For example, to create a 25.5% discount, set this to 2550. */ basisPoints: number; }; /** @internal */ export type DiscountPercentageCreateMetadata$Outbound = | string | number | number | boolean; /** @internal */ export const DiscountPercentageCreateMetadata$outboundSchema: z.ZodMiniType< DiscountPercentageCreateMetadata$Outbound, DiscountPercentageCreateMetadata > = smartUnion([z.string(), z.int(), z.number(), z.boolean()]); export function discountPercentageCreateMetadataToJSON( discountPercentageCreateMetadata: DiscountPercentageCreateMetadata, ): string { return JSON.stringify( DiscountPercentageCreateMetadata$outboundSchema.parse( discountPercentageCreateMetadata, ), ); } /** @internal */ export type DiscountPercentageCreate$Outbound = { metadata?: { [k: string]: string | number | number | boolean } | undefined; name: string; code?: string | null | undefined; starts_at?: string | null | undefined; ends_at?: string | null | undefined; max_redemptions?: number | null | undefined; products?: Array | null | undefined; organization_id?: string | null | undefined; type: "percentage"; duration: string; duration_in_months?: number | null | undefined; basis_points: number; }; /** @internal */ export const DiscountPercentageCreate$outboundSchema: z.ZodMiniType< DiscountPercentageCreate$Outbound, DiscountPercentageCreate > = z.pipe( z.object({ metadata: z.optional( z.record( z.string(), smartUnion([z.string(), z.int(), z.number(), z.boolean()]), ), ), name: z.string(), code: z.optional(z.nullable(z.string())), startsAt: z.optional( z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))), ), endsAt: z.optional( z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))), ), maxRedemptions: z.optional(z.nullable(z.int())), products: z.optional(z.nullable(z.array(z.string()))), organizationId: z.optional(z.nullable(z.string())), type: z.literal("percentage"), duration: DiscountDuration$outboundSchema, durationInMonths: z.optional(z.nullable(z.int())), basisPoints: z.int(), }), z.transform((v) => { return remap$(v, { startsAt: "starts_at", endsAt: "ends_at", maxRedemptions: "max_redemptions", organizationId: "organization_id", durationInMonths: "duration_in_months", basisPoints: "basis_points", }); }), ); export function discountPercentageCreateToJSON( discountPercentageCreate: DiscountPercentageCreate, ): string { return JSON.stringify( DiscountPercentageCreate$outboundSchema.parse(discountPercentageCreate), ); }