import {z} from 'zod' export type MiscellaneousCharges = {amount?: number | undefined, description?: string | undefined}; export type PenaltyPostTripCharge = {amount?: number | undefined, penalty_type?: string | undefined}; export type UnexpectedPostTripCharge = {amount?: number | undefined, charge_type?: string | undefined, description?: string | undefined}; export type SecurityDepositPostTripCharges = {miscellaneous_charges?: MiscellaneousCharges | undefined, paid_on_return_addons_for_charge?: Array | undefined, penalties?: Array | undefined, unexpected_post_trip_charges?: Array | undefined}; export type CollectOverageFeeRequest = {admin_message?: string | undefined, dry_claim?: boolean | undefined, message?: string | undefined, post_trip_charges?: SecurityDepositPostTripCharges | undefined, usage_overage_only?: boolean | undefined}; export type CreateApiBookingsIdCollectOverageFeeArgs = {id: number, body: CollectOverageFeeRequest}; export type CreateApiBookingsIdCollectOverageFeeOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const dBInterfaceMap = z.unknown(); export const paymentProcessorName = z.string(); export const paymentProcessor = z.object({country: z.string().optional(), external_processor: z.string().optional(), external_processor_id: z.string().optional(), name: paymentProcessorName.optional()}); export const transaction: z.ZodType = z.object({actual_deposit_date: z.string().optional(), adjustment: z.number().int().optional(), amount: z.number().int().optional(), auto_deposit: z.boolean().optional(), available: z.string().optional(), booking_id: z.number().int().optional(), brand: z.string().optional(), can_delete: z.boolean().optional(), can_finance_sync: z.boolean().optional(), can_refund: z.boolean().optional(), can_retry: z.boolean().optional(), can_reverse_transfer: z.boolean().optional(), can_sync: z.boolean().optional(), can_transfer: z.boolean().optional(), cc_fee: z.number().int().optional(), charged: z.string().optional(), created: z.string().optional(), created_by_id: z.number().int().optional(), deposit_date: z.string().optional(), description: z.string().optional(), display_charge_type: z.string().optional(), display_payment_processor_name: z.string().optional(), display_type: z.string().optional(), dispute_reason: z.string().nullable().optional(), dispute_status: z.string().nullable().optional(), disputed: z.boolean().optional(), expected_deposit_date: z.string().optional(), failed: z.boolean().optional(), fraudulent: z.boolean().optional(), fx_fee: z.number().int().optional(), id: z.number().int().optional(), is_refund: z.boolean().optional(), last_four: z.string().optional(), original_charge_id: z.lazy(() => transaction.optional()), our_fee: z.number().int().optional(), outdoorsy_fee: z.number().int().optional(), owner_federal_withholding_tax: z.number().int().optional(), owner_fee: z.number().int().optional(), owner_integrations_fee: z.number().int().nullable().optional(), owner_quebec_sales_tax: z.number().int().optional(), paid: z.boolean().optional(), payment_meta: dBInterfaceMap.optional(), payment_processor: paymentProcessor.optional(), payment_source: z.string().optional(), processor_settlement_id: z.string().nullable().optional(), recipient_id: z.number().int().optional(), refund_source: z.string().optional(), refunded: z.number().int().optional(), refunded_cc_fee: z.number().int().optional(), refunded_fee: z.number().int().optional(), refunded_fx_fee: z.number().int().optional(), refunded_outdoorsy_fee: z.number().int().optional(), refunded_owner_federal_withholding_tax: z.number().int().optional(), refunded_owner_fee: z.number().int().optional(), refunded_owner_integrations_fee: z.number().int().nullable().optional(), refunded_owner_quebec_sales_tax: z.number().int().optional(), refunded_service_fee: z.number().int().optional(), retry_payout_id: z.lazy(() => transaction.optional()), sales_tax: z.number().int().optional(), service_fee: z.number().int().optional(), status: z.string().optional(), stripe_fee: z.number().int().optional(), stripe_fee_refund: z.number().int().optional(), stripe_id: z.string().optional(), transfer: z.lazy(() => transaction.optional()), type: z.string().optional()}); export const createApiBookingsIdCollectOverageFeeResponse = z.array(transaction); 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 }; /** * Collect booking overage fee * * POST /bookings/{id}/collect-overage-fee * * Also accepts auth: API-Key */ export const createApiBookingsIdCollectOverageFee = async (args: CreateApiBookingsIdCollectOverageFeeArgs, options: CreateApiBookingsIdCollectOverageFeeOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/bookings/${encodeURIComponent(String(args.id))}/collect-overage-fee${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(createApiBookingsIdCollectOverageFeeResponse, await res.json()) };