import {z} from 'zod' export type Form1099KMonthlyAmounts = {january?: number | undefined, february?: number | undefined, march?: number | undefined, april?: number | undefined, may?: number | undefined, june?: number | undefined, july?: number | undefined, august?: number | undefined, september?: number | undefined, october?: number | undefined, november?: number | undefined, december?: number | undefined}; export type Form1099KPSEDetails = {pse_name?: string | undefined, pse_phone?: string | undefined}; export type Form1099KStateFiling = {state_code?: string | undefined, state_id_number?: string | undefined, state_tax_withheld?: number | undefined}; export type ForeignAddress = {address1?: string | undefined, address2?: string | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, postal_code?: string | undefined}; export type Form1099KUpdateRequest = {tax_year: '2023' | '2024' | '2025', supplemental_gross_amount?: number | undefined, gross_amount?: number | undefined, merchant_category_code: string, number_of_payment_transactions: number, federal_tax_withheld?: number | undefined, monthly_amounts?: Form1099KMonthlyAmounts | undefined, account_number?: string | undefined, filer_indicator?: ('PSE' | 'EPF') | undefined, transactions_reported_type: 'Payment_Card' | 'Third_Party_Network', pse_details?: Form1099KPSEDetails | undefined, state_filing?: Array | undefined, is_postal?: boolean | undefined, email_address?: string | undefined, address?: ForeignAddress | undefined, submission_id: string, is_void?: boolean | undefined}; export type UpdateApiPayoutUserTokenTaxForm1099kArgs = {body: Form1099KUpdateRequest}; export type UpdateApiPayoutUserTokenTaxForm1099kOptions = {baseUrl?: string | undefined, AUTHORIZERNAME?: string | undefined, fetch?: typeof fetch | undefined}; export const form1099UpdateCorrectionResponse = z.object({submission_id: z.string().optional(), record_id: z.string().optional(), operation: z.enum(["UPDATE", "CORRECTION"]).optional(), original_submission_id: z.string().optional(), status: z.enum(["SUCCESS", "FAILURE"]).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 }; /** * Update or Correct Form 1099-K * * PUT /payout/{user_token}/tax/form1099k * * Also accepts auth: api_key */ export const updateApiPayoutUserTokenTaxForm1099k = async (args: UpdateApiPayoutUserTokenTaxForm1099kArgs, options?: UpdateApiPayoutUserTokenTaxForm1099kOptions) => { const {baseUrl = "https://api.masspay.io/v1.0.0", fetch: fetchFn = fetch, AUTHORIZERNAME} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AUTHORIZERNAME !== undefined) headers.set("Authorization", AUTHORIZERNAME) const url = `${baseUrl.replace(/\/+$/, '')}/payout/${encodeURIComponent(String(args.user_token))}/tax/form1099k${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(form1099UpdateCorrectionResponse, await res.json()) };