import {z} from 'zod' export type QPilotCoreModelsPaymentMethodType = 'Stripe' | 'AuthorizeNet' | 'Test' | 'PayPal' | 'Braintree' | 'CyberSource' | 'Undefined' | 'Other' | 'Nmi' | 'PayaV1' | 'TrustCommerce' | 'Square' | 'Sage' | 'CyberSourceV2' | 'Checkout' | 'PaypalV2' | 'Shopify' | 'PayPalV3' | 'Airwallex'; export type GetApiSitesSiteIdPaymentMethodsArgs = {siteId: number, customerId?: string | undefined, paymentMethodType?: QPilotCoreModelsPaymentMethodType | undefined, page?: number | undefined, pageSize?: number | undefined, orderBy?: string | undefined, order?: string | undefined}; export type GetApiSitesSiteIdPaymentMethodsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const qPilotCoreModelsPaymentMethodType = z.enum(["Stripe", "AuthorizeNet", "Test", "PayPal", "Braintree", "CyberSource", "Undefined", "Other", "Nmi", "PayaV1", "TrustCommerce", "Square", "Sage", "CyberSourceV2", "Checkout", "PaypalV2", "Shopify", "PayPalV3", "Airwallex"]); export const qPilotCoreModelsGatewayPaymentType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11), z.literal(12), z.literal(13), z.literal(14), z.literal(15), z.literal(16), z.literal(17), z.literal(18), z.literal(19), z.literal(20), z.literal(21), z.literal(22), z.literal(23), z.literal(24), z.literal(25), z.literal(26), z.literal(27), z.literal(28), z.literal(29), z.literal(30), z.literal(31), z.literal(32)]); export const qPilotCoreModelsDtoRequestsUpsertPaymentMethodDto = z.object({customerId: z.string().min(1), type: qPilotCoreModelsPaymentMethodType.optional(), gatewayCustomerId: z.string().nullable().optional(), gatewayPaymentId: z.string().nullable().optional(), description: z.string().min(1), expiration: z.string().max(4).nullable().optional(), lastFourDigits: z.string().nullable().optional(), billingFirstName: z.string().nullable().optional(), billingLastName: z.string().nullable().optional(), billingStreet1: z.string().nullable().optional(), billingStreet2: z.string().nullable().optional(), billingCity: z.string().nullable().optional(), billingState: z.string().nullable().optional(), billingPostcode: z.string().nullable().optional(), billingCountry: z.string().nullable().optional(), billingCompany: z.string().nullable().optional(), isDefault: z.boolean().optional(), applyToScheduledOrders: z.boolean().optional(), gatewayPaymentType: qPilotCoreModelsGatewayPaymentType.optional()}); export const qPilotCoreModelsPagedResultUpsertPaymentMethodDto = z.object({items: z.array(qPilotCoreModelsDtoRequestsUpsertPaymentMethodDto).nullable().optional(), totalCount: z.number().int().optional(), totalPages: z.number().int().optional()}); 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 }; /** * Get Payment Methods * * GET /Sites/{siteId}/PaymentMethods */ export const getApiSitesSiteIdPaymentMethods = async (args: GetApiSitesSiteIdPaymentMethodsArgs, options?: GetApiSitesSiteIdPaymentMethodsOptions) => { const {baseUrl = "https://api.qpilot.cloud", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.customerId != null) query.append("customerId", String(args.customerId)) if (args.paymentMethodType != null) query.append("paymentMethodType", String(args.paymentMethodType)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.order != null) query.append("order", String(args.order)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/Sites/${encodeURIComponent(String(args.siteId))}/PaymentMethods${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(qPilotCoreModelsPagedResultUpsertPaymentMethodDto, await res.json()) };