import {z} from 'zod' export type CardAcceptorModel = {address?: string | undefined, city?: string | undefined, country?: string | undefined, ecommerce_security_level_indicator?: string | undefined, mcc?: string | undefined, name?: string | undefined, partial_approval_capable?: boolean | undefined, state?: string | undefined, zip?: string | undefined}; export type OriginalCreditSenderData = {funding_source: 'cash' | 'credit' | 'debit' | 'deposit_account' | 'mobile_money_payment' | 'non_visa_credit' | 'prepaid', sender_account_number?: string | undefined, sender_account_type?: ('bank_account_number_and_identification_code' | 'card_account' | 'email' | 'iban' | 'other' | 'phone_number' | 'rtn_bank_account' | 'social_network_id' | 'wallet_id') | undefined, sender_address?: string | undefined, sender_city?: string | undefined, sender_country?: string | undefined, sender_name?: string | undefined, sender_reference_number?: string | undefined, sender_state?: string | undefined, transaction_purpose?: ('crypto_currency' | 'education' | 'emergency_need' | 'family_support' | 'gifts' | 'labor_transfers' | 'lending' | 'medical_treatment' | 'other' | 'salary' | 'savings' | 'travel') | undefined, unique_transaction_reference_number?: string | undefined}; export type OriginalCreditRequestModel = {amount: number, card_acceptor?: CardAcceptorModel | undefined, card_id: string, mid: string, screening_score?: string | undefined, sender_data?: OriginalCreditSenderData | undefined, transactionPurpose?: string | undefined, type: 'account_to_account' | 'bill_payment' | 'business_to_business' | 'card_bill_payment' | 'cash_claim' | 'cash_in' | 'cash_out' | 'disbursement' | 'face_to_face_merchant_payment' | 'gambling_payout' | 'government_disbursement' | 'government_payment' | 'loyalty' | 'merchant_disbursement' | 'mobile_air_time_payment' | 'money_transfer_by_bank' | 'money_transfer_by_merchant' | 'online_gambling_payout' | 'payments_goods_services' | 'pension_disbursement' | 'person_to_person' | 'prepaid' | 'prepaid_loads' | 'wallet_transfer'}; export type CreateApiCardsTransactionSimulationsFinancialOriginalCreditArgs = {body: OriginalCreditRequestModel}; export type CreateApiCardsTransactionSimulationsFinancialOriginalCreditOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const simulationResponseModel = z.object({}); 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 }; /** * Simulate OCT * * POST /cards/transaction_simulations/financial/original_credit */ export const createApiCardsTransactionSimulationsFinancialOriginalCredit = async (args: CreateApiCardsTransactionSimulationsFinancialOriginalCreditArgs, options?: CreateApiCardsTransactionSimulationsFinancialOriginalCreditOptions) => { const {baseUrl = "https://api-sandbox.synctera.com/v0", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/cards/transaction_simulations/financial/original_credit${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(simulationResponseModel, await res.json()) };