import {z} from 'zod' export type PaymentType = 'ae_aani' | 'ae_uaefts' | 'ae_uaefts_rtgs' | 'ar_coelsa' | 'ar_mep' | 'ar_transfer_30' | 'au_becs' | 'au_npp' | 'au_rits' | 'bacs' | 'becs' | 'bh_benefit' | 'bh_fawri' | 'bh_rtgs' | 'br_pix' | 'br_str' | 'br_ted' | 'ca_eft' | 'ca_lynx' | 'ca_rtr' | 'cbs_transfer' | 'ch_sct' | 'ch_sic' | 'ch_sip' | 'chaps' | 'cl_cca' | 'cl_lbtr' | 'cl_tef' | 'co_ach' | 'co_bre_b' | 'co_cud' | 'fps' | 'icelandic_exp' | 'id_bifast' | 'id_birtgs' | 'id_sknbi' | 'internal_transfer' | 'ke_eft' | 'ke_pesalink' | 'ke_rtgs' | 'mx_spei' | 'my_duitnow' | 'my_ibg' | 'my_rentas' | 'no_nbo' | 'no_nics' | 'no_nics_instant' | 'osko' | 'ph_instapay' | 'ph_pddts' | 'ph_philpass' | 'pl_elixir' | 'pl_express_elixir' | 'pl_sorbnet' | 'rits' | 'ro_regis' | 'ro_sent' | 'ro_sent_instant' | 'sa_sarie' | 'sa_sarie_instant' | 'sa_sarie_rtgs' | 'se_bankgirot' | 'se_rix' | 'se_rix_instant' | 'sepa' | 'sepa_instant' | 'sepa_urgent' | 'sg_giro' | 'sg_meps' | 'sg_paynow' | 'swift' | 'swift_fi_to_fi' | 'target2' | 'target2_fi_to_fi' | 'th_bahtnet' | 'th_nitmx' | 'th_promptpay' | 'tl_ips' | 'tl_rtimor_ach' | 'tl_rtimor_rtgs' | 'treasury' | 'us_ach' | 'us_fednow' | 'us_rtp' | 'us_wire' | 'za_eft' | 'za_rpp' | 'za_samos'; export type CommonAddress = {line_1?: string | undefined, line_2?: string | undefined, building_number?: string | undefined, street_name?: string | undefined, postal_code?: string | undefined, region_state?: string | undefined, city?: string | undefined, country?: string | undefined, department?: (string | null) | undefined, sub_department?: (string | null) | undefined, building_name?: (string | null) | undefined, floor?: (string | null) | undefined, postal_box?: (string | null) | undefined, room?: (string | null) | undefined, city_location_name?: (string | null) | undefined, district_name?: (string | null) | undefined}; export type OrganizationIdentificationOthersType = 'bank_identification' | 'central_bank_identification' | 'clearing_house_identification' | 'company_incorporation_number' | 'company_identification' | 'customer_number' | 'duns_number' | 'employee_number' | 'global_location_number' | 'siren' | 'siret' | 'tax_number' | 'telephone_number' | 'business_domain_identification' | 'other_identification' | 'unknown'; export type OrganizationIdentification = {legal_entity_identifier?: string | undefined, business_identification_code?: string | undefined, default_other_identifier_type?: OrganizationIdentificationOthersType | undefined, others?: Array<{type: OrganizationIdentificationOthersType, value: string}> | undefined}; export type PrivateIdentificationOtherIdentificationType = 'alien_registration_number' | 'passport_number' | 'customer_identification_number' | 'drivers_license_number' | 'employee_identification_number' | 'national_identity_number' | 'social_security_number' | 'telephone_number' | 'tax_identification_number' | 'person_commercial_identification'; export type PrivateIdentification = {birth_date?: string | undefined, birth_city?: string | undefined, birth_country?: string | undefined, other?: ({identification?: string | undefined, identification_type?: PrivateIdentificationOtherIdentificationType | undefined, custom_identification_type?: string | undefined, identification_issuer?: string | undefined}) | undefined}; export type PaymentOrderOriginatingAccount = {account_number?: string | undefined, account_number_format?: ('iban' | 'uk_account_number' | 'us_account_number' | 'tokenized' | 'other') | undefined, bank_code: string, bank_code_format?: ('bic' | 'uk_sorting_code' | 'us_aba_routing_number' | 'tokenized' | 'other') | undefined, fi_bank_code?: string | undefined, holder_name: string, holder_address?: CommonAddress | undefined, bank_name?: string | undefined, bank_address?: CommonAddress | undefined, creditor_identifier?: string | undefined, organization_identification?: OrganizationIdentification | undefined, private_identification?: PrivateIdentification | undefined}; export type PaymentOrderUltimateOriginator = {holder_name?: string | undefined, holder_address?: CommonAddress | undefined, organization_identification?: OrganizationIdentification | undefined, private_identification?: PrivateIdentification | undefined}; export type PaymentOrderReceivingAccount = {account_number?: string | undefined, account_number_format?: ('iban' | 'uk_account_number' | 'us_account_number' | 'tokenized' | 'other') | undefined, bank_code: string, bank_code_format?: ('bic' | 'uk_sorting_code' | 'us_aba_routing_number' | 'tokenized' | 'other') | undefined, fi_bank_code?: string | undefined, holder_name: string, holder_address?: CommonAddress | undefined, bank_name?: string | undefined, bank_address?: CommonAddress | undefined, organization_identification?: OrganizationIdentification | undefined, private_identification?: PrivateIdentification | undefined}; export type PaymentOrderUltimateReceiver = {holder_name?: string | undefined, holder_address?: CommonAddress | undefined, organization_identification?: OrganizationIdentification | undefined, private_identification?: PrivateIdentification | undefined}; export type PaymentOrderDirectDebitMandate = {reference?: string | undefined, signature_date?: string | undefined, type?: ('sepa_core' | 'sepa_b2b' | 'bacs_debit') | undefined, sequence?: ('one_off' | 'recurring') | undefined, frequency?: ('one_off' | 'recurring') | undefined}; export type PaymentOrderDirectDebitSequenceType = 'first' | 'recurring' | 'final' | 'one_off' | null; export type CommonAgentOtherIdentification = {identification?: string | undefined, identification_type?: OrganizationIdentificationOthersType | undefined, custom_identification_type?: string | undefined, identification_issuer?: string | undefined}; export type CommonAgentFinancialInstitutionIdentification = {swift_code?: string | undefined, bank_code?: string | undefined, bank_code_format?: ('bic' | 'uk_sorting_code' | 'us_aba_routing_number' | 'tokenized' | 'other') | undefined, name?: string | undefined, legal_entity_identifier?: string | undefined, postal_address?: CommonAddress | undefined, other?: CommonAgentOtherIdentification | undefined}; export type CommonIntermediaryAgents = Array<{financial_institution_identification: CommonAgentFinancialInstitutionIdentification, account_number?: string | undefined, account_number_format?: string | undefined, organization_identification?: ({name?: string | undefined, bank_code?: string | undefined, legal_entity_identifier?: string | undefined, other?: string | undefined}) | undefined, postal_address?: CommonAddress | undefined}>; export type CommonPreviousInstructingAgents = Array<{financial_institution_identification: CommonAgentFinancialInstitutionIdentification, account_number?: string | undefined, account_number_format?: string | undefined, organization_identification?: ({name?: string | undefined, bank_code?: string | undefined, legal_entity_identifier?: string | undefined, other?: string | undefined}) | undefined, postal_address?: CommonAddress | undefined}>; export type PaymentOrderSettlementInformation = {settlement_account: string}; export type CommonCustomFields = Record; export type PaymentOrderCreationDetails = {type: PaymentType, direction: 'credit' | 'debit', amount: number, currency: string, reference: string, end_to_end_id?: string | undefined, connected_account_id: string, originating_account?: PaymentOrderOriginatingAccount | undefined, originating_account_id?: string | undefined, ultimate_originator?: PaymentOrderUltimateOriginator | undefined, receiving_account?: PaymentOrderReceivingAccount | undefined, receiving_account_id?: string | undefined, ultimate_receiver?: PaymentOrderUltimateReceiver | undefined, direct_debit_mandate?: PaymentOrderDirectDebitMandate | undefined, direct_debit_mandate_id?: string | undefined, direct_debit_sequence_type?: PaymentOrderDirectDebitSequenceType | undefined, initiated_at?: string | undefined, intermediary_agents?: CommonIntermediaryAgents | undefined, previous_instructing_agents?: CommonPreviousInstructingAgents | undefined, uetr?: string | undefined, purpose?: string | undefined, category_purpose_code?: string | undefined, fee_option?: ('originator' | 'receiver' | 'shared') | undefined, routing_instruction?: string | undefined, instructed_agent?: string | undefined, addressee_bank_code?: string | undefined, requested_execution_date?: string | undefined, auto_approval?: boolean | undefined, retry_details?: ({payment_retry_rule_id?: string | undefined}) | undefined, treasury_option?: ('local' | 'international' | 'relocated' | 'safeguarding') | undefined, confidentiality_option?: 'payroll' | undefined, settlement_method?: ('cover' | 'instructed_agent' | 'instructing_agent') | undefined, settlement_information?: PaymentOrderSettlementInformation | undefined, fi_to_fi_option?: ('advi' | 'core' | 'cover') | undefined, related_payment_id?: string | undefined, cbs_transfer_allowed?: boolean | undefined, lending?: ({context?: ('disbursement' | 'repayment') | undefined, credit_arrangement_id?: string | undefined, loan_ids?: Array | undefined}) | undefined, metadata?: Record | undefined, custom_fields?: CommonCustomFields | undefined}; export type CreateApiPaymentOrdersArgs = {'Idempotency-Key'?: string | undefined, body: PaymentOrderCreationDetails}; export type CreateApiPaymentOrdersOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const paymentType = z.enum(["ae_aani", "ae_uaefts", "ae_uaefts_rtgs", "ar_coelsa", "ar_mep", "ar_transfer_30", "au_becs", "au_npp", "au_rits", "bacs", "becs", "bh_benefit", "bh_fawri", "bh_rtgs", "br_pix", "br_str", "br_ted", "ca_eft", "ca_lynx", "ca_rtr", "cbs_transfer", "ch_sct", "ch_sic", "ch_sip", "chaps", "cl_cca", "cl_lbtr", "cl_tef", "co_ach", "co_bre_b", "co_cud", "fps", "icelandic_exp", "id_bifast", "id_birtgs", "id_sknbi", "internal_transfer", "ke_eft", "ke_pesalink", "ke_rtgs", "mx_spei", "my_duitnow", "my_ibg", "my_rentas", "no_nbo", "no_nics", "no_nics_instant", "osko", "ph_instapay", "ph_pddts", "ph_philpass", "pl_elixir", "pl_express_elixir", "pl_sorbnet", "rits", "ro_regis", "ro_sent", "ro_sent_instant", "sa_sarie", "sa_sarie_instant", "sa_sarie_rtgs", "se_bankgirot", "se_rix", "se_rix_instant", "sepa", "sepa_instant", "sepa_urgent", "sg_giro", "sg_meps", "sg_paynow", "swift", "swift_fi_to_fi", "target2", "target2_fi_to_fi", "th_bahtnet", "th_nitmx", "th_promptpay", "tl_ips", "tl_rtimor_ach", "tl_rtimor_rtgs", "treasury", "us_ach", "us_fednow", "us_rtp", "us_wire", "za_eft", "za_rpp", "za_samos"]); export const commonAddress = z.object({line_1: z.string().optional(), line_2: z.string().optional(), building_number: z.string().optional(), street_name: z.string().optional(), postal_code: z.string().optional(), region_state: z.string().optional(), city: z.string().optional(), country: z.string().optional(), department: z.string().nullable().optional(), sub_department: z.string().nullable().optional(), building_name: z.string().nullable().optional(), floor: z.string().nullable().optional(), postal_box: z.string().nullable().optional(), room: z.string().nullable().optional(), city_location_name: z.string().nullable().optional(), district_name: z.string().nullable().optional()}); export const organizationIdentificationOthersType = z.enum(["bank_identification", "central_bank_identification", "clearing_house_identification", "company_incorporation_number", "company_identification", "customer_number", "duns_number", "employee_number", "global_location_number", "siren", "siret", "tax_number", "telephone_number", "business_domain_identification", "other_identification", "unknown"]); export const organizationIdentification = z.object({legal_entity_identifier: z.string().optional(), business_identification_code: z.string().optional(), default_other_identifier_type: organizationIdentificationOthersType.optional(), others: z.array(z.object({type: organizationIdentificationOthersType, value: z.string()})).optional()}); export const privateIdentificationOtherIdentificationType = z.enum(["alien_registration_number", "passport_number", "customer_identification_number", "drivers_license_number", "employee_identification_number", "national_identity_number", "social_security_number", "telephone_number", "tax_identification_number", "person_commercial_identification"]); export const privateIdentification = z.object({birth_date: z.string().optional(), birth_city: z.string().max(35).optional(), birth_country: z.string().max(2).optional(), other: z.object({identification: z.string().max(35).optional(), identification_type: privateIdentificationOtherIdentificationType.optional(), custom_identification_type: z.string().max(35).optional(), identification_issuer: z.string().max(35).optional()}).optional()}); export const paymentOrderOriginatingAccount = z.object({account_number: z.string().optional(), account_number_format: z.enum(["iban", "uk_account_number", "us_account_number", "tokenized", "other"]).optional(), bank_code: z.string(), bank_code_format: z.enum(["bic", "uk_sorting_code", "us_aba_routing_number", "tokenized", "other"]).optional(), fi_bank_code: z.string().optional(), holder_name: z.string(), holder_address: commonAddress.optional(), bank_name: z.string().optional(), bank_address: commonAddress.optional(), creditor_identifier: z.string().max(35).optional(), organization_identification: organizationIdentification.optional(), private_identification: privateIdentification.optional()}); export const paymentOrderUltimateOriginator = z.object({holder_name: z.string().optional(), holder_address: commonAddress.optional(), organization_identification: organizationIdentification.optional(), private_identification: privateIdentification.optional()}); export const paymentOrderReceivingAccount = z.object({account_number: z.string().optional(), account_number_format: z.enum(["iban", "uk_account_number", "us_account_number", "tokenized", "other"]).optional(), bank_code: z.string(), bank_code_format: z.enum(["bic", "uk_sorting_code", "us_aba_routing_number", "tokenized", "other"]).optional(), fi_bank_code: z.string().optional(), holder_name: z.string(), holder_address: commonAddress.optional(), bank_name: z.string().optional(), bank_address: commonAddress.optional(), organization_identification: organizationIdentification.optional(), private_identification: privateIdentification.optional()}); export const paymentOrderUltimateReceiver = z.object({holder_name: z.string().optional(), holder_address: commonAddress.optional(), organization_identification: organizationIdentification.optional(), private_identification: privateIdentification.optional()}); export const paymentOrderDirectDebitMandate = z.object({reference: z.string().max(35).optional(), signature_date: z.string().optional(), type: z.enum(["sepa_core", "sepa_b2b", "bacs_debit"]).optional(), sequence: z.enum(["one_off", "recurring"]).optional(), frequency: z.enum(["one_off", "recurring"]).optional()}); export const paymentOrderDirectDebitSequenceType = z.enum(["first", "recurring", "final", "one_off"]).nullable(); export const commonAgentOtherIdentification = z.object({identification: z.string().max(35).optional(), identification_type: organizationIdentificationOthersType.optional(), custom_identification_type: z.string().max(35).optional(), identification_issuer: z.string().max(35).optional()}); export const commonAgentFinancialInstitutionIdentification = z.object({swift_code: z.string().optional(), bank_code: z.string().optional(), bank_code_format: z.enum(["bic", "uk_sorting_code", "us_aba_routing_number", "tokenized", "other"]).optional(), name: z.string().max(140).optional(), legal_entity_identifier: z.string().optional(), postal_address: commonAddress.optional(), other: commonAgentOtherIdentification.optional()}); export const commonIntermediaryAgents = z.array(z.object({financial_institution_identification: commonAgentFinancialInstitutionIdentification, account_number: z.string().optional(), account_number_format: z.string().optional(), organization_identification: z.object({name: z.string().optional(), bank_code: z.string().optional(), legal_entity_identifier: z.string().optional(), other: z.string().optional()}).optional(), postal_address: commonAddress.optional()})); export const commonPreviousInstructingAgents = z.array(z.object({financial_institution_identification: commonAgentFinancialInstitutionIdentification, account_number: z.string().optional(), account_number_format: z.string().optional(), organization_identification: z.object({name: z.string().optional(), bank_code: z.string().optional(), legal_entity_identifier: z.string().optional(), other: z.string().optional()}).optional(), postal_address: commonAddress.optional()})); export const paymentOrderSwiftGpiDetails = z.object({status: z.enum(["created", "in_progress", "received", "rejected"]).optional(), confirmed_at: z.string().optional(), confirmed_amount: z.number().int().gte(0).optional(), confirmed_currency: z.string().optional(), tracking_progress: z.array(z.object({id: z.string(), processed_at: z.string(), status: z.enum(["executed", "received", "rejected"]), status_details: z.string().optional(), bank_code: z.string(), fee_amount: z.number().int().gte(0), fee_currency: z.string()})).optional()}); export const commonPaymentValidationResult = z.object({payment_validation_rule_id: z.string(), status: z.enum(["in_progress", "successful", "failed"]), validations: z.array(z.array(z.object({type: z.enum(["internal_account_is_active", "direct_debit_mandate_is_active", "liquidity_screening", "sanctions_screening", "risk_screening", "limits_screening", "mambu_authorization"]), status: z.enum(["queued", "in_progress", "successful", "failed", "canceled", "pending_investigation", "pending_retry", "technical_error"]), status_details: z.string().optional(), resource_id: z.string().optional(), resource_url: z.string().optional(), mode: z.enum(["pre_built", "custom"]).optional(), last_updated_at: z.string().optional(), retry_details: z.object({attempt_count: z.number().int().gte(1).lte(5).optional(), max_attempts: z.number().int().gte(1).lte(5).optional(), next_attempt_at: z.string().nullable().optional(), final_action: z.enum(["approve_payment", "cancel_payment", "confirm_payment", "reject_payment", "set_payment_to_received", "set_payment_to_pending_confirmation", "suspend_payment"]).optional()}).nullable().optional()})))}); export const commonCbsTransaction = z.object({id: z.string().optional(), type: z.enum(["deposit", "withdrawal", "disbursement", "repayment", "adjustment"]).optional(), context: z.enum(["deposit", "suspense", "disbursement", "repayment"]).optional(), payment_validation_type: z.enum(["internal_account_is_active", "direct_debit_mandate_is_active", "liquidity_screening", "sanctions_screening", "risk_screening", "limits_screening", "mambu_authorization"]).optional(), account_id: z.string().optional(), authorization_id: z.string().optional(), external_id: z.string().optional(), channel: z.string().optional(), booked_at: z.string().optional()}); export const commonCbsData = z.object({transaction_id: z.string().optional(), authorization_id: z.string().optional(), transactions: z.array(commonCbsTransaction).optional()}); export const paymentOrderRetryDetails = z.object({payment_retry_rule_id: z.string().optional(), original_payment_id: z.string().optional(), retried_from_payment_id: z.string().optional(), retried_to_payment_id: z.string().optional(), retry_scheduled_at: z.string().optional()}); export const paymentOrderSettlementInformation = z.object({settlement_account: z.string()}); export const commonCustomFields = z.object({}); export const paymentOrderDetails = z.object({id: z.string(), idempotency_key: z.string(), object: z.string(), type: paymentType, direction: z.enum(["credit", "debit"]), amount: z.number().int().gte(0), currency: z.literal("EUR"), value_date: z.string(), status: z.string(), status_details: z.string(), reconciled_amount: z.number().int().gte(0), reconciliation_status: z.enum(["partially_reconciled", "reconciled", "unreconciled", "excluded"]), reference: z.string().max(140), end_to_end_id: z.string().max(35).optional(), connected_account_id: z.string(), originating_account: paymentOrderOriginatingAccount, originating_account_id: z.string().optional(), ultimate_originator: paymentOrderUltimateOriginator.optional(), receiving_account: paymentOrderReceivingAccount, receiving_account_id: z.string().optional(), ultimate_receiver: paymentOrderUltimateReceiver.optional(), direct_debit_mandate: paymentOrderDirectDebitMandate.optional(), direct_debit_mandate_id: z.string().optional(), direct_debit_sequence_type: paymentOrderDirectDebitSequenceType.optional(), intermediary_agents: commonIntermediaryAgents.optional(), previous_instructing_agents: commonPreviousInstructingAgents.optional(), uetr: z.string().optional(), swift_gpi: paymentOrderSwiftGpiDetails.optional(), purpose: z.string().optional(), category_purpose_code: z.string().optional(), fee_option: z.enum(["originator", "receiver", "shared"]).optional(), routing_instruction: z.string().optional(), requested_execution_date: z.string().optional(), auto_approval: z.boolean(), payment_validation: z.object({status: z.enum(["in_progress", "successful", "failed"]), validation_results: z.array(commonPaymentValidationResult)}).optional(), cbs_data: commonCbsData.optional(), retry_details: paymentOrderRetryDetails.optional(), treasury_option: z.enum(["local", "international", "relocated", "safeguarding"]).optional(), confidentiality_option: z.literal("payroll").optional(), settlement_method: z.enum(["cover", "instructed_agent", "instructing_agent"]).optional(), settlement_information: paymentOrderSettlementInformation.optional(), fi_to_fi_option: z.enum(["advi", "core", "cover"]).optional(), related_payment_id: z.string().optional(), related_payment_type: z.string().optional(), metadata: z.object({}), custom_fields: commonCustomFields, bank_data: z.object({file_id: z.string(), message_id: z.string(), transaction_id: z.string(), end_to_end_id: z.string()}), initiated_at: z.string().optional(), instructed_agent: z.string().nullable().optional(), addressee_bank_code: z.string().nullable().optional(), created_at: 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 }; /** * Create payment order * * POST /payment_orders */ export const createApiPaymentOrders = async (args: CreateApiPaymentOrdersArgs, options?: CreateApiPaymentOrdersOptions) => { const {baseUrl = "https://sandbox.numeral.io/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/payment_orders${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(paymentOrderDetails, await res.json()) };