import {z} from 'zod' export type ChargeStatus = 'OUTSTANDING' | 'PAID' | 'EXTERNAL_SETTLEMENT' | 'VOID' | 'WRITE_OFF' | 'REFUNDED' | 'CHARGEBACK' | 'PAYMENT_PLAN' | 'COLLECTIONS'; export type UserType = 'PROVIDER' | 'PATIENT' | 'ASSISTANT'; export type PatientTagSummary = {id: string, name: string, emoji?: (string | null) | undefined, color?: (string | null) | undefined, isActive: boolean, createdDate: string, updatedDate?: (string | null) | undefined}; export type PatientSummary = {id: string, firstName?: (string | null) | undefined, lastName?: (string | null) | undefined, phoneNumber?: (string | null) | undefined, email?: (string | null) | undefined, type: UserType, locationId?: (string | null) | undefined, externalId?: (string | null) | undefined, address?: (string | null) | undefined, addressLineTwo?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, zipCode?: (string | null) | undefined, country?: (string | null) | undefined, createdDate: string, addressValid?: (boolean | null) | undefined, meta?: (Record | null) | undefined, isArchived?: (boolean | null) | undefined, primaryLocationId?: (string | null) | undefined, gender?: (string | null) | undefined, dateOfBirth?: (string | null) | undefined, patientMedications?: (Array | null) | undefined, onSchedulingBlacklist?: (boolean | null) | undefined, surchargeDisabled?: (boolean | null) | undefined, tags?: (Array | null) | undefined, creditBalance?: (number | null) | undefined, preferredProviderId?: (string | null) | undefined}; export type UserTiny = {id: string, firstName?: (string | null) | undefined, lastName?: (string | null) | undefined, phoneNumber?: (string | null) | undefined, email?: (string | null) | undefined, type: UserType, locationId?: (string | null) | undefined}; export type AdjustmentType = 'WRITE_OFF' | 'ADJUSTMENT' | 'EXTERNAL_SETTLEMENT'; export type AdjustmentSummary = {chargeId: string, providerId?: (string | null) | undefined, locationId?: (string | null) | undefined, id: string, amount: number, reason?: (string | null) | undefined, createdDate: string, adjustmentType: AdjustmentType}; export type PaymentStatus = 'CANCELED' | 'CREATED' | 'FAILED' | 'IN_REVIEW' | 'PRESENTING' | 'PROCESSING' | 'SUCCEEDED'; export type PaymentMethodType = 'CARD' | 'ACH' | 'APPLE_PAY'; export type PaymentMethodSummary = {id: string, patientId: string | null, rainforestPaymentMethodId: string, brand: string | null, last4: string | null, expMonth: number | null, expYear: number | null, accountHolderType: string | null, accountNumberLast4: number | null, bankName: string | null, routingNumber: number | null, description: string | null, type: PaymentMethodType | null, isDefault?: boolean | undefined, isArchived?: boolean | undefined}; export type RefundReason = 'DUPLICATE' | 'DISPUTE' | 'BOOKING_FEE' | 'OTHER'; export type TableRefundInput = {id: string, amount: number, reason: RefundReason, createdDate: string, description?: (string | null) | undefined, creator?: (UserTiny | null) | undefined}; export type ChargeTablePaymentInput = {id: string, amount: number, status: PaymentStatus, createdDate: string, paymentMedium: string, paymentMethod?: (PaymentMethodSummary | null) | undefined, refunds: Array}; export type PlannedPaymentStatus = 'SCHEDULED' | 'COMPLETED' | 'FAILED' | 'CANCELLED'; export type ChargeTablePlannedPayment = {id: string, amount: number, status: PlannedPaymentStatus, paymentDate: string}; export type ChargeItem = {id?: (string | null) | undefined, itemId?: (string | null) | undefined, chargeId: string, name?: (string | null) | undefined, description?: (string | null) | undefined, quantity: number, discountAmount?: (number | null) | undefined, discountPercentage?: (number | null) | undefined, discountReason?: (string | null) | undefined, price: number, soldPackageId?: (string | null) | undefined, bankedQuantity?: (number | null) | undefined, bankedItemId?: (string | null) | undefined, issuedDiscountId?: (string | null) | undefined, soldByProviderId?: (string | null) | undefined, taxAmount?: (number | null) | undefined, pricingId?: (string | null) | undefined, shipmentIds?: (Array | null) | undefined}; export type ProviderTiny = {id: string, firstName: string, lastName?: (string | null) | undefined, email?: (string | null) | undefined, createdDate?: (string | null) | undefined}; export type TipDetail = {chargeId: string, amount: number, providerId: string, id?: string | undefined, provider?: (ProviderTiny | null) | undefined}; export type ChargeTableInput = {id: string, total: number, totalOutstanding: number, description?: (string | null) | undefined, status: ChargeStatus, patient: PatientSummary, ruleSetId?: (string | null) | undefined, externalCreatedDate?: (string | null) | undefined, createdDate: string, externalId?: (string | null) | undefined, creator?: (UserTiny | null) | undefined, adjustments: Array, payments: Array, plannedPayments: Array, comment?: (string | null) | undefined, items: Array, locationId?: (string | null) | undefined, tips?: Array | undefined}; export type CreateApiBillingPaymentCashCreateArgs = {TENANT: string, 'API-KEY': string, payment_medium?: string | undefined, body: ChargeTableInput}; export type CreateApiBillingPaymentCashCreateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const paymentStatus = z.enum(["CANCELED", "CREATED", "FAILED", "IN_REVIEW", "PRESENTING", "PROCESSING", "SUCCEEDED"]); export const paymentSummary = 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()}); 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 Cash Payment * * POST /billing/payment/cash/create */ export const createApiBillingPaymentCashCreate = async (args: CreateApiBillingPaymentCashCreateArgs, options: CreateApiBillingPaymentCashCreateOptions) => { 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.payment_medium != null) query.append("payment_medium", String(args.payment_medium)) const url = `${baseUrl.replace(/\/+$/, '')}/billing/payment/cash/create${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(paymentSummary, await res.json()) };