import {z} from 'zod' export type CreateApiV1PaymentPagesArgs = {body: {clientReferenceId?: string | undefined, successReturnUrl?: string | undefined, failReturnUrl?: string | undefined, billingEmail?: string | undefined, location?: ({country: string, zipcode: string, state?: string | undefined, latitude?: number | undefined, longitude?: number | undefined} | {country: string, zipcode?: string | undefined, state: string, latitude?: number | undefined, longitude?: number | undefined}) | undefined, fromChannel?: string | undefined, lineItems: Array<{productId: string, quantity: number}>, settings?: ({expireInSeconds?: number | undefined, flexibleAmount?: ({maxAmount?: number | undefined, percentage?: number | undefined, fixedAmount?: number | undefined}) | undefined}) | undefined, description?: string | undefined, customer?: ({id: string} | {referenceId: string} | {referenceId: string, signupAt: number, email?: string | undefined, firstName?: string | undefined, middleName?: string | undefined, lastName?: string | undefined, dateOfBirth?: string | undefined, address?: ({line1?: string | undefined, line2?: string | undefined, city?: string | undefined, country?: string | undefined, state?: string | undefined, postalCode?: (string | string) | undefined}) | undefined, phoneNumber?: string | undefined, merchantTrustSignal?: ({playerId: string, hoursPlayed?: (number | null) | undefined, playerLevel?: (number | null) | undefined, trustStatus?: ('GOOD' | 'BAD' | 'null' | null) | undefined}) | undefined}) | undefined} | {clientReferenceId?: string | undefined, successReturnUrl?: string | undefined, failReturnUrl?: string | undefined, billingEmail?: string | undefined, location?: ({country: string, zipcode: string, state?: string | undefined, latitude?: number | undefined, longitude?: number | undefined} | {country: string, zipcode?: string | undefined, state: string, latitude?: number | undefined, longitude?: number | undefined}) | undefined, fromChannel?: string | undefined, lineItems: Array<{quantity: number, clientProductId: string, displayName: string, description?: string | undefined, image?: string | undefined, amount: number, currency: 'USD' | 'AUD' | 'CAD' | 'CHF' | 'DKK' | 'EUR' | 'GBP' | 'NOK' | 'NZD' | 'PLN' | 'SEK' | 'SGD'}>, settings?: ({expireInSeconds?: number | undefined, flexibleAmount?: ({maxAmount?: number | undefined, percentage?: number | undefined, fixedAmount?: number | undefined}) | undefined}) | undefined, description?: string | undefined, customer?: ({id: string} | {referenceId: string} | {referenceId: string, signupAt: number, email?: string | undefined, firstName?: string | undefined, middleName?: string | undefined, lastName?: string | undefined, dateOfBirth?: string | undefined, address?: ({line1?: string | undefined, line2?: string | undefined, city?: string | undefined, country?: string | undefined, state?: string | undefined, postalCode?: (string | string) | undefined}) | undefined, phoneNumber?: string | undefined, merchantTrustSignal?: ({playerId: string, hoursPlayed?: (number | null) | undefined, playerLevel?: (number | null) | undefined, trustStatus?: ('GOOD' | 'BAD' | 'null' | null) | undefined}) | undefined}) | undefined}}; export type CreateApiV1PaymentPagesOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createPaymentPageResponse = z.object({id: z.string(), merchant: z.object({merchantId: z.string(), name: z.string(), wallet: z.object({evmAddress: z.string(), solanaAddress: z.string()}).optional(), livemode: z.boolean(), regionCode: z.enum(["US", "CA", "EU"]).optional(), checkoutSettings: z.object({processingChannelIdLivemode: z.enum(["pc_jlkqbuuu2svulf7jkiyw5m6w44", "pc_cjd2au72ozrelgqc2oi4pjpaoi", "pc_jplm2l7q77eunak5ngtyb7yqt4", "pc_nddjkfedyxienabgww2d7yqkwa"]).optional(), processingChannelIdTestmode: z.string()}).optional(), isGiftCardPayinEffective: z.boolean().optional()}), currency: z.enum(["USD", "AUD", "CAD", "CHF", "DKK", "EUR", "GBP", "HKD", "JPY", "NOK", "NZD", "PLN", "SEK", "SGD", "TWD", "KRW", "SOL", "USDC", "USDT", "HONEY", "EURC"]), amount: z.number(), source: z.enum(["direct", "iap", "subscription", "card-verification", "consumer-onramp"]), lineItems: z.array(z.object({productId: z.string().optional(), name: z.string(), currency: z.enum(["USD", "AUD", "CAD", "CHF", "DKK", "EUR", "GBP", "HKD", "JPY", "NOK", "NZD", "PLN", "SEK", "SGD", "TWD", "KRW", "SOL", "USDC", "USDT", "HONEY", "EURC"]), amount: z.number(), price: z.number(), quantity: z.number(), description: z.string().optional(), images: z.array(z.string()).optional()})).optional(), clientReferenceId: z.string().optional(), successReturnUrl: z.string().optional(), failReturnUrl: z.string().optional(), fromChannel: z.string().optional(), createdAt: z.number(), url: z.string(), clientSecret: z.string(), status: z.enum(["UNPAID", "PAID", "EXPIRED", "CANCELED"]), isRecurring: z.boolean(), billingEmail: z.string().optional(), location: z.object({country: z.string(), zipcode: z.string().optional(), state: z.string().optional(), latitude: z.number().optional(), longitude: z.number().optional()}).optional(), description: z.string().optional(), expireAtSeconds: z.number().optional(), disputeId: z.string().optional(), disputeStatus: z.enum(["new", "actionRequired", "ongoing", "partialWon", "won", "lost", "resolved", "canceled", "manuallyCanceled"]).optional(), displayStatus: z.enum(["UNPAID", "SUCCESSFUL", "REFUNDING", "REFUNDED", "DISPUTED", "EXPIRED", "CANCELED"]).optional(), customer: z.object({id: z.string(), referenceId: z.string(), email: z.string().optional()}).optional(), integrationType: z.enum(["HOSTED", "SERVER_TO_SERVER"]).optional(), threeDsMode: z.enum(["MERCHANT_PROVIDED", "BREEZE_HOSTED"]).optional()}); export const createApiV1PaymentPagesResponse = z.object({status: z.literal("SUCCEEDED"), data: createPaymentPageResponse}); 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 }; /** * Create a payment page * * POST /v1/payment_pages */ export const createApiV1PaymentPages = async (args: CreateApiV1PaymentPagesArgs, options?: CreateApiV1PaymentPagesOptions) => { const {baseUrl = "https://api.breeze.cash", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/payment_pages${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(createApiV1PaymentPagesResponse, await res.json()) };