import {z} from 'zod' export type BusinessDocument = {document_type: 'kyb_report' | 'articles_of_incorporation' | 'certificate_of_incorporation' | 'certificate_of_good_standing' | 'business_license' | 'operating_agreement' | 'bylaws' | 'ownership_structure' | 'proof_of_address' | 'bank_statement' | 'tax_document' | 'financial_statement' | 'other', file_name: string, file_content: string, description?: string | undefined}; export type CreateBusinessTxn = {reference_id: string, legal_name: string, type: 'Ccorp' | 'LLC' | 'Partnership' | 'Nonprofit' | 'Scorp' | 'Soleprop' | 'Other', category: string, mcc_sic?: string | undefined, country: string, street1: string, street2?: string | undefined, city: string, state_prov: string, postal_code: string, address_type?: ('Residential' | 'Commercial' | 'Other') | undefined, place_of_incorporation: string, incorporation_date: string, phone_number: string, email_address: string, website_address: string, description: string, tax_id_type: 'Passport' | 'National Identification Card' | 'Driving License' | 'Social Security Card/Number' | 'Tax Payer Identification Card/Number' | 'Senior Citizen Identification Card' | 'Birth Certificate' | 'Village Elder Identification Card' | 'Permanent Residency Identification Card' | 'Alien Registration Certificate/Card' | 'PAN Card' | 'Voter’s Identification Card' | 'Health Insurance Card/Number' | 'Employer Identification Card' | 'Others not listed', tax_id_number: string, registration_number: string, articles_of_incorporation?: string | undefined, partner_comments?: string | undefined, notify_user?: boolean | undefined, partner_pays_transaction_fees?: boolean | undefined, bank_details?: ({first_name?: string | undefined, last_name?: string | undefined, name_on_account: string, account_type?: ('Checking' | 'Savings') | undefined, routing_number: string, account_number: string}) | undefined, dba?: ({same_as_legal: boolean, business_name?: string | undefined, street1?: string | undefined, street2?: string | undefined, city?: string | undefined, state_prov?: string | undefined, postal_code?: string | undefined, country?: string | undefined}) | undefined, details?: ({company_annual_revenue?: number | undefined, days_to_receive_product_or_service?: number | undefined, expected_monthly_payout_transaction_volume?: number | undefined, expected_monthly_payout_transaction_count?: number | undefined, transaction_types_accepted?: (Array<'Visa' | 'Mastercard' | 'Discover' | 'Amex' | 'ACH'>) | undefined, credit_and_debit_card_accepted?: boolean | undefined, expected_monthly_amex_sales_volume?: number | undefined, card_acceptance_card_present?: number | undefined, card_acceptance_card_not_present?: number | undefined, card_acceptance_internet?: boolean | undefined, total_ach_annual_amount?: number | undefined, average_ach_ticket_amount?: number | undefined, highest_ach_ticket_amount?: number | undefined, max_monthly_ach_ticket_amount?: number | undefined, total_sales_monthly?: number | undefined, actual_or_projected_monthly_credit_debit_sales?: number | undefined, highest_amount_ticket?: number | undefined, times_year_highest_ticket_amount_expected?: number | undefined, avg_ticket_amount?: number | undefined}) | undefined, contact_person?: ({first_name?: string | undefined, last_name?: string | undefined, title?: string | undefined, email_address?: string | undefined, phone_number?: string | undefined, reference_id?: string | undefined}) | undefined, principal: Array<{type: Array<'Control Person' | 'Owner' | 'Officer'>, reference_id?: string | undefined, title: string, first_name: string, middle_name?: string | undefined, last_name: string, percentage_of_ownership: number, address_same_as_legal: boolean, street1: string, street2?: string | undefined, city: string, state_prov: string, postal_code: string, country: string, email_address: string, phone_number: string, dob: string, tax_id_type: 'Passport' | 'National Identification Card' | 'Driving License' | 'Social Security Card/Number' | 'Tax Payer Identification Card/Number' | 'Senior Citizen Identification Card' | 'Birth Certificate' | 'Village Elder Identification Card' | 'Permanent Residency Identification Card' | 'Alien Registration Certificate/Card' | 'PAN Card' | 'Voter’s Identification Card' | 'Health Insurance Card/Number' | 'Employer Identification Card' | 'Others not listed', tax_id_number: string, id_document?: string | undefined, signing_application: boolean, country_of_citizenship: string}>, webhooks?: (Array<{webhook_url?: string | undefined, event_types?: (Array<'user.created' | 'user.status' | 'payout.created' | 'payout.status' | 'payin.created' | 'payin.status' | 'load.created' | 'load.status' | 'load.reversed' | 'spendback.created' | 'spendback.status' | 'spendback.inactivity' | 'kyc.id' | 'kyc.tax' | 'attributes.stored' | 'deposit_account.created' | 'business.created' | 'business.status' | 'balance.credit' | 'payout_reversal.created' | 'payout_reversal.status' | 'avs.completed' | 'payin_deposit.return_completed' | 'payin_deposit.returned' | 'file_upload_req.created' | 'file_upload_req.status' | 'file_upload_req.verified'>) | undefined}>) | undefined, documents?: Array | undefined}; export type CreateApiBusinessArgs = {body: CreateBusinessTxn}; export type CreateApiBusinessOptions = {baseUrl?: string | undefined, AUTHORIZERNAME?: string | undefined, fetch?: typeof fetch | undefined}; export const businessDocumentResp = z.object({document_token: z.string(), document_type: z.enum(["kyb_report", "articles_of_incorporation", "certificate_of_incorporation", "certificate_of_good_standing", "business_license", "operating_agreement", "bylaws", "ownership_structure", "proof_of_address", "bank_statement", "tax_document", "financial_statement", "other"]), file_name: z.string(), size_bytes: z.number().int(), description: z.string().optional(), time_uploaded: z.string()}); export const createApiBusinessResponse = z.object({business_token: z.string(), api_key: z.string(), webhooks: z.array(z.object({webhook_token: z.string().optional(), webhook_url: z.string().optional(), event_types: z.array(z.enum(["user.created", "user.status", "payout.created", "payout.status", "payin.created", "payin.status", "load.created", "load.status", "load.reversed", "spendback.created", "spendback.status", "spendback.inactivity", "kyc.id", "kyc.tax", "attributes.stored", "deposit_account.created", "business.created", "business.status", "balance.credit", "payout_reversal.created", "payout_reversal.status", "avs.completed", "payin_deposit.return_completed", "payin_deposit.returned", "file_upload_req.created", "file_upload_req.status", "file_upload_req.verified"])).optional(), webhook_secret: z.string().optional()})).optional(), documents: z.array(businessDocumentResp).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 }; /** * Create business * * POST /business * * Also accepts auth: api_key */ export const createApiBusiness = async (args: CreateApiBusinessArgs, options?: CreateApiBusinessOptions) => { 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(/\/+$/, '')}/business${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(createApiBusinessResponse, await res.json()) };