/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { CustomerRequestEntity, CustomerRequestEntity$inboundSchema, CustomerRequestEntity$Outbound, CustomerRequestEntity$outboundSchema, } from "./customerrequestentity.js"; import { CustomFieldRequestEntity, CustomFieldRequestEntity$inboundSchema, CustomFieldRequestEntity$Outbound, CustomFieldRequestEntity$outboundSchema, } from "./customfieldrequestentity.js"; export type CreateCheckoutRequest = { /** * Identify and track each checkout request. */ requestId?: string | undefined; /** * The ID of the product associated with the checkout session. */ productId: string; /** * The number of units for the order. */ units?: number | undefined; /** * Prefill the checkout session with a discount code. */ discountCode?: string | undefined; /** * Customer data for checkout session. This will prefill the customer info on the checkout page. */ customer?: CustomerRequestEntity | undefined; /** * Collect additional information from your customer using custom fields. Up to 3 fields are supported. */ customFields?: Array | undefined; /** * DEPRECATED: Use `custom_fields` instead. Collect additional information from your customer using custom fields. Up to 3 fields are supported. * * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. */ customField?: Array | undefined; /** * The URL to which the user will be redirected after the checkout process is completed. */ successUrl?: string | undefined; /** * Metadata for the checkout in the form of key-value pairs */ metadata?: { [k: string]: any } | undefined; }; /** @internal */ export const CreateCheckoutRequest$inboundSchema: z.ZodType< CreateCheckoutRequest, z.ZodTypeDef, unknown > = z.object({ request_id: z.string().optional(), product_id: z.string(), units: z.number().optional(), discount_code: z.string().optional(), customer: CustomerRequestEntity$inboundSchema.optional(), custom_fields: z.array(CustomFieldRequestEntity$inboundSchema).optional(), custom_field: z.array(CustomFieldRequestEntity$inboundSchema).optional(), success_url: z.string().optional(), metadata: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { "request_id": "requestId", "product_id": "productId", "discount_code": "discountCode", "custom_fields": "customFields", "custom_field": "customField", "success_url": "successUrl", }); }); /** @internal */ export type CreateCheckoutRequest$Outbound = { request_id?: string | undefined; product_id: string; units?: number | undefined; discount_code?: string | undefined; customer?: CustomerRequestEntity$Outbound | undefined; custom_fields?: Array | undefined; custom_field?: Array | undefined; success_url?: string | undefined; metadata?: { [k: string]: any } | undefined; }; /** @internal */ export const CreateCheckoutRequest$outboundSchema: z.ZodType< CreateCheckoutRequest$Outbound, z.ZodTypeDef, CreateCheckoutRequest > = z.object({ requestId: z.string().optional(), productId: z.string(), units: z.number().optional(), discountCode: z.string().optional(), customer: CustomerRequestEntity$outboundSchema.optional(), customFields: z.array(CustomFieldRequestEntity$outboundSchema).optional(), customField: z.array(CustomFieldRequestEntity$outboundSchema).optional(), successUrl: z.string().optional(), metadata: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { requestId: "request_id", productId: "product_id", discountCode: "discount_code", customFields: "custom_fields", customField: "custom_field", successUrl: "success_url", }); }); export function createCheckoutRequestToJSON( createCheckoutRequest: CreateCheckoutRequest, ): string { return JSON.stringify( CreateCheckoutRequest$outboundSchema.parse(createCheckoutRequest), ); } export function createCheckoutRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateCheckoutRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateCheckoutRequest' from JSON`, ); }