import {z} from 'zod' export type GetApiVariableRecurringPaymentsCommercialConsentsConsentIdArgs = {consentId: string}; export type GetApiVariableRecurringPaymentsCommercialConsentsConsentIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const responseMeta = z.object({tracingId: z.string().optional()}); export const authorisationStatus = z.enum(["AWAITING_AUTHORIZATION", "AWAITING_FURTHER_AUTHORIZATION", "AWAITING_RE_AUTHORIZATION", "AUTHORIZED", "CONSUMED", "REJECTED", "REVOKED", "FAILED", "EXPIRED", "UNKNOWN", "INVALID", "AWAITING_DECOUPLED_PRE_AUTHORIZATION", "AWAITING_PRE_AUTHORIZATION", "PRE_AUTHORIZED", "AWAITING_DECOUPLED_AUTHORIZATION", "AWAITING_SCA_METHOD", "AWAITING_SCA_CODE"]); export const featureEnum = z.enum(["INITIATE_PRE_AUTHORISATION", "INITIATE_PRE_AUTHORISATION_ACCOUNTS", "INITIATE_PRE_AUTHORISATION_PAYMENTS", "INITIATE_ACCOUNT_REQUEST", "INITIATE_EMBEDDED_ACCOUNT_REQUEST", "ACCOUNT_REQUEST_DETAILS", "ACCOUNTS", "ACCOUNT", "ACCOUNT_TRANSACTIONS", "ACCOUNT_STATEMENTS", "ACCOUNT_STATEMENT", "ACCOUNT_STATEMENT_FILE", "ACCOUNT_SCHEDULED_PAYMENTS", "ACCOUNT_DIRECT_DEBITS", "ACCOUNT_PERIODIC_PAYMENTS", "ACCOUNT_TRANSACTIONS_WITH_MERCHANT", "IDENTITY", "ACCOUNTS_WITHOUT_BALANCE", "ACCOUNT_WITHOUT_BALANCE", "ACCOUNT_BALANCES", "INITIATE_SINGLE_PAYMENT_SORTCODE", "EXISTING_PAYMENT_INITIATION_DETAILS", "CREATE_SINGLE_PAYMENT_SORTCODE", "EXISTING_PAYMENTS_DETAILS", "INITIATE_DOMESTIC_SINGLE_PAYMENT", "INITIATE_EMBEDDED_DOMESTIC_SINGLE_PAYMENT", "CREATE_DOMESTIC_SINGLE_PAYMENT", "INITIATE_EMBEDDED_BULK_PAYMENT", "INITIATE_DOMESTIC_SINGLE_INSTANT_PAYMENT", "CREATE_DOMESTIC_SINGLE_INSTANT_PAYMENT", "INITIATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT", "CREATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT", "INITIATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT_SWEEPING", "CREATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT_SWEEPING", "INITIATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT_COMMERCIAL", "CREATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT_COMMERCIAL", "INITIATE_DOMESTIC_SCHEDULED_PAYMENT", "CREATE_DOMESTIC_SCHEDULED_PAYMENT", "INITIATE_DOMESTIC_PERIODIC_PAYMENT", "CREATE_DOMESTIC_PERIODIC_PAYMENT", "PERIODIC_PAYMENT_FREQUENCY_EXTENDED", "INITIATE_INTERNATIONAL_SCHEDULED_PAYMENT", "CREATE_INTERNATIONAL_SCHEDULED_PAYMENT", "INITIATE_INTERNATIONAL_PERIODIC_PAYMENT", "CREATE_INTERNATIONAL_PERIODIC_PAYMENT", "INITIATE_INTERNATIONAL_SINGLE_PAYMENT", "CREATE_INTERNATIONAL_SINGLE_PAYMENT", "INITIATE_BULK_PAYMENT", "CREATE_BULK_PAYMENT", "EXISTING_BULK_PAYMENT_DETAILS", "TRANSFER", "OPEN_DATA_PERSONAL_CURRENT_ACCOUNTS", "OPEN_DATA_ATMS", "READ_DOMESTIC_SINGLE_REFUND", "READ_DOMESTIC_SCHEDULED_REFUND", "READ_DOMESTIC_PERIODIC_PAYMENT_REFUND", "READ_INTERNATIONAL_SINGLE_REFUND", "READ_INTERNATIONAL_SCHEDULED_REFUND", "ACCOUNT_BENEFICIARIES", "INITIATE_ONETIME_PRE_AUTHORISATION_PAYMENTS", "INITIATE_ONETIME_PRE_AUTHORISATION_ACCOUNTS", "INITIATE_ONETIME_PRE_AUTHORISATION", "VARIABLE_RECURRING_PAYMENT_FUNDS_CONFIRMATION"]); export const amount = z.object({amount: z.number(), currency: z.string()}); export const vrpPeriodicLimits = z.object({frequency: z.string(), totalMaxAmount: amount, alignment: z.string()}); export const vrpControlParameters = z.object({psuAuthenticationMethods: z.array(z.string()), maxAmountPerPayment: amount, periodicLimits: z.array(vrpPeriodicLimits), validFrom: z.string().optional(), validTo: z.string().optional()}); export const accountIdentificationType = z.enum(["SORT_CODE", "ACCOUNT_NUMBER", "IBAN", "BBAN", "BIC", "PAN", "MASKED_PAN", "MSISDN", "BSB", "NCC", "ABA", "ABA_WIRE", "ABA_ACH", "EMAIL", "ROLL_NUMBER", "BLZ", "IFS", "CLABE", "CTN", "BRANCH_CODE", "VIRTUAL_ACCOUNT_ID"]); export const accountIdentification = z.object({type: accountIdentificationType, identification: z.string()}); export const addressTypeEnum = z.enum(["BUSINESS", "CORRESPONDENCE", "DELIVERY_TO", "MAIL_TO", "PO_BOX", "POSTAL", "RESIDENTIAL", "STATEMENT", "UNKNOWN"]); export const address = z.object({addressLines: z.array(z.string()).optional(), streetName: z.string().optional(), buildingNumber: z.string().optional(), postCode: z.string().optional(), townName: z.string().optional(), county: z.array(z.string()).optional(), country: z.string().optional(), department: z.string().optional(), subDepartment: z.string().optional(), addressType: addressTypeEnum.optional()}); export const payer = z.object({name: z.string().optional(), accountIdentifications: z.array(accountIdentification), address: address.optional()}); export const vrpUltimatePayer = z.object({name: z.string().optional(), accountIdentifications: z.array(accountIdentification).optional(), legalEntityIdentification: z.string().optional(), address: address.optional()}); export const payeeAccountType = z.string(); export const payee = z.object({name: z.string(), accountIdentifications: z.array(accountIdentification), accountType: payeeAccountType.optional(), address: address.optional(), merchantId: z.string().optional(), merchantCategoryCode: z.string().optional()}); export const vrpUltimatePayee = z.object({name: z.string().optional(), accountIdentifications: z.array(accountIdentification).optional(), legalEntityIdentification: z.string().optional(), accountType: payeeAccountType.optional(), address: address.optional(), merchantId: z.string().optional(), merchantCategoryCode: z.string().optional()}); export const vrpInitiationDetails = z.object({reference: z.string().optional(), payer: payer.optional(), ultimatePayer: vrpUltimatePayer.optional(), payee: payee.optional(), ultimatePayee: vrpUltimatePayee.optional()}); export const vrpCommercialRiskDetails = z.object({paymentContextCode: z.string(), paymentPurposeCode: z.string(), categoryPurposeCode: z.string(), merchantCustomerId: z.string(), isContractPresent: z.boolean(), isPayeePrepopulated: z.boolean(), payeeAccountType: z.string().optional()}); export const vrpCommercialAuthorisationResponse = z.object({id: z.string().optional(), userUuid: z.string().optional(), applicationUserId: z.string().optional(), institutionId: z.string().optional(), status: authorisationStatus.optional(), createdAt: z.string().optional(), featureScope: z.array(featureEnum).optional(), consentToken: z.string().optional(), state: z.string().optional(), authorizedAt: z.string().optional(), institutionConsentId: z.string().optional(), authorisationUrl: z.string().optional(), qrCodeUrl: z.string().optional(), controlParameters: vrpControlParameters.optional(), initiationDetails: vrpInitiationDetails.optional(), riskDetails: vrpCommercialRiskDetails.optional()}); export const responseForwardedData = z.object({headers: z.record(z.string(), z.string()).optional(), url: z.string().optional()}); export const rawRequest = z.object({method: z.string().optional(), url: z.string().optional(), requestInstant: z.string().optional(), headers: z.record(z.string(), z.string()).optional(), body: z.object({}).optional(), bodyParameters: z.record(z.string(), z.string()).optional(), startTime: z.string().optional(), startedAt: z.string().optional()}); export const rawResponse = z.object({request: rawRequest.optional(), duration: z.string().optional(), headers: z.record(z.string(), z.string()).optional(), resultCode: z.number().int().optional(), result: z.object({}).optional()}); export const apiResponseOfVrpCommercialAuthorisationResponse = z.object({meta: responseMeta.optional(), data: vrpCommercialAuthorisationResponse.optional(), links: z.record(z.string(), z.string()).optional(), forwardedData: z.array(responseForwardedData).optional(), tracingId: z.string().optional(), raw: z.array(rawResponse).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 }; /** * Get Commercial VRP Consent Details * * GET /variable-recurring-payments/commercial/consents/{consentId} */ export const getApiVariableRecurringPaymentsCommercialConsentsConsentId = async (args: GetApiVariableRecurringPaymentsCommercialConsentsConsentIdArgs, options?: GetApiVariableRecurringPaymentsCommercialConsentsConsentIdOptions) => { const {baseUrl = "https://api.yapily.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json;charset=UTF-8") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/variable-recurring-payments/commercial/consents/${encodeURIComponent(String(args.consentId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(apiResponseOfVrpCommercialAuthorisationResponse, await res.json()) };