import {z} from 'zod' export type GetApiSitesSiteIdPaymentMethodsIdArgs = {siteId: number, id: number}; export type GetApiSitesSiteIdPaymentMethodsIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const qPilotCoreModelsPaymentMethodStatus = z.enum(["Active", "Expired", "Revoked", "Invalid"]); 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 qPilotCoreModelsDtoEntitiesPaymentMethodDto = z.object({id: z.number().int().optional(), status: qPilotCoreModelsPaymentMethodStatus.optional(), createdUtc: z.string().optional(), updatedUtc: z.string().optional(), expirationDate: z.string().nullable().optional(), 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().nullable().optional(), lastFourDigits: z.string().nullable().optional(), billingFirstName: z.string().max(256).nullable().optional(), billingLastName: z.string().max(256).nullable().optional(), billingStreet1: z.string().max(256).nullable().optional(), billingStreet2: z.string().max(256).nullable().optional(), billingCity: z.string().max(256).nullable().optional(), billingState: z.string().max(256).nullable().optional(), billingPostcode: z.string().max(20).nullable().optional(), billingCountry: z.string().max(2).nullable().optional(), billingCompany: z.string().max(255).nullable().optional(), isDefault: z.boolean().nullable().optional(), gatewayPaymentType: qPilotCoreModelsGatewayPaymentType.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 Method * * GET /Sites/{siteId}/PaymentMethods/{id} */ export const getApiSitesSiteIdPaymentMethodsId = async (args: GetApiSitesSiteIdPaymentMethodsIdArgs, options?: GetApiSitesSiteIdPaymentMethodsIdOptions) => { 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 (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/Sites/${encodeURIComponent(String(args.siteId))}/PaymentMethods/${encodeURIComponent(String(args.id))}${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(qPilotCoreModelsDtoEntitiesPaymentMethodDto, await res.json()) };