import {z} from 'zod' export type SessionId = string; export type CheckoutSessionReviewRequest = {clientContext?: string | undefined, data: {sessionId: SessionId, code: string}}; export type CreateApiV1CheckoutSessionsReviewArgs = {body: CheckoutSessionReviewRequest}; export type CreateApiV1CheckoutSessionsReviewOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const countryCode = z.enum(["AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "CV", "KH", "CM", "CA", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "SZ", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MK", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "SS", "ES", "LK", "SD", "SR", "SJ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW"]); export const contactPhone = z.object({countryCode: z.string().max(4), phoneNumber: z.string().max(10)}); export const consumer = z.object({firstName: z.string().max(50).optional(), lastName: z.string().max(50).optional(), fullName: z.string().max(100), countryCode: countryCode.optional(), languageCode: z.string().optional(), emailAddress: z.string().max(128), mobileNumber: contactPhone.optional()}); export const digitalCardData = z.object({artUri: z.string().max(1024), artHeight: z.number(), artWidth: z.number()}); export const billingAddress = z.object({name: z.string().max(100).optional(), line1: z.string().max(50), line2: z.string().max(50).optional(), line3: z.string().max(50).optional(), city: z.string().max(128), state: z.string().max(2), zip: z.string().max(10), countryCode: countryCode}); export const cardNetworkResponse = z.enum(["VISA", "MASTERCARD", "DISCOVER"]).max(32); export const payOutSupported = z.enum(["YES", "NO", "UNKNOWN"]).max(32); export const maskedCard = z.object({panLastFour: z.string().max(4), paymentAccountReference: z.string().max(29), paymentCardDescriptor: z.string().max(32), panExpirationMonth: z.string().max(2).optional(), panExpirationYear: z.string().max(4).optional(), digitalCardData: digitalCardData, billingAddress: billingAddress, paymentCardType: z.enum(["CREDIT", "DEBIT"]).max(32), paymentCardBrand: cardNetworkResponse, paymentCardNetwork: cardNetworkResponse, payoutSupported: payOutSupported.optional()}); export const contactDetails = z.object({contactFullName: z.string().max(100).optional(), contactPhoneNumber: contactPhone.optional()}); export const shippingAddress = z.object({name: z.string().max(100).optional(), line1: z.string().max(50), line2: z.string().max(50).optional(), line3: z.string().max(50).optional(), city: z.string().max(128), state: z.string().max(2), zip: z.string().max(10), countryCode: countryCode, deliveryContactDetails: contactDetails.optional()}); export const links = z.object({action: z.string().optional(), link: z.string().optional()}); export const checkoutSessionReviewResponse = z.object({clientContext: z.string().max(64).optional(), ewSID: z.string().max(36), timestampISO8601: z.string().max(24), data: z.object({consumer: consumer, maskedCard: maskedCard, shippingAddress: shippingAddress.optional(), links: links, code: z.string().max(10000)})}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Review Session * * POST /v1/checkout/sessions/review */ export const createApiV1CheckoutSessionsReview = async (args: CreateApiV1CheckoutSessionsReviewArgs, options?: CreateApiV1CheckoutSessionsReviewOptions) => { const {baseUrl = "https://api.paze.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/checkout/sessions/review${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(checkoutSessionReviewResponse, await res.json()) };