import {z} from 'zod' export type BusinessDetailsDto = {businessName?: string | undefined, country?: string | undefined, customerCity?: string | undefined, customerCountry?: string | undefined, customerLine1?: string | undefined, customerLine2?: string | undefined, customerName?: string | undefined, customerPostalCode?: string | undefined, customerRef?: string | undefined, customerState?: string | undefined, isBusiness: boolean, taxId?: string | undefined, taxIdType?: ('ae_trn' | 'al_tin' | 'am_tin' | 'ao_tin' | 'au_abn' | 'aw_tin' | 'az_tin' | 'ba_tin' | 'bb_tin' | 'bd_bin' | 'bf_ifu' | 'bh_vat' | 'bj_ifu' | 'bs_tin' | 'by_tin' | 'ca_gst_hst' | 'cd_nif' | 'ch_vat' | 'cl_tin' | 'cm_niu' | 'co_nit' | 'cr_tin' | 'cv_nif' | 'ec_ruc' | 'eg_tin' | 'et_tin' | 'eu_vat' | 'gb_vat' | 'ge_vat' | 'gn_nif' | 'hk_br' | 'id_npwp' | 'in_gst' | 'is_vat' | 'jp_trn' | 'ke_pin' | 'kg_tin' | 'kh_tin' | 'kr_brn' | 'kz_bin' | 'la_tin' | 'li_vat' | 'lk_vat' | 'ma_vat' | 'md_vat' | 'me_pib' | 'mk_vat' | 'mr_nif' | 'mx_rfc' | 'my_sst' | 'ng_tin' | 'no_vat' | 'np_pan' | 'nz_gst' | 'om_vat' | 'pe_ruc' | 'ph_tin' | 'rs_pib' | 'ru_inn' | 'sa_vat' | 'sg_gst' | 'sn_ninea' | 'sr_fin' | 'th_vat' | 'tj_tin' | 'tr_tin' | 'tw_vat' | 'tz_vat' | 'ua_vat' | 'ug_tin' | 'us_ein' | 'uy_ruc' | 'uz_vat' | 'vn_tin' | 'za_vat' | 'zm_tin' | 'zw_tin') | undefined}; export type CreateApiV1SdkPaymentIntentsProcessorPaymentIdBusinessDetailsArgs = {processorPaymentId: string, body: BusinessDetailsDto}; export type CreateApiV1SdkPaymentIntentsProcessorPaymentIdBusinessDetailsOptions = {baseUrl?: string | undefined, SecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const taxBreakdownDto = z.object({currency: z.string(), inclusive: z.boolean(), notRegistered: z.boolean().optional(), subtotal: z.number(), taxAmount: z.number(), taxRate: z.number(), taxType: z.enum(["amusement_tax", "communications_tax", "gst", "hst", "igst", "jct", "lease_tax", "pst", "qst", "retail_delivery_fee", "rst", "sales_tax", "service_tax", "vat"]).optional(), total: z.number(), treatment: z.enum(["reverse_charge", "standard", "none", "not_collecting", "not_supported"])}); export const attachBusinessDetailsResponse = z.object({taxBreakdown: taxBreakdownDto}); 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 }; /** * Attach business tax details to a payment intent * * POST /v1/sdk/payment-intents/{processorPaymentId}/business-details */ export const createApiV1SdkPaymentIntentsProcessorPaymentIdBusinessDetails = async (args: CreateApiV1SdkPaymentIntentsProcessorPaymentIdBusinessDetailsArgs, options?: CreateApiV1SdkPaymentIntentsProcessorPaymentIdBusinessDetailsOptions) => { const {baseUrl = "https://api.solvapay.com", fetch: fetchFn = fetch, SecretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (SecretKey !== undefined) headers.set('authorization', `Bearer ${SecretKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/sdk/payment-intents/${encodeURIComponent(String(args.processorPaymentId))}/business-details${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(attachBusinessDetailsResponse, await res.json()) };