export type UUID = string; export type DefendChargebackDocument = {document_base64: string, filename?: string | undefined, content_type?: string | undefined}; export type DefendChargebackShippingInfo = {company_name?: string | undefined, shipping_date?: string | undefined, tracking_number?: string | undefined, shipping_address?: string | undefined}; export type DefendChargebackRecipientInfo = {name?: string | undefined, phone?: string | undefined, email?: string | undefined}; export type DefendChargebackRequestBody = {description: string, document: DefendChargebackDocument, product_name?: string | undefined, shipping_info?: DefendChargebackShippingInfo | undefined, recipient_info?: DefendChargebackRecipientInfo | undefined}; export type CreateApiChargebackRequestsIdDefendArgs = {id: UUID, body: DefendChargebackRequestBody}; export type CreateApiChargebackRequestsIdDefendOptions = {baseUrl?: string | undefined, apiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Chargeback: Defend * * POST /chargeback_requests/{id}/defend */ export const createApiChargebackRequestsIdDefend = async (args: CreateApiChargebackRequestsIdDefendArgs, options?: CreateApiChargebackRequestsIdDefendOptions) => { const {baseUrl = "https://komoju.com/api/v1", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (apiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${apiKey.username}:${apiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/chargeback_requests/${encodeURIComponent(String(args.id))}/defend${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 undefined };