export type ExternalRefundRequest = {serviceProvider: 'AUTHORIZENET' | 'BRAINTREE' | 'CHECKOUT' | 'CIRCLE' | 'NMI' | 'STRIPE', serviceTransactionId: string, sourceAmount: number}; export type CreateApiPaymentsExternalRefundArgs = {'X-Idempotency-Key'?: string | undefined, 'Meld-Passthrough-Reference'?: string | undefined, 'Meld-Passthrough-Key-Id'?: string | undefined, 'Meld-Passthrough-Key-Public'?: string | undefined, 'Meld-Passthrough-Key-Private'?: string | undefined, 'Meld-Passthrough-Oauth'?: string | undefined, body: ExternalRefundRequest}; export type CreateApiPaymentsExternalRefundOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Refund an external payment transaction * * POST /payments/external/refund */ export const createApiPaymentsExternalRefund = async (args: CreateApiPaymentsExternalRefundArgs, options?: CreateApiPaymentsExternalRefundOptions) => { const {baseUrl = "https://api-sb.meld.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (args['X-Idempotency-Key'] != null) headers.set("X-Idempotency-Key", String(args['X-Idempotency-Key'])) if (args['Meld-Passthrough-Reference'] != null) headers.set("Meld-Passthrough-Reference", String(args['Meld-Passthrough-Reference'])) if (args['Meld-Passthrough-Key-Id'] != null) headers.set("Meld-Passthrough-Key-Id", String(args['Meld-Passthrough-Key-Id'])) if (args['Meld-Passthrough-Key-Public'] != null) headers.set("Meld-Passthrough-Key-Public", String(args['Meld-Passthrough-Key-Public'])) if (args['Meld-Passthrough-Key-Private'] != null) headers.set("Meld-Passthrough-Key-Private", String(args['Meld-Passthrough-Key-Private'])) if (args['Meld-Passthrough-Oauth'] != null) headers.set("Meld-Passthrough-Oauth", String(args['Meld-Passthrough-Oauth'])) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/payments/external/refund${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 res.blob() };