import {z} from 'zod' 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 ChargeStatus = 'OUTSTANDING' | 'PAID' | 'EXTERNAL_SETTLEMENT' | 'VOID' | 'WRITE_OFF' | 'REFUNDED' | 'CHARGEBACK' | 'PAYMENT_PLAN' | 'COLLECTIONS'; 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 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 RefundSummary = {id: string, paymentId: string, amount: number, reason: RefundReason, createdDate: string, status: PaymentStatus, rainforestRefundId?: (string | null) | undefined, fee?: number | undefined}; export type PaymentInput = {id: string, patientId?: (string | null) | undefined, payinId?: (string | null) | undefined, amount: number, status: PaymentStatus, currency?: string | undefined, payinConfigId?: (string | null) | undefined, paymentMedium: string, paymentMethodId?: (string | null) | undefined, stripePaymentIntentId?: (string | null) | undefined, failedReason?: (string | null) | undefined, updatedDate?: (string | null) | undefined, createdDate: string, fee?: number | undefined, feeToPatient: number, paymentMethod?: (PaymentMethodSummary | null) | undefined, refunds?: Array | undefined}; export type ChargePaymentDetailInput = {paymentId: string, amount: number, createdDate?: (string | null) | undefined, chargeId: string, payment: PaymentInput}; 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 ChargeDetailInput = {id?: (string | null) | undefined, patientId: string, patient?: (PatientSummary | null) | undefined, total?: number | undefined, totalOutstanding: number, description?: (string | null) | undefined, status?: ChargeStatus | undefined, discountAmount?: (number | null) | undefined, discountPercentage?: (number | null) | undefined, externalId?: (string | null) | undefined, externalCreatedDate?: (string | null) | undefined, ruleSetId?: (string | null) | undefined, createdDate?: (string | null) | undefined, creatorId?: (string | null) | undefined, items?: Array | undefined, tips?: Array | undefined, locationId?: (string | null) | undefined, eventId?: (string | null) | undefined, memberId?: (string | null) | undefined, comment?: (string | null) | undefined, meta?: (Record | null) | undefined, merchantAccountId?: (string | null) | undefined, payments?: Array | undefined, adjustments?: Array | undefined}; export type InvoiceCreate = {patientId: string, ruleSetId: string, charges?: (Array | null) | undefined}; export type CreateApiBillingPaymentTerminalSetupInvoicingArgs = {TENANT: string, 'API-KEY': string, body: InvoiceCreate}; export type CreateApiBillingPaymentTerminalSetupInvoicingOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiBillingPaymentTerminalSetupInvoicingResponse = z.string(); 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 }; /** * Setup Invoicing * * POST /billing/payment-terminal/setup-invoicing */ export const createApiBillingPaymentTerminalSetupInvoicing = async (args: CreateApiBillingPaymentTerminalSetupInvoicingArgs, options: CreateApiBillingPaymentTerminalSetupInvoicingOptions) => { 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'])) const url = `${baseUrl.replace(/\/+$/, '')}/billing/payment-terminal/setup-invoicing${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(createApiBillingPaymentTerminalSetupInvoicingResponse, await res.json()) };