import {z} from 'zod' export type CurrencyCode = string; export type AmountIntegerValueInput = {currency: CurrencyCode, value: number}; export type AmountStringValueInput = {currency: CurrencyCode, stringValue: string}; export type AmountInput = AmountIntegerValueInput | AmountStringValueInput; export type CreditTransferSchemeType = 'SCT' | 'SCT_INST' | 'CROSS_BORDER' | 'GB_CT_BACS' | 'GB_CT_CHAPS' | 'GB_CT_FPS' | 'SE_A2A' | 'SE_GIRO' | 'DK_A2A' | 'DK_CT_SAMEDAY' | 'DK_CT_INST' | 'DK_CT_FIK71' | 'DK_CT_FIK73' | 'DK_CT_FIK75' | 'DK_CT_NEMKONTO' | 'DK_CT_T2' | 'CH_CT' | 'NO_CT' | 'NO_CT_KID' | 'US_CT_ACH' | 'US_CT_WIRE' | 'IS_CT' | 'AU_CT' | 'AU_CT_BECS' | 'AU_CT_BPAY' | 'HK_CT' | 'HK_CT_CHATS' | 'HK_CT_FPS' | 'IL_CT' | 'SG_CT' | 'SG_CT_FAST' | 'SG_CT_GIRO' | 'SG_CT_MEPS' | 'BG_CT' | 'CL_CT' | 'CO_CT' | 'CR_CT' | 'CZ_CT' | 'MX_CT' | 'MX_CT_SPID' | 'MX_CT_SPEI' | 'MX_CT_TEF' | 'MY_CT_IBG' | 'MY_CT_JOMPAY' | 'MY_CT_RENTAS' | 'KR_CT' | 'TW_CT_ACH' | 'TW_CT_FISC' | 'TH_CT' | 'TH_CT_BAHTNET' | 'TH_CT_SMART' | 'CA_CT_LYNX' | 'CA_CT_ACSS' | 'PE_CT' | 'PL_CT' | 'RO_CT' | 'TR_CT' | 'AE_CT' | 'AE_CT_IPI' | 'DE_CT' | 'FR_CT' | 'IN_IMPS' | 'IN_NEFT' | 'IN_RTGS' | 'BR_CT_PIX' | 'BR_CT_TED' | 'BOOK_TRANSFER' | 'CN_CT_BEPS' | 'CN_CT_HVPS' | 'VN_CT' | 'PH_CT_PESONET' | 'PH_CT_INSTAPAY' | 'PH_CT_PHILPASS' | 'PH_CT_PDDTS' | 'RS_CT' | 'JP_CT' | 'MU_CT' | 'KE_CT_RTGS' | 'GE_CT_RTGS' | 'ZA_CT_EFT' | 'BD_CT_BEFTN' | 'BD_CT_RTGS' | 'MA_CT' | 'SA_CT_SARIE' | 'HU_CT_VIBER' | 'HU_CT_GIRO'; export type InstrumentType = 'US_ACH' | 'CITI_WORLDLINK'; export type InstrumentInput = {type: InstrumentType}; export type SchemeDetailsUrgency = 'HIGH'; export type SchemeDetailsInput = {instrument?: InstrumentInput | undefined, intraCompany?: boolean | undefined, urgency?: SchemeDetailsUrgency | undefined}; export type Date = string; export type AccountType = 'ACCOUNT' | 'EXTERNAL_ACCOUNT' | 'INLINE'; export type InternalAccountRef = {type: AccountType, id: string}; export type ExternalAccountRef = {type: AccountType, id: string}; export type MarketCode = string; export type AccountIdentifierType = 'IBAN' | 'NUMBER' | 'ADYEN' | 'AU_BPAY_BILLER_CODE' | 'DK_FIK' | 'INVESTMENT_NUMBER' | 'MY_JOMPAY_BILLER_CODE' | 'NATIONAL_ID_NUMBER' | 'PAYPAL' | 'PROPRIETARY' | 'SE_BANKGIRO' | 'SE_PLUSGIRO' | 'SOLDO' | 'WALLET_ADYEN_BALANCE_PLATFORM' | 'WALLET_AIRWALLEX' | 'WALLET_AIRWALLEX_NUMBER' | 'WALLET_CURRENCYCLOUD' | 'WALLET_FLASH_PAYMENTS' | 'WALLET_FREEMARKET' | 'WALLET_HYPERWALLET' | 'WALLET_INPAY' | 'WALLET_LEAD' | 'WALLET_MERCURY' | 'WALLET_MONEYCORP' | 'WALLET_PAYHAWK' | 'WALLET_REVOLUT' | 'WALLET_SKRILL' | 'WALLET_STRIPE' | 'WALLET_SWISSQUOTE' | 'WALLET_UNIT'; export type AccountIdentifier = {type: AccountIdentifierType, market: MarketCode, number: string, invalid?: boolean | undefined}; export type RoutingIdentifierType = 'BIC' | 'AT_BLZ' | 'AU_BSB' | 'BD_BRN' | 'BR_BRANCH' | 'BR_COMPE' | 'BR_ISP' | 'CA_CPA' | 'CH_BCC' | 'CH_SIC' | 'CL_SBIF' | 'CN_APS' | 'CZ_NBC' | 'DE_BLZ' | 'ES_NCC' | 'GB_DSC' | 'GR_BIC' | 'HK_NCC' | 'IE_NCC' | 'IL_NCC' | 'IN_FSC' | 'IT_NCC' | 'JP_ZGN' | 'KR_BOK' | 'KR_KFTC' | 'MX_ABM' | 'MY_NCC' | 'NZ_NCC' | 'PH_BRSTN' | 'PL_KNR' | 'PT_NCC' | 'RU_CBC' | 'SE_SBA' | 'SG_IBG' | 'TH_CBC' | 'TW_NCC' | 'US_ABA' | 'US_PID' | 'VN_CITAD' | 'ZA_NCC'; export type RoutingConstraints = {accountNumberType?: AccountIdentifierType | undefined, scheme?: string | undefined}; export type RoutingIdentifier = {type: RoutingIdentifierType, number: string, invalid?: boolean | undefined, constraints?: RoutingConstraints | undefined}; export type ExternalID = string; export type PartyType = 'INDIVIDUAL' | 'COMPANY'; export type CountryCode = string; export type CountrySubdivision = string; export type Address = {country?: CountryCode | undefined, countrySubdivision?: CountrySubdivision | undefined, city?: string | undefined, postalCode?: string | undefined, streetName?: string | undefined, streetNumber?: string | undefined}; export type NationalIdentifier = {type: 'CIVIC' | 'COMPANY', market: MarketCode, number: string}; export type InlineAccountHolder = {externalId?: ExternalID | undefined, legalName: string, partyType?: PartyType | undefined, address?: Address | undefined, nationalIdentifier?: NationalIdentifier | undefined, email?: string | undefined, phone?: string | undefined}; export type InlineExternalAccount = {type: AccountType, market: MarketCode, identifiers: Array, routing?: Array | undefined, externalId?: ExternalID | undefined, holder: InlineAccountHolder}; export type CreditTransferDestination = InternalAccountRef | ExternalAccountRef | InlineExternalAccount; export type PaymentReference = string; export type RemittanceType = 'STRUCTURED' | 'UNSTRUCTURED' | 'CREDITOR_REFERENCE'; export type CategoryPurpose = string; export type ChargeBearer = 'SHARED' | 'DEBTOR' | 'CREDITOR' | 'SERVICE_LEVEL'; export type RegulatoryReportingIndicator = 'CREDITOR' | 'DEBTOR' | 'BOTH'; export type RegulatoryReportingDetails = {market: MarketCode, indicator: RegulatoryReportingIndicator, code: string}; export type TaxDetailsType = 'PL_MPP'; export type TaxDetailsInput = {type: TaxDetailsType, amount: AmountInput, creditorId?: string | undefined, invoiceNumber?: string | undefined}; export type FXRate = {value: string, unitCurrency?: CurrencyCode | undefined}; export type FXInstruction = {reference?: string | undefined, rate?: FXRate | undefined, additionalInfo?: string | undefined}; export type Metadata = {[key: string]: string} | null; export type ResourceID = string; export type CreateCreditTransferRequest = {amount: AmountInput, scheme: CreditTransferSchemeType, schemeDetails?: SchemeDetailsInput | undefined, date: Date, source: InternalAccountRef, destination: CreditTransferDestination, reference: PaymentReference, referenceType?: RemittanceType | undefined, categoryPurpose?: CategoryPurpose | undefined, chargeBearer?: ChargeBearer | undefined, regulatoryReporting?: Array | undefined, taxDetails?: TaxDetailsInput | undefined, fxInstruction?: FXInstruction | undefined, externalId?: ExternalID | undefined, metadata?: Metadata | undefined, paymentScheduleId?: ResourceID | undefined}; export type CreateApiPaymentsV2CreditTransfersArgs = {body: CreateCreditTransferRequest}; export type CreateApiPaymentsV2CreditTransfersOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const resourceID = z.string().min(32).max(64); export const organizationID = z.string(); export const currencyCode = z.string().min(3).max(3); export const amount = z.object({currency: currencyCode, stringValue: z.string(), value: z.number().int()}); export const creditTransferSchemeType = z.enum(["SCT", "SCT_INST", "CROSS_BORDER", "GB_CT_BACS", "GB_CT_CHAPS", "GB_CT_FPS", "SE_A2A", "SE_GIRO", "DK_A2A", "DK_CT_SAMEDAY", "DK_CT_INST", "DK_CT_FIK71", "DK_CT_FIK73", "DK_CT_FIK75", "DK_CT_NEMKONTO", "DK_CT_T2", "CH_CT", "NO_CT", "NO_CT_KID", "US_CT_ACH", "US_CT_WIRE", "IS_CT", "AU_CT", "AU_CT_BECS", "AU_CT_BPAY", "HK_CT", "HK_CT_CHATS", "HK_CT_FPS", "IL_CT", "SG_CT", "SG_CT_FAST", "SG_CT_GIRO", "SG_CT_MEPS", "BG_CT", "CL_CT", "CO_CT", "CR_CT", "CZ_CT", "MX_CT", "MX_CT_SPID", "MX_CT_SPEI", "MX_CT_TEF", "MY_CT_IBG", "MY_CT_JOMPAY", "MY_CT_RENTAS", "KR_CT", "TW_CT_ACH", "TW_CT_FISC", "TH_CT", "TH_CT_BAHTNET", "TH_CT_SMART", "CA_CT_LYNX", "CA_CT_ACSS", "PE_CT", "PL_CT", "RO_CT", "TR_CT", "AE_CT", "AE_CT_IPI", "DE_CT", "FR_CT", "IN_IMPS", "IN_NEFT", "IN_RTGS", "BR_CT_PIX", "BR_CT_TED", "BOOK_TRANSFER", "CN_CT_BEPS", "CN_CT_HVPS", "VN_CT", "PH_CT_PESONET", "PH_CT_INSTAPAY", "PH_CT_PHILPASS", "PH_CT_PDDTS", "RS_CT", "JP_CT", "MU_CT", "KE_CT_RTGS", "GE_CT_RTGS", "ZA_CT_EFT", "BD_CT_BEFTN", "BD_CT_RTGS", "MA_CT", "SA_CT_SARIE", "HU_CT_VIBER", "HU_CT_GIRO"]); export const instrumentType = z.enum(["US_ACH", "CITI_WORLDLINK"]); export const instrument = z.discriminatedUnion("type", [z.object({type: instrumentType, citiWorldlinkId: z.string()}), z.object({type: instrumentType, usAchCompanyId: z.string(), usAchCompanyName: z.string().optional(), usAchImmediateOrigin: z.string().optional()})]); export const schemeDetailsUrgency = z.literal("HIGH"); export const schemeDetails = z.object({instrument: instrument.optional(), intraCompany: z.boolean().optional(), initiatorId: z.string().optional(), urgency: schemeDetailsUrgency.optional()}); export const date = z.string(); export const paymentStatus = z.enum(["CREATED", "APPROVED", "REJECTED", "PENDING_SUBMISSION", "SENT", "PENDING_AT_BANK", "ACCEPTED", "EXECUTED", "FAILED", "RETURNED", "UNKNOWN"]); export const paymentStatusReason = z.object({code: z.string().optional(), description: z.string().optional()}); export const accountType = z.enum(["ACCOUNT", "EXTERNAL_ACCOUNT", "INLINE"]); export const marketCode = z.string().min(2).max(2); export const accountIdentifierType = z.enum(["IBAN", "NUMBER", "ADYEN", "AU_BPAY_BILLER_CODE", "DK_FIK", "INVESTMENT_NUMBER", "MY_JOMPAY_BILLER_CODE", "NATIONAL_ID_NUMBER", "PAYPAL", "PROPRIETARY", "SE_BANKGIRO", "SE_PLUSGIRO", "SOLDO", "WALLET_ADYEN_BALANCE_PLATFORM", "WALLET_AIRWALLEX", "WALLET_AIRWALLEX_NUMBER", "WALLET_CURRENCYCLOUD", "WALLET_FLASH_PAYMENTS", "WALLET_FREEMARKET", "WALLET_HYPERWALLET", "WALLET_INPAY", "WALLET_LEAD", "WALLET_MERCURY", "WALLET_MONEYCORP", "WALLET_PAYHAWK", "WALLET_REVOLUT", "WALLET_SKRILL", "WALLET_STRIPE", "WALLET_SWISSQUOTE", "WALLET_UNIT"]); export const accountIdentifier = z.object({type: accountIdentifierType, market: marketCode, number: z.string().min(1).max(255), invalid: z.boolean().optional()}); export const routingIdentifierType = z.enum(["BIC", "AT_BLZ", "AU_BSB", "BD_BRN", "BR_BRANCH", "BR_COMPE", "BR_ISP", "CA_CPA", "CH_BCC", "CH_SIC", "CL_SBIF", "CN_APS", "CZ_NBC", "DE_BLZ", "ES_NCC", "GB_DSC", "GR_BIC", "HK_NCC", "IE_NCC", "IL_NCC", "IN_FSC", "IT_NCC", "JP_ZGN", "KR_BOK", "KR_KFTC", "MX_ABM", "MY_NCC", "NZ_NCC", "PH_BRSTN", "PL_KNR", "PT_NCC", "RU_CBC", "SE_SBA", "SG_IBG", "TH_CBC", "TW_NCC", "US_ABA", "US_PID", "VN_CITAD", "ZA_NCC"]); export const routingConstraints = z.object({accountNumberType: accountIdentifierType.optional(), scheme: z.string().optional()}); export const routingIdentifier = z.object({type: routingIdentifierType, number: z.string().min(1).max(255), invalid: z.boolean().optional(), constraints: routingConstraints.optional()}); export const accountSnapshot = z.object({type: accountType, id: resourceID, organizationId: organizationID, market: marketCode, identifiers: z.array(accountIdentifier), routing: z.array(routingIdentifier), currency: currencyCode}); export const externalID = z.string(); export const countryCode = z.string().min(2).max(2); export const countrySubdivision = z.string().max(6); export const address = z.object({country: countryCode.optional(), countrySubdivision: countrySubdivision.optional(), city: z.string().max(64).optional(), postalCode: z.string().max(16).optional(), streetName: z.string().max(64).optional(), streetNumber: z.string().max(16).optional()}); export const nationalIdentifier = z.object({type: z.enum(["CIVIC", "COMPANY"]), market: marketCode, number: z.string()}); export const partyType = z.enum(["INDIVIDUAL", "COMPANY"]); export const accountHolder = z.object({type: z.enum(["COUNTERPARTY", "ENTITY", "INLINE"]), id: z.string().optional(), externalId: externalID.optional(), legalName: z.string(), address: address.optional(), nationalIdentifier: nationalIdentifier.optional(), partyType: partyType.optional(), email: z.string().optional(), phone: z.string().optional()}); export const externalAccountSnapshot = z.object({type: accountType, id: resourceID, externalId: externalID.optional(), organizationId: organizationID, market: marketCode, identifiers: z.array(accountIdentifier), routing: z.array(routingIdentifier).optional()}); export const inlineExternalAccountSnapshot = z.object({type: accountType, organizationId: organizationID, market: marketCode, identifiers: z.array(accountIdentifier), routing: z.array(routingIdentifier).optional()}); export const approvalStatus = z.enum(["PENDING", "APPROVED", "REJECTED"]); export const userAuditInfo = z.object({id: resourceID, username: z.string(), name: z.string().optional(), roleId: z.string().optional()}); export const paymentApprovalStep = z.object({id: z.string(), approvalChainId: z.string(), requiredRoleIds: z.array(z.string()).optional(), status: approvalStatus, approver: userAuditInfo.optional(), updated: z.string().optional(), autoApproved: z.boolean(), allowCreatorApproval: z.boolean().optional(), sequentialApproval: z.boolean().optional(), sequenceNumber: z.number().int().optional()}); export const attachedTransactionRef = z.object({type: z.literal("TRANSACTION"), id: z.string()}); export const paymentReference = z.string().max(140); export const remittanceType = z.enum(["STRUCTURED", "UNSTRUCTURED", "CREDITOR_REFERENCE"]); export const categoryPurpose = z.string(); export const chargeBearer = z.enum(["SHARED", "DEBTOR", "CREDITOR", "SERVICE_LEVEL"]); export const regulatoryReportingIndicator = z.enum(["CREDITOR", "DEBTOR", "BOTH"]); export const regulatoryReportingDetails = z.object({market: marketCode, indicator: regulatoryReportingIndicator, code: z.string()}); export const taxDetailsType = z.literal("PL_MPP"); export const taxDetails = z.object({type: taxDetailsType, amount: amount, creditorId: z.string().optional(), invoiceNumber: z.string().optional()}); export const fXRate = z.object({value: z.string(), unitCurrency: currencyCode.optional()}); export const fXInstruction = z.object({reference: z.string().optional(), rate: fXRate.optional(), additionalInfo: z.string().optional()}); export const batchTreatmentType = z.enum(["INDIVIDUAL_PAYMENTS", "BATCH"]); export const batchDetails = z.object({id: resourceID, treatment: batchTreatmentType}); export const eTag = z.string(); export const metadata = z.record(z.string(), z.string()).nullable(); export const resourceVersion = z.number().int().gte(1); export const createdTimestamp = z.string(); export const updatedTimestamp = z.string(); export const creditTransfer = z.object({id: resourceID, organizationId: organizationID, creatorUserId: resourceID.optional(), amount: amount, scheme: creditTransferSchemeType, schemeDetails: schemeDetails.optional(), date: date, status: paymentStatus, statusReason: paymentStatusReason.optional(), source: accountSnapshot, sourceHolder: accountHolder, destination: z.discriminatedUnion("type", [externalAccountSnapshot, accountSnapshot, inlineExternalAccountSnapshot]), destinationHolder: accountHolder, approvalSteps: z.array(paymentApprovalStep), attachedTransactions: z.array(attachedTransactionRef), reference: paymentReference, referenceType: remittanceType.optional(), categoryPurpose: categoryPurpose.optional(), chargeBearer: chargeBearer.optional(), regulatoryReporting: z.array(regulatoryReportingDetails).optional(), taxDetails: taxDetails.optional(), fxInstruction: fXInstruction.optional(), connectionInstructionId: z.string().optional(), batch: batchDetails.optional(), paymentScheduleId: resourceID.optional(), etag: eTag, externalId: externalID.optional(), metadata: metadata.optional(), version: resourceVersion, created: createdTimestamp, updated: updatedTimestamp}); 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 credit transfer * * POST /payments/v2/credit-transfers */ export const createApiPaymentsV2CreditTransfers = async (args: CreateApiPaymentsV2CreditTransfersArgs, options?: CreateApiPaymentsV2CreditTransfersOptions) => { const {baseUrl = "https://api.atlar.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/payments/v2/credit-transfers${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(creditTransfer, await res.json()) };