import {z} from 'zod' export type DepositStatus = 'PROCESSING' | 'IN_REVIEW' | 'SUCCEEDED' | 'FAILED'; export type GetApiBillingDepositsArgs = {TENANT: string, 'API-KEY': string, page?: (number | null) | undefined, per_page?: (number | null) | undefined, sort_by?: (string | null) | undefined, sort_direction?: ('asc' | 'desc' | null) | undefined, location_id?: (string | null) | undefined, merchant_account_id?: (string | null) | undefined, status?: (DepositStatus | null) | undefined, rainforest_deposit_id?: (string | null) | undefined, month?: (string | null) | undefined, tz?: (string | null) | undefined, body: Array | string | null}; export type GetApiBillingDepositsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const depositStatus = z.enum(["PROCESSING", "IN_REVIEW", "SUCCEEDED", "FAILED"]); export const paymentStatus = z.enum(["CANCELED", "CREATED", "FAILED", "IN_REVIEW", "PRESENTING", "PROCESSING", "SUCCEEDED"]); export const paymentMethodType = z.enum(["CARD", "ACH", "APPLE_PAY"]); export const paymentMethodSummary = z.object({id: z.string(), patientId: z.string().nullable(), rainforestPaymentMethodId: z.string(), brand: z.string().nullable(), last4: z.string().nullable(), expMonth: z.number().int().nullable(), expYear: z.number().int().nullable(), accountHolderType: z.string().nullable(), accountNumberLast4: z.number().int().nullable(), bankName: z.string().nullable(), routingNumber: z.number().int().nullable(), description: z.string().nullable(), type: paymentMethodType.nullable(), isDefault: z.boolean().optional(), isArchived: z.boolean().optional()}); export const refundReason = z.enum(["DUPLICATE", "DISPUTE", "BOOKING_FEE", "OTHER"]); export const refundSummary = z.object({id: z.string(), paymentId: z.string(), amount: z.number().int(), reason: refundReason, createdDate: z.string(), status: paymentStatus, rainforestRefundId: z.string().nullable().optional(), fee: z.number().int().optional()}); export const userType = z.enum(["PROVIDER", "PATIENT", "ASSISTANT"]); export const patientTagSummary = z.object({id: z.string(), name: z.string(), emoji: z.string().nullable().optional(), color: z.string().nullable().optional(), isActive: z.boolean(), createdDate: z.string(), updatedDate: z.string().nullable().optional()}); export const patientSummary = z.object({id: z.string(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), phoneNumber: z.string().nullable().optional(), email: z.string().nullable().optional(), type: userType, locationId: z.string().nullable().optional(), externalId: z.string().nullable().optional(), address: z.string().nullable().optional(), addressLineTwo: z.string().nullable().optional(), city: z.string().nullable().optional(), state: z.string().nullable().optional(), zipCode: z.string().nullable().optional(), country: z.string().nullable().optional(), createdDate: z.string(), addressValid: z.boolean().nullable().optional(), meta: z.object({}).nullable().optional(), isArchived: z.boolean().nullable().optional(), primaryLocationId: z.string().nullable().optional(), gender: z.string().nullable().optional(), dateOfBirth: z.string().nullable().optional(), patientMedications: z.array(z.string()).nullable().optional(), onSchedulingBlacklist: z.boolean().nullable().optional(), surchargeDisabled: z.boolean().nullable().optional(), tags: z.array(patientTagSummary).nullable().optional(), creditBalance: z.number().int().nullable().optional(), preferredProviderId: z.string().nullable().optional()}); export const paymentWithPatient = z.object({id: z.string(), patientId: z.string().nullable().optional(), payinId: z.string().nullable().optional(), amount: z.number().int(), status: paymentStatus, currency: z.string().optional(), payinConfigId: z.string().nullable().optional(), paymentMedium: z.string(), paymentMethodId: z.string().nullable().optional(), stripePaymentIntentId: z.string().nullable().optional(), failedReason: z.string().nullable().optional(), updatedDate: z.string().nullable().optional(), createdDate: z.string(), fee: z.number().int().optional(), feeToPatient: z.number().int(), paymentMethod: paymentMethodSummary.nullable().optional(), refunds: z.array(refundSummary).optional(), patient: patientSummary.nullable()}); export const refundWithPatient = z.object({id: z.string(), paymentId: z.string(), amount: z.number().int(), reason: refundReason, createdDate: z.string(), status: paymentStatus, rainforestRefundId: z.string().nullable().optional(), fee: z.number().int().optional(), patient: patientSummary}); export const depositDetails = z.object({rainforestDepositId: z.string(), merchantAccountId: z.string(), amount: z.number().int(), currency: z.string().optional(), fee: z.number().int().optional(), netAmount: z.number().int(), status: depositStatus.optional(), rainforestCreatedDate: z.string().nullable().optional(), rainforestUpdatedDate: z.string().nullable().optional(), description: z.string().nullable().optional(), externalReference: z.string().nullable().optional(), id: z.string(), createdDate: z.string(), updatedDate: z.string().nullable().optional(), subtotal: z.number().int().nullable().optional(), totalFees: z.number().int().nullable().optional(), amountDeposited: z.number().int().nullable().optional(), payments: z.array(paymentWithPatient).optional(), refunds: z.array(refundWithPatient).optional()}); export const pageDepositDetails = z.object({data: z.array(depositDetails), total: z.number().int()}); 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 }; /** * List Deposits * * GET /billing/deposits */ export const getApiBillingDeposits = async (args: GetApiBillingDepositsArgs, options: GetApiBillingDepositsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.TENANT != null) headers.set("TENANT", String(args.TENANT)) if (args['API-KEY'] != null) headers.set("API-KEY", String(args['API-KEY'])) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_direction != null) query.append("sort_direction", String(args.sort_direction)) if (args.location_id != null) query.append("location_id", String(args.location_id)) if (args.merchant_account_id != null) query.append("merchant_account_id", String(args.merchant_account_id)) if (args.status != null) query.append("status", String(args.status)) if (args.rainforest_deposit_id != null) query.append("rainforest_deposit_id", String(args.rainforest_deposit_id)) if (args.month != null) query.append("month", String(args.month)) if (args.tz != null) query.append("tz", String(args.tz)) const url = `${baseUrl.replace(/\/+$/, '')}/billing/deposits${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", 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(pageDepositDetails, await res.json()) };