import {z} from 'zod' export type CreateApiV1ChargesChargeIdCaptureArgs = {charge_id: string, body: {amount?: number | undefined, tip_amount?: number | undefined}}; export type CreateApiV1ChargesChargeIdCaptureOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1ChargesChargeIdCaptureResponse = z.object({data: z.object({object: z.string().optional(), id: z.string().optional(), amount: z.number().int().optional(), amount_approved: z.number().int().optional(), amount_refunded: z.number().int().optional(), amount_captured: z.number().int().optional(), amount_voided: z.number().int().optional(), application_fee_amount: z.number().int().optional(), tip_amount: z.number().int().optional(), payarc_fees: z.number().int().optional(), type: z.string().optional(), customer_email: z.string().optional(), net_amount: z.number().int().optional(), captured: z.number().int().optional(), is_refunded: z.number().int().optional(), status: z.string().optional(), auth_code: z.string().optional(), failure_code: z.unknown(), failure_message: z.unknown(), charge_description: z.unknown(), kount_details: z.string().optional(), kount_status: z.string().optional(), statement_description: z.string().optional(), invoice: z.unknown(), under_review: z.number().int().optional(), created_at: z.number().int().optional(), updated_at: z.number().int().optional(), email: z.unknown(), phone_number: z.unknown(), card_level: z.string().optional(), sales_tax: z.unknown(), purchase_order: z.unknown(), supplier_reference_number: z.unknown(), customer_ref_id: z.unknown(), ship_to_zip: z.unknown(), amex_descriptor: z.unknown(), customer_vat_number: z.unknown(), summary_commodity_code: z.unknown(), shipping_charges: z.unknown(), duty_charges: z.unknown(), ship_from_zip: z.unknown(), destination_country_code: z.unknown(), vat_invoice: z.unknown(), order_date: z.unknown(), tax_category: z.unknown(), tax_type: z.unknown(), tax_rate: z.unknown(), tax_amount: z.unknown(), created_by: z.string().optional(), terminal_register: z.unknown(), amex_level3: z.array(z.unknown()).optional(), tip_amount_refunded: z.unknown(), sales_tax_refunded: z.unknown(), shipping_charges_refunded: z.unknown(), duty_charges_refunded: z.unknown(), pax_reference_number: z.unknown(), refund_reason: z.unknown(), refund_description: z.unknown(), surcharge: z.number().int().optional(), toll_amount: z.unknown(), airport_fee: z.unknown(), health_care: z.unknown(), health_care_type: z.unknown(), prescription_amount: z.unknown(), vision_amount: z.unknown(), clinic_amount: z.unknown(), dental_amount: z.unknown(), industry_type: z.unknown(), void_reason: z.unknown(), void_description: z.unknown(), server_id: z.unknown(), external_invoice_id: z.unknown(), external_order_id: z.unknown(), tsys_response_code: z.string().optional(), host_response_code: z.string().optional(), host_response_message: z.string().optional(), emv_issuer_scripts: z.unknown(), emv_issuer_authentication_data: z.unknown(), host_reference_number: z.string().optional(), sale_terminal_id: z.unknown(), sale_mid: z.unknown(), edc_type: z.unknown(), ecr_reference_number: z.unknown(), refund: z.object({data: z.array(z.unknown()).optional()}).optional(), card: z.object({data: z.object({object: z.string().optional(), id: z.string().optional(), address1: z.unknown(), address2: z.unknown(), card_source: z.string().optional(), card_holder_name: z.unknown(), is_default: z.number().int().optional(), exp_month: z.string().optional(), exp_year: z.string().optional(), is_verified: z.number().int().optional(), fingerprint: z.string().optional(), city: z.unknown(), state: z.unknown(), zip: z.unknown(), brand: z.string().optional(), last4digit: z.string().optional(), first6digit: z.number().int().optional(), country: z.unknown(), avs_status: z.string().optional(), cvc_status: z.string().optional(), address_check_passed: z.number().int().optional(), zip_check_passed: z.number().int().optional(), customer_id: z.string().optional(), created_at: z.number().int().optional(), updated_at: z.number().int().optional(), card_type: z.string().optional(), bin_country: z.string().optional(), bank_name: z.unknown(), bank_website: z.unknown(), bank_phone: z.unknown()}).optional()}).optional()}).optional(), meta: z.object({include: z.array(z.string()).optional(), custom: z.array(z.unknown()).optional()}).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 }; /** * Capture a Charge * * POST /v1/charges/{charge_id}/capture */ export const createApiV1ChargesChargeIdCapture = async (args: CreateApiV1ChargesChargeIdCaptureArgs, options?: CreateApiV1ChargesChargeIdCaptureOptions) => { const {baseUrl = "https://testapi.payarc.net", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v1/charges/${encodeURIComponent(String(args.charge_id))}/capture${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(createApiV1ChargesChargeIdCaptureResponse, await res.json()) };