/* * 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 { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { CustomerEntity, CustomerEntity$inboundSchema, CustomerEntity$Outbound, CustomerEntity$outboundSchema, } from "./customerentity.js"; import { CustomField, CustomField$inboundSchema, CustomField$Outbound, CustomField$outboundSchema, } from "./customfield.js"; import { EnvironmentMode, EnvironmentMode$inboundSchema, EnvironmentMode$outboundSchema, } from "./environmentmode.js"; import { LicenseEntity, LicenseEntity$inboundSchema, LicenseEntity$Outbound, LicenseEntity$outboundSchema, } from "./licenseentity.js"; import { OrderEntity, OrderEntity$inboundSchema, OrderEntity$Outbound, OrderEntity$outboundSchema, } from "./orderentity.js"; import { ProductEntity, ProductEntity$inboundSchema, ProductEntity$Outbound, ProductEntity$outboundSchema, } from "./productentity.js"; import { ProductFeatureEntity, ProductFeatureEntity$inboundSchema, ProductFeatureEntity$Outbound, ProductFeatureEntity$outboundSchema, } from "./productfeatureentity.js"; import { SubscriptionEntity, SubscriptionEntity$inboundSchema, SubscriptionEntity$Outbound, SubscriptionEntity$outboundSchema, } from "./subscriptionentity.js"; /** * Status of the checkout. */ export const Status = { Pending: "pending", Processing: "processing", Completed: "completed", Expired: "expired", } as const; /** * Status of the checkout. */ export type Status = ClosedEnum; /** * The product associated with the checkout session. */ export type CheckoutEntityProduct = ProductEntity | string; /** * The subscription associated with the checkout session. */ export type Subscription = SubscriptionEntity | string; /** * The customer associated with the checkout session. */ export type CheckoutEntityCustomer = CustomerEntity | string; export type CheckoutEntity = { /** * Unique identifier for the object. */ id: string; /** * String representing the environment. */ mode: EnvironmentMode; /** * String representing the object's type. Objects of the same type share the same value. */ object: string; /** * Status of the checkout. */ status: Status; /** * Identify and track each checkout request. */ requestId?: string | undefined; /** * The product associated with the checkout session. */ product: ProductEntity | string; /** * The number of units for the of the product. */ units?: number | undefined; /** * The order associated with the checkout session. */ order?: OrderEntity | undefined; /** * The subscription associated with the checkout session. */ subscription?: SubscriptionEntity | string | undefined; /** * The customer associated with the checkout session. */ customer?: CustomerEntity | string | undefined; /** * Additional information collected from your customer during the checkout process. */ customFields?: Array | undefined; /** * The URL to which the customer will be redirected to complete the payment. */ checkoutUrl?: string | undefined; /** * The URL to which the user will be redirected after the checkout process is completed. */ successUrl?: string | null | undefined; /** * License keys issued for the order. */ licenseKeys?: Array | undefined; /** * DEPRECATED: Use `license_keys` instead. Features issued for the order. * * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. */ feature?: Array | undefined; /** * Metadata for the checkout in the form of key-value pairs */ metadata?: { [k: string]: any } | undefined; }; /** @internal */ export const Status$inboundSchema: z.ZodNativeEnum = z .nativeEnum(Status); /** @internal */ export const Status$outboundSchema: z.ZodNativeEnum = Status$inboundSchema; /** @internal */ export const CheckoutEntityProduct$inboundSchema: z.ZodType< CheckoutEntityProduct, z.ZodTypeDef, unknown > = z.union([ProductEntity$inboundSchema, z.string()]); /** @internal */ export type CheckoutEntityProduct$Outbound = ProductEntity$Outbound | string; /** @internal */ export const CheckoutEntityProduct$outboundSchema: z.ZodType< CheckoutEntityProduct$Outbound, z.ZodTypeDef, CheckoutEntityProduct > = z.union([ProductEntity$outboundSchema, z.string()]); export function checkoutEntityProductToJSON( checkoutEntityProduct: CheckoutEntityProduct, ): string { return JSON.stringify( CheckoutEntityProduct$outboundSchema.parse(checkoutEntityProduct), ); } export function checkoutEntityProductFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CheckoutEntityProduct$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CheckoutEntityProduct' from JSON`, ); } /** @internal */ export const Subscription$inboundSchema: z.ZodType< Subscription, z.ZodTypeDef, unknown > = z.union([SubscriptionEntity$inboundSchema, z.string()]); /** @internal */ export type Subscription$Outbound = SubscriptionEntity$Outbound | string; /** @internal */ export const Subscription$outboundSchema: z.ZodType< Subscription$Outbound, z.ZodTypeDef, Subscription > = z.union([SubscriptionEntity$outboundSchema, z.string()]); export function subscriptionToJSON(subscription: Subscription): string { return JSON.stringify(Subscription$outboundSchema.parse(subscription)); } export function subscriptionFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Subscription$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Subscription' from JSON`, ); } /** @internal */ export const CheckoutEntityCustomer$inboundSchema: z.ZodType< CheckoutEntityCustomer, z.ZodTypeDef, unknown > = z.union([CustomerEntity$inboundSchema, z.string()]); /** @internal */ export type CheckoutEntityCustomer$Outbound = CustomerEntity$Outbound | string; /** @internal */ export const CheckoutEntityCustomer$outboundSchema: z.ZodType< CheckoutEntityCustomer$Outbound, z.ZodTypeDef, CheckoutEntityCustomer > = z.union([CustomerEntity$outboundSchema, z.string()]); export function checkoutEntityCustomerToJSON( checkoutEntityCustomer: CheckoutEntityCustomer, ): string { return JSON.stringify( CheckoutEntityCustomer$outboundSchema.parse(checkoutEntityCustomer), ); } export function checkoutEntityCustomerFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CheckoutEntityCustomer$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CheckoutEntityCustomer' from JSON`, ); } /** @internal */ export const CheckoutEntity$inboundSchema: z.ZodType< CheckoutEntity, z.ZodTypeDef, unknown > = z.object({ id: z.string(), mode: EnvironmentMode$inboundSchema, object: z.string(), status: Status$inboundSchema, request_id: z.string().optional(), product: z.union([ProductEntity$inboundSchema, z.string()]), units: z.number().default(1), order: OrderEntity$inboundSchema.optional(), subscription: z.union([SubscriptionEntity$inboundSchema, z.string()]) .optional(), customer: z.union([CustomerEntity$inboundSchema, z.string()]).optional(), custom_fields: z.array(CustomField$inboundSchema).optional(), checkout_url: z.string().optional(), success_url: z.nullable(z.string()).optional(), license_keys: z.array(LicenseEntity$inboundSchema).optional(), feature: z.array(ProductFeatureEntity$inboundSchema).optional(), metadata: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { "request_id": "requestId", "custom_fields": "customFields", "checkout_url": "checkoutUrl", "success_url": "successUrl", "license_keys": "licenseKeys", }); }); /** @internal */ export type CheckoutEntity$Outbound = { id: string; mode: string; object: string; status: string; request_id?: string | undefined; product: ProductEntity$Outbound | string; units: number; order?: OrderEntity$Outbound | undefined; subscription?: SubscriptionEntity$Outbound | string | undefined; customer?: CustomerEntity$Outbound | string | undefined; custom_fields?: Array | undefined; checkout_url?: string | undefined; success_url?: string | null | undefined; license_keys?: Array | undefined; feature?: Array | undefined; metadata?: { [k: string]: any } | undefined; }; /** @internal */ export const CheckoutEntity$outboundSchema: z.ZodType< CheckoutEntity$Outbound, z.ZodTypeDef, CheckoutEntity > = z.object({ id: z.string(), mode: EnvironmentMode$outboundSchema, object: z.string(), status: Status$outboundSchema, requestId: z.string().optional(), product: z.union([ProductEntity$outboundSchema, z.string()]), units: z.number().default(1), order: OrderEntity$outboundSchema.optional(), subscription: z.union([SubscriptionEntity$outboundSchema, z.string()]) .optional(), customer: z.union([CustomerEntity$outboundSchema, z.string()]).optional(), customFields: z.array(CustomField$outboundSchema).optional(), checkoutUrl: z.string().optional(), successUrl: z.nullable(z.string()).optional(), licenseKeys: z.array(LicenseEntity$outboundSchema).optional(), feature: z.array(ProductFeatureEntity$outboundSchema).optional(), metadata: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { requestId: "request_id", customFields: "custom_fields", checkoutUrl: "checkout_url", successUrl: "success_url", licenseKeys: "license_keys", }); }); export function checkoutEntityToJSON(checkoutEntity: CheckoutEntity): string { return JSON.stringify(CheckoutEntity$outboundSchema.parse(checkoutEntity)); } export function checkoutEntityFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CheckoutEntity$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CheckoutEntity' from JSON`, ); }