import {z} from 'zod' export type ConsentId = string; export type DebtorName = string; export type Iban = string; export type OtherAccountIdentification1CH = string; export type CurrencyCode = string; export type CashAccountType = string; export type AccountReference16CH = {iban?: Iban | undefined, otherAccountIdentification?: OtherAccountIdentification1CH | undefined, currency?: CurrencyCode | undefined, cashAccountType?: CashAccountType | undefined}; export type DebtorId = string; export type Bicfi = string; export type InstitutionalIdentification2 = {clearingSystemIdCode: string, clearingSystemMemberId: string}; export type DebtorAgent7CH = {bic?: Bicfi | undefined, iid?: InstitutionalIdentification2 | undefined}; export type UltimateDebtor = string; export type AmountValue = string; export type Amount = {currency: CurrencyCode, amount: AmountValue}; export type ExchangeRateInformation1 = {exchangeRate?: string | undefined, contractIdentification?: string | undefined, rateType?: ('SPOT' | 'SALE' | 'AGRD') | undefined}; export type CountryCode = string; export type PostalAddress6CH = {streetName?: string | undefined, buildingNumber?: string | undefined, townName?: string | undefined, postCode?: string | undefined, country?: CountryCode | undefined, addressLine1?: string | undefined, addressLine2?: string | undefined}; export type CreditorAgent7CH = {bic?: Bicfi | undefined, iid?: InstitutionalIdentification2 | undefined, name?: string | undefined, address?: PostalAddress6CH | undefined}; export type CreditorAgentName = string; export type CreditorName = string; export type CreditorId = string; export type Address = {streetName?: string | undefined, buildingNumber?: string | undefined, townName?: string | undefined, postCode?: string | undefined, country: CountryCode}; export type CreditorNameAndAddress = string; export type UltimateCreditor = string; export type PurposeCode = 'SALA' | 'PENS'; export type ExternalServiceLevel1Code = 'SEPA' | 'PRPT' | 'SDVA' | 'URGP'; export type ChargeBearer = 'DEBT' | 'CRED' | 'SHAR' | 'SLEV'; export type RemittanceInformationUnstructured = string; export type RemittanceInformationStructured = {reference: string, referenceType?: string | undefined, referenceIssuer?: string | undefined, SCORorQRRorIPI?: ('SCOR' | 'QRR' | 'IPI') | undefined, additionalRemittanceInformation?: string | undefined}; export type PaymentInitiationJson = {endToEndIdentification: string, debtorName: DebtorName, debtorAccount: AccountReference16CH, debtorId?: DebtorId | undefined, debtorAgent?: DebtorAgent7CH | undefined, ultimateDebtor?: UltimateDebtor | undefined, instructedAmount?: Amount | undefined, equivalentAmount?: Amount | undefined, transactionCurrency?: CurrencyCode | undefined, exchangeRateInformation?: ExchangeRateInformation1 | undefined, creditorAccount: AccountReference16CH, creditorAgent?: CreditorAgent7CH | undefined, creditorAgentName?: CreditorAgentName | undefined, creditorName: CreditorName, creditorId?: CreditorId | undefined, creditorAddress?: Address | undefined, creditorNameAndAddress?: CreditorNameAndAddress | undefined, ultimateCreditor?: UltimateCreditor | undefined, purposeCode?: PurposeCode | undefined, serviceLevel?: ExternalServiceLevel1Code | undefined, chargeBearer?: ChargeBearer | undefined, remittanceInformationUnstructured?: RemittanceInformationUnstructured | undefined, remittanceInformationStructured?: RemittanceInformationStructured | undefined, requestedExecutionDate: string, intermediaryAgent?: Bicfi | undefined}; export type StartDate = string; export type EndDate = string; export type ExecutionRule = 'following' | 'preceding'; export type FrequencyCode = 'Daily' | 'Weekly' | 'EveryTwoWeeks' | 'Monthly' | 'EveryTwoMonths' | 'Quarterly' | 'SemiAnnual' | 'Annual' | 'MonthlyVariable'; export type DayOfExecution = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '28' | '29' | '30' | '31'; export type PeriodicPaymentInitiationJson = {endToEndIdentification: string, debtorName: DebtorName, debtorAccount: AccountReference16CH, debtorId?: DebtorId | undefined, debtorAgent?: DebtorAgent7CH | undefined, ultimateDebtor?: UltimateDebtor | undefined, instructedAmount?: Amount | undefined, equivalentAmount?: Amount | undefined, transactionCurrency?: CurrencyCode | undefined, exchangeRateInformation?: ExchangeRateInformation1 | undefined, creditorAccount: AccountReference16CH, creditorAgent?: CreditorAgent7CH | undefined, creditorAgentName?: CreditorAgentName | undefined, creditorName: CreditorName, creditorId?: CreditorId | undefined, creditorAddress?: Address | undefined, creditorNameAndAddress?: CreditorNameAndAddress | undefined, ultimateCreditor?: UltimateCreditor | undefined, purposeCode?: PurposeCode | undefined, serviceLevel?: ExternalServiceLevel1Code | undefined, chargeBearer?: ChargeBearer | undefined, remittanceInformationUnstructured?: RemittanceInformationUnstructured | undefined, remittanceInformationStructured?: RemittanceInformationStructured | undefined, intermediaryAgent?: Bicfi | undefined, startDate: StartDate, endDate?: EndDate | undefined, executionRule?: ExecutionRule | undefined, frequency: FrequencyCode, dayOfExecution?: DayOfExecution | undefined}; export type BatchBookingPreferred = boolean; export type PaymentInitiationBulkElementJson = {endToEndIdentification: string, debtorName: DebtorName, debtorId?: DebtorId | undefined, ultimateDebtor?: UltimateDebtor | undefined, instructedAmount?: Amount | undefined, equivalentAmount?: Amount | undefined, transactionCurrency?: CurrencyCode | undefined, exchangeRateInformation?: ExchangeRateInformation1 | undefined, creditorAccount: AccountReference16CH, creditorAgent?: CreditorAgent7CH | undefined, creditorAgentName?: CreditorAgentName | undefined, creditorName: CreditorName, creditorId?: CreditorId | undefined, creditorAddress?: Address | undefined, creditorNameAndAddress?: CreditorNameAndAddress | undefined, ultimateCreditor?: UltimateCreditor | undefined, purposeCode?: PurposeCode | undefined, serviceLevel?: ExternalServiceLevel1Code | undefined, chargeBearer?: ChargeBearer | undefined, remittanceInformationUnstructured?: RemittanceInformationUnstructured | undefined, remittanceInformationStructured?: RemittanceInformationStructured | undefined, intermediaryAgent?: Bicfi | undefined}; export type BulkPaymentInitiationJson = {batchBookingPreferred?: BatchBookingPreferred | undefined, debtorAccount: AccountReference16CH, debtorAgent: DebtorAgent7CH, requestedExecutionDate?: string | undefined, requestedExecutionTime?: string | undefined, payments: Array}; export type CreateApiV1PaymentServicePaymentProductArgs = {'payment-service': 'payments' | 'bulk-payments' | 'periodic-payments', 'payment-product': 'domestic-swiss-credit-transfers-isr' | 'domestic-swiss-credit-transfers' | 'domestic-swiss-credit-transfers-qr' | 'domestic-swiss-foreign-credit-transfers' | 'swiss-sepa-credit-transfers' | 'swiss-cross-border-credit-transfers' | 'pain.001-sepa-credit-transfers' | 'pain.001-cross-border-credit-transfers' | 'pain.001-swiss-six-credit-transfers', 'X-Request-ID': string, Digest?: string | undefined, Signature?: string | undefined, 'TPP-Signature-Certificate'?: string | undefined, 'PSU-ID'?: string | undefined, 'PSU-ID-Type'?: string | undefined, 'PSU-Corporate-ID'?: string | undefined, 'PSU-Corporate-ID-Type'?: string | undefined, 'Consent-ID'?: ConsentId | undefined, 'PSU-IP-Address': string, 'TPP-Redirect-Preferred'?: boolean | undefined, 'TPP-Redirect-URI'?: string | undefined, 'TPP-Nok-Redirect-URI'?: string | undefined, 'TPP-Explicit-Authorisation-Preferred'?: boolean | undefined, 'TPP-Rejection-NoFunds-Preferred'?: boolean | undefined, 'TPP-Brand-Logging-Information'?: string | undefined, 'TPP-Notification-URI'?: string | undefined, 'TPP-Notification-Content-Preferred'?: string | undefined, 'PSU-IP-Port'?: string | undefined, 'PSU-Accept'?: string | undefined, 'PSU-Accept-Charset'?: string | undefined, 'PSU-Accept-Encoding'?: string | undefined, 'PSU-Accept-Language'?: string | undefined, 'PSU-User-Agent'?: string | undefined, 'PSU-Http-Method'?: ('GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE') | undefined, 'PSU-Device-ID'?: string | undefined, 'PSU-Geo-Location'?: string | undefined, body: PaymentInitiationJson | PeriodicPaymentInitiationJson | BulkPaymentInitiationJson}; export type CreateApiV1PaymentServicePaymentProductOptions = {baseUrl?: string | undefined, BearerAuthOAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionStatus = z.enum(["ACCC", "ACCP", "ACSC", "ACSP", "ACTC", "ACWC", "ACWP", "RCVD", "PDNG", "RJCT", "CANC", "ACFC", "PATC", "PART"]); export const paymentId = z.string(); export const currencyCode = z.string(); export const amountValue = z.string(); export const amount = z.object({currency: currencyCode, amount: amountValue}); export const transactionFeeIndicator = z.boolean(); export const authenticationType = z.enum(["SMS_OTP", "CHIP_OTP", "PHOTO_OTP", "PUSH_OTP", "SMTP_OTP"]); export const authenticationMethodId = z.string().max(35); export const authenticationObject = z.object({authenticationType: authenticationType, authenticationVersion: z.string().optional(), authenticationMethodId: authenticationMethodId, name: z.string().optional(), explanation: z.string().optional()}); export const scaMethods = z.array(authenticationObject); export const chosenScaMethod = z.object({authenticationType: authenticationType, authenticationVersion: z.string().optional(), authenticationMethodId: authenticationMethodId, name: z.string().optional(), explanation: z.string().optional()}); export const challengeData = z.object({image: z.string().optional(), data: z.array(z.string()).optional(), imageLink: z.string().optional(), otpMaxLength: z.number().int().optional(), otpFormat: z.enum(["characters", "integer"]).optional(), additionalInformation: z.string().optional()}); export const hrefEntry = z.string(); export const hrefType = z.object({href: hrefEntry.optional()}); export const linksPaymentInitiation = z.object({scaRedirect: hrefType.optional(), scaOAuth: hrefType.optional(), confirmation: hrefType.optional(), startAuthorisation: hrefType.optional(), startAuthorisationWithPsuIdentification: hrefType.optional(), startAuthorisationWithPsuAuthentication: hrefType.optional(), startAuthorisationWithEncryptedPsuAuthentication: hrefType.optional(), startAuthorisationWithAuthenticationMethodSelection: hrefType.optional(), startAuthorisationWithTransactionAuthorisation: hrefType.optional(), self: hrefType.optional(), status: hrefType.optional(), scaStatus: hrefType.optional()}).and(z.record(z.string(), hrefType)); export const psuMessageText = z.string().max(500); export const tppMessageCategory = z.enum(["ERROR", "WARNING"]); export const messageCode2XX = z.literal("WARNING"); export const tppMessageText = z.string().max(500); export const tppMessage2XX = z.object({category: tppMessageCategory, code: messageCode2XX, path: z.string().optional(), text: tppMessageText.optional()}); export const paymentInitationRequestResponse201 = z.object({transactionStatus: transactionStatus, paymentId: paymentId, transactionFees: amount.optional(), currencyConversionFee: amount.optional(), estimatedTotalAmount: amount.optional(), estimatedInterbankSettlementAmount: amount.optional(), transactionFeeIndicator: transactionFeeIndicator.optional(), scaMethods: scaMethods.optional(), chosenScaMethod: chosenScaMethod.optional(), challengeData: challengeData.optional(), _links: linksPaymentInitiation, psuMessage: psuMessageText.optional(), tppMessages: z.array(tppMessage2XX).optional()}); 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 }; /** * Payment initiation request * * POST /v1/{payment-service}/{payment-product} */ export const createApiV1PaymentServicePaymentProduct = async (args: CreateApiV1PaymentServicePaymentProductArgs, options?: CreateApiV1PaymentServicePaymentProductOptions) => { const {baseUrl = "https://api.dev.openbankingproject.ch", fetch: fetchFn = fetch, BearerAuthOAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Request-ID'] != null) headers.set("X-Request-ID", String(args['X-Request-ID'])) if (args.Digest != null) headers.set("Digest", String(args.Digest)) if (args.Signature != null) headers.set("Signature", String(args.Signature)) if (args['TPP-Signature-Certificate'] != null) headers.set("TPP-Signature-Certificate", String(args['TPP-Signature-Certificate'])) if (args['PSU-ID'] != null) headers.set("PSU-ID", String(args['PSU-ID'])) if (args['PSU-ID-Type'] != null) headers.set("PSU-ID-Type", String(args['PSU-ID-Type'])) if (args['PSU-Corporate-ID'] != null) headers.set("PSU-Corporate-ID", String(args['PSU-Corporate-ID'])) if (args['PSU-Corporate-ID-Type'] != null) headers.set("PSU-Corporate-ID-Type", String(args['PSU-Corporate-ID-Type'])) if (args['Consent-ID'] != null) headers.set("Consent-ID", String(args['Consent-ID'])) if (args['PSU-IP-Address'] != null) headers.set("PSU-IP-Address", String(args['PSU-IP-Address'])) if (args['TPP-Redirect-Preferred'] != null) headers.set("TPP-Redirect-Preferred", String(args['TPP-Redirect-Preferred'])) if (args['TPP-Redirect-URI'] != null) headers.set("TPP-Redirect-URI", String(args['TPP-Redirect-URI'])) if (args['TPP-Nok-Redirect-URI'] != null) headers.set("TPP-Nok-Redirect-URI", String(args['TPP-Nok-Redirect-URI'])) if (args['TPP-Explicit-Authorisation-Preferred'] != null) headers.set("TPP-Explicit-Authorisation-Preferred", String(args['TPP-Explicit-Authorisation-Preferred'])) if (args['TPP-Rejection-NoFunds-Preferred'] != null) headers.set("TPP-Rejection-NoFunds-Preferred", String(args['TPP-Rejection-NoFunds-Preferred'])) if (args['TPP-Brand-Logging-Information'] != null) headers.set("TPP-Brand-Logging-Information", String(args['TPP-Brand-Logging-Information'])) if (args['TPP-Notification-URI'] != null) headers.set("TPP-Notification-URI", String(args['TPP-Notification-URI'])) if (args['TPP-Notification-Content-Preferred'] != null) headers.set("TPP-Notification-Content-Preferred", String(args['TPP-Notification-Content-Preferred'])) if (args['PSU-IP-Port'] != null) headers.set("PSU-IP-Port", String(args['PSU-IP-Port'])) if (args['PSU-Accept'] != null) headers.set("PSU-Accept", String(args['PSU-Accept'])) if (args['PSU-Accept-Charset'] != null) headers.set("PSU-Accept-Charset", String(args['PSU-Accept-Charset'])) if (args['PSU-Accept-Encoding'] != null) headers.set("PSU-Accept-Encoding", String(args['PSU-Accept-Encoding'])) if (args['PSU-Accept-Language'] != null) headers.set("PSU-Accept-Language", String(args['PSU-Accept-Language'])) if (args['PSU-User-Agent'] != null) headers.set("PSU-User-Agent", String(args['PSU-User-Agent'])) if (args['PSU-Http-Method'] != null) headers.set("PSU-Http-Method", String(args['PSU-Http-Method'])) if (args['PSU-Device-ID'] != null) headers.set("PSU-Device-ID", String(args['PSU-Device-ID'])) if (args['PSU-Geo-Location'] != null) headers.set("PSU-Geo-Location", String(args['PSU-Geo-Location'])) if (BearerAuthOAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuthOAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args['payment-service']))}/${encodeURIComponent(String(args['payment-product']))}${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(paymentInitationRequestResponse201, await res.json()) };