@develit-services/bank 5.6.1 → 5.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/base.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { uuidv4, first, buildMultiFilterConditions as buildMultiFilterConditions$1, bankAccountMetadataSchema, structuredAddressSchema, workflowInstanceStatusSchema, develitWorker, createInternalError, action, service } from '@develit-io/backend-sdk';
2
- import { G as tables, g as accountInsertSchema, H as relations, o as isProcessedStatus, p as isTerminalStatus, L as getNonTerminalPaymentRequestsQuery, x as toIncomingPayment, N as calculateCzechIban, j as assignAccount, u as toBatchedPayment, y as toPaymentRequestInsert, a as FinbricksClient, F as FINBRICKS_ENDPOINTS } from './shared/bank.BZkc4e0m.mjs';
2
+ import { G as tables, g as accountInsertSchema, H as relations, o as isProcessedStatus, p as isTerminalStatus, L as getNonTerminalPaymentRequestsQuery, x as toIncomingPayment, N as calculateCzechIban, j as assignAccount, u as toBatchedPayment, y as toPaymentRequestInsert, a as FinbricksClient, F as FINBRICKS_ENDPOINTS } from './shared/bank.BVXtqHnq.mjs';
3
3
  import { eq, sql, and, like, asc, desc, inArray, gte, lte, isNull, count } from 'drizzle-orm';
4
4
  import { WorkerEntrypoint } from 'cloudflare:workers';
5
5
  import { drizzle } from 'drizzle-orm/d1';
6
6
  import 'jose';
7
- import { h as encrypt, d as createCredentialsResolver, i as initiateConnector, e as updatePaymentRequestStatusCommand, a as getPaymentRequestsByBatchIdQuery, g as getBatchByIdQuery, u as upsertBatchCommand, j as importAesKey, f as createPaymentCommand, b as getAccountByIdQuery } from './shared/bank.toAgXBfS.mjs';
7
+ import { h as encrypt, d as createCredentialsResolver, i as initiateConnector, e as updatePaymentRequestStatusCommand, a as getPaymentRequestsByBatchIdQuery, g as getBatchByIdQuery, u as upsertBatchCommand, j as importAesKey, f as createPaymentCommand, b as getAccountByIdQuery } from './shared/bank.DLU1sOBm.mjs';
8
8
  import { z } from 'zod';
9
9
  import { I as INSTRUCTION_PRIORITIES, C as CHARGE_BEARERS, g as PAYMENT_TYPES, b as CONNECTOR_KEYS, a as BATCH_STATUSES, f as PAYMENT_STATUSES, P as PAYMENT_DIRECTIONS, e as PAYMENT_REQUEST_STATUSES } from './shared/bank.BzDNLxB_.mjs';
10
10
  import { CURRENCY_CODES } from '@develit-io/general-codes';
@@ -733,6 +733,11 @@ const getAccountBalanceInputSchema = z.object({
733
733
  accountId: z.string().uuid()
734
734
  });
735
735
 
736
+ const closePaymentRequestInputSchema = z.object({
737
+ paymentRequestId: z.string(),
738
+ statusReason: z.string().optional()
739
+ });
740
+
736
741
  var __defProp = Object.defineProperty;
737
742
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
738
743
  var __decorateClass = (decorators, target, key, kind) => {
@@ -750,6 +755,9 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
750
755
  // ── Unified status resolution ──────────────────────────────────────
751
756
  this.POLLING_TIMEOUT_MS = 14 * 24 * 60 * 60 * 1e3;
752
757
  // 14 days
758
+ // OPENED = authorization never completed; auth links are short-lived, so close much sooner
759
+ this.OPENED_TIMEOUT_MS = 48 * 60 * 60 * 1e3;
760
+ // 48 hours
753
761
  this.COMPLETED_POLLING_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
754
762
  this.allowedProviders = config.allowedProviders;
755
763
  this.db = drizzle(this.env.BANK_D1, { schema: tables, relations });
@@ -1095,13 +1103,16 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1095
1103
  console.log("[updatePaymentRequestStatuses] By connector", byConnector);
1096
1104
  const now = Date.now();
1097
1105
  const pollableIds = [];
1106
+ const closedEvents = [];
1098
1107
  for (const pr of nonTerminalPRs) {
1099
1108
  const status = pr.status;
1100
1109
  if (isTerminalStatus(status, pr.connectorKey)) {
1101
1110
  continue;
1102
1111
  }
1103
1112
  if (status === "OPENED" || status === "AUTHORIZED") {
1104
- if (pr.createdAt != null && now - pr.createdAt.getTime() > this.POLLING_TIMEOUT_MS) {
1113
+ const timeoutMs = status === "OPENED" ? this.OPENED_TIMEOUT_MS : this.POLLING_TIMEOUT_MS;
1114
+ const statusReason = status === "OPENED" ? "Authorization not completed within 48 hours" : "Polling timeout: no final status received after 14 days";
1115
+ if (pr.createdAt != null && now - pr.createdAt.getTime() > timeoutMs) {
1105
1116
  console.warn(
1106
1117
  "[updatePaymentRequestStatuses] Closing PR due to timeout",
1107
1118
  {
@@ -1113,17 +1124,42 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1113
1124
  age: `${Math.floor((now - pr.createdAt.getTime()) / (24 * 60 * 60 * 1e3))} days`
1114
1125
  }
1115
1126
  );
1127
+ const processedAt = /* @__PURE__ */ new Date();
1116
1128
  await updatePaymentRequestStatusCommand(this.db, {
1117
1129
  id: pr.id,
1118
1130
  status: "CLOSED",
1119
- statusReason: "Polling timeout: no final status received after 14 days",
1120
- processedAt: /* @__PURE__ */ new Date()
1131
+ statusReason,
1132
+ processedAt
1121
1133
  }).command.execute();
1134
+ closedEvents.push(
1135
+ buildPaymentRequestEvent({
1136
+ ...pr,
1137
+ status: "CLOSED",
1138
+ statusReason,
1139
+ processedAt
1140
+ })
1141
+ );
1122
1142
  continue;
1123
1143
  }
1124
1144
  pollableIds.push(pr.id);
1125
1145
  }
1126
1146
  }
1147
+ if (closedEvents.length > 0) {
1148
+ try {
1149
+ await this.pushToQueue(
1150
+ this.env.QUEUE_BUS_QUEUE,
1151
+ closedEvents
1152
+ );
1153
+ } catch (err) {
1154
+ console.error(
1155
+ "[updatePaymentRequestStatuses] Failed to push timeout-close events to queue",
1156
+ {
1157
+ eventCount: closedEvents.length,
1158
+ error: err instanceof Error ? err.message : String(err)
1159
+ }
1160
+ );
1161
+ }
1162
+ }
1127
1163
  const result = await this._resolvePaymentRequestStatuses(pollableIds);
1128
1164
  const duration = Date.now() - startTime;
1129
1165
  console.log("[updatePaymentRequestStatuses] Completed", {
@@ -1216,6 +1252,18 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1216
1252
  });
1217
1253
  const result = connector.parseAuthorizationCallback(callbackUrl);
1218
1254
  if (!result.success) {
1255
+ if (paymentRequestId) {
1256
+ try {
1257
+ await updatePaymentRequestStatusCommand(this.db, {
1258
+ id: paymentRequestId,
1259
+ statusReason: `Authorization error: ${result.error}`
1260
+ }).command.execute();
1261
+ } catch (err) {
1262
+ this.logError({
1263
+ message: `[handleAuthorizationCallback] Failed to persist error reason for PR ${paymentRequestId}: ${err}`
1264
+ });
1265
+ }
1266
+ }
1219
1267
  return {
1220
1268
  paymentsUpdated: 0,
1221
1269
  batchId: null,
@@ -1244,6 +1292,87 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1244
1292
  }
1245
1293
  );
1246
1294
  }
1295
+ async closePaymentRequest(input) {
1296
+ return this.handleAction(
1297
+ { data: input, schema: closePaymentRequestInputSchema },
1298
+ { successMessage: "Payment request closed" },
1299
+ async ({ paymentRequestId, statusReason }) => {
1300
+ const pr = await getPaymentRequestByIdQuery(this.db, {
1301
+ paymentRequestId
1302
+ });
1303
+ if (!pr) {
1304
+ throw createInternalError(null, {
1305
+ message: `Payment request ${paymentRequestId} not found`,
1306
+ code: "DB-B-011",
1307
+ status: 404
1308
+ });
1309
+ }
1310
+ if (pr.status !== "OPENED") {
1311
+ throw createInternalError(null, {
1312
+ message: `Only OPENED payment requests can be closed (current status: ${pr.status})`,
1313
+ code: "DB-B-012",
1314
+ status: 400
1315
+ });
1316
+ }
1317
+ let bankStatus = null;
1318
+ try {
1319
+ const connector = await this._initiateBankConnector({
1320
+ connectorKey: pr.connectorKey
1321
+ });
1322
+ bankStatus = await connector.getPaymentStatus({
1323
+ paymentId: pr.bankRefId ?? pr.id
1324
+ });
1325
+ } catch (err) {
1326
+ this.logError({
1327
+ message: `[closePaymentRequest] Status re-poll failed for PR ${pr.id}, closing anyway: ${err}`
1328
+ });
1329
+ }
1330
+ if (bankStatus && bankStatus !== "OPENED") {
1331
+ await this._resolvePaymentRequestStatuses([pr.id]);
1332
+ throw createInternalError(null, {
1333
+ message: `Payment request is no longer OPENED at the bank (current status: ${bankStatus})`,
1334
+ code: "DB-B-013",
1335
+ status: 409
1336
+ });
1337
+ }
1338
+ const processedAt = /* @__PURE__ */ new Date();
1339
+ const reason = statusReason ?? "Closed by operator";
1340
+ const updated = first(
1341
+ await updatePaymentRequestStatusCommand(this.db, {
1342
+ id: pr.id,
1343
+ status: "CLOSED",
1344
+ statusReason: reason,
1345
+ processedAt
1346
+ }).command.execute()
1347
+ );
1348
+ try {
1349
+ await this.pushToQueue(
1350
+ this.env.QUEUE_BUS_QUEUE,
1351
+ [
1352
+ buildPaymentRequestEvent({
1353
+ ...pr,
1354
+ status: "CLOSED",
1355
+ statusReason: reason,
1356
+ processedAt
1357
+ })
1358
+ ]
1359
+ );
1360
+ } catch (err) {
1361
+ this.logError({
1362
+ message: `[closePaymentRequest] Failed to push close event for PR ${pr.id}: ${err}`
1363
+ });
1364
+ }
1365
+ return {
1366
+ paymentRequest: updated ?? {
1367
+ ...pr,
1368
+ status: "CLOSED",
1369
+ statusReason: reason,
1370
+ processedAt
1371
+ }
1372
+ };
1373
+ }
1374
+ );
1375
+ }
1247
1376
  async processBatch(input) {
1248
1377
  return this.handleAction(
1249
1378
  { data: input, schema: processBatchInputSchema },
@@ -2096,6 +2225,9 @@ __decorateClass([
2096
2225
  __decorateClass([
2097
2226
  action("handle-authorization-callback")
2098
2227
  ], BankServiceBase.prototype, "handleAuthorizationCallback", 1);
2228
+ __decorateClass([
2229
+ action("close-payment-request")
2230
+ ], BankServiceBase.prototype, "closePaymentRequest", 1);
2099
2231
  __decorateClass([
2100
2232
  action("process-batch")
2101
2233
  ], BankServiceBase.prototype, "processBatch", 1);
@@ -1,4 +1,4 @@
1
- export { aB as account, aC as accountCredentials, aD as batch, aE as ott, aF as payment, aG as paymentRequest } from '../shared/bank.CGVCfq1B.cjs';
1
+ export { aC as account, aD as accountCredentials, aE as batch, aF as ott, aG as payment, aH as paymentRequest } from '../shared/bank.BQwwtIR4.cjs';
2
2
  import 'drizzle-orm/sqlite-core';
3
3
  import 'drizzle-orm';
4
4
  import '@develit-io/general-codes';
@@ -1,4 +1,4 @@
1
- export { aB as account, aC as accountCredentials, aD as batch, aE as ott, aF as payment, aG as paymentRequest } from '../shared/bank.CGVCfq1B.mjs';
1
+ export { aC as account, aD as accountCredentials, aE as batch, aF as ott, aG as payment, aH as paymentRequest } from '../shared/bank.BQwwtIR4.mjs';
2
2
  import 'drizzle-orm/sqlite-core';
3
3
  import 'drizzle-orm';
4
4
  import '@develit-io/general-codes';
@@ -1,4 +1,4 @@
1
- export { aB as account, aC as accountCredentials, aD as batch, aE as ott, aF as payment, aG as paymentRequest } from '../shared/bank.CGVCfq1B.js';
1
+ export { aC as account, aD as accountCredentials, aE as batch, aF as ott, aG as payment, aH as paymentRequest } from '../shared/bank.BQwwtIR4.js';
2
2
  import 'drizzle-orm/sqlite-core';
3
3
  import 'drizzle-orm';
4
4
  import '@develit-io/general-codes';
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  const backendSdk = require('@develit-io/backend-sdk');
4
- const paymentDirection = require('../shared/bank.CYnp7V23.cjs');
4
+ const paymentDirection = require('../shared/bank.CQjuudum.cjs');
5
5
  const batchLifecycle = require('../shared/bank.NF8bZBy0.cjs');
6
6
  const drizzleOrm = require('drizzle-orm');
7
- const bank = require('../shared/bank.B-7lJ4uA.cjs');
7
+ const bank = require('../shared/bank.B0DNtuUM.cjs');
8
8
  const cloudflare_workers = require('cloudflare:workers');
9
9
  const cloudflare_workflows = require('cloudflare:workflows');
10
10
  const d1 = require('drizzle-orm/d1');
@@ -1,8 +1,8 @@
1
1
  import { first, uuidv4, asNonEmpty } from '@develit-io/backend-sdk';
2
- import { G as tables, H as relations, v as toBatchedPaymentFromPaymentRequest, z as toPreparedPayment, m as isPaymentCompleted } from '../shared/bank.BZkc4e0m.mjs';
2
+ import { G as tables, H as relations, v as toBatchedPaymentFromPaymentRequest, z as toPreparedPayment, m as isPaymentCompleted } from '../shared/bank.BVXtqHnq.mjs';
3
3
  import { i as isBatchAuthorized, b as isBatchFailed, d as isBatchProcessing } from '../shared/bank.XqSw509X.mjs';
4
4
  import { eq, and, inArray } from 'drizzle-orm';
5
- import { g as getBatchByIdQuery, a as getPaymentRequestsByBatchIdQuery, c as checksum, u as upsertBatchCommand, b as getAccountByIdQuery, d as createCredentialsResolver, i as initiateConnector, e as updatePaymentRequestStatusCommand, f as createPaymentCommand } from '../shared/bank.toAgXBfS.mjs';
5
+ import { g as getBatchByIdQuery, a as getPaymentRequestsByBatchIdQuery, c as checksum, u as upsertBatchCommand, b as getAccountByIdQuery, d as createCredentialsResolver, i as initiateConnector, e as updatePaymentRequestStatusCommand, f as createPaymentCommand } from '../shared/bank.DLU1sOBm.mjs';
6
6
  import { WorkflowEntrypoint } from 'cloudflare:workers';
7
7
  import { NonRetryableError } from 'cloudflare:workflows';
8
8
  import { drizzle } from 'drizzle-orm/d1';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const drizzleOrm = require('drizzle-orm');
4
- const paymentDirection = require('./bank.CYnp7V23.cjs');
4
+ const paymentDirection = require('./bank.CQjuudum.cjs');
5
5
  const backendSdk = require('@develit-io/backend-sdk');
6
6
  require('./bank.9Yw4KHyl.cjs');
7
7
  require('date-fns');
@@ -167,6 +167,20 @@ class CreditasConnector extends paymentDirection.FinbricksConnector {
167
167
  supportsBatch() {
168
168
  return false;
169
169
  }
170
+ /**
171
+ * Creditas discards `remittanceInformation.unstructured` on outgoing SEPA and
172
+ * puts `endToEndIdentification` on the recipient's statement instead, so the
173
+ * payer's message never arrives. Omitting E2E (optional per the Finbricks
174
+ * spec) leaves the remittance as the only reference carrier.
175
+ *
176
+ * Evidenced by control payment 2026-07-27 (mtid
177
+ * 76c75147-b25b-4581-a088-31aa394877f8, build 5.7.0): sent remittance
178
+ * "interní převod DB VS2607277272" + E2E "/VS2607277272", statement showed
179
+ * "/VS2607277272" — the leading slash only ever existed in E2E.
180
+ */
181
+ buildSepaEndToEndId() {
182
+ return void 0;
183
+ }
170
184
  }
171
185
 
172
186
  class CSASConnector extends paymentDirection.FinbricksConnector {
@@ -3606,7 +3606,7 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
3606
3606
  name: string;
3607
3607
  tableName: "payment";
3608
3608
  dataType: "string enum";
3609
- data: "PROCESSING" | "BOOKED" | "REJECTED" | "PENDING" | "CANCELLED" | "SCHEDULED" | "HOLD" | "INFO";
3609
+ data: "PROCESSING" | "PENDING" | "BOOKED" | "CANCELLED" | "REJECTED" | "SCHEDULED" | "HOLD" | "INFO";
3610
3610
  driverParam: string;
3611
3611
  notNull: true;
3612
3612
  hasDefault: false;
@@ -4110,7 +4110,7 @@ declare const paymentRequest: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
4110
4110
  name: string;
4111
4111
  tableName: "payment_request";
4112
4112
  dataType: "string enum";
4113
- data: "AUTHORIZED" | "COMPLETED" | "OPENED" | "BOOKED" | "SETTLED" | "REJECTED" | "CLOSED";
4113
+ data: "AUTHORIZED" | "COMPLETED" | "BOOKED" | "REJECTED" | "OPENED" | "SETTLED" | "CLOSED";
4114
4114
  driverParam: string;
4115
4115
  notNull: true;
4116
4116
  hasDefault: false;
@@ -5391,5 +5391,5 @@ type ParsedBankPayment = {
5391
5391
  */
5392
5392
  type BatchPayment = Omit<PaymentInsertType, 'bankRefId'>;
5393
5393
 
5394
- export { IBankConnector as I, BASE_TERMINAL_STATUSES as M, BATCH_MODES as N, BATCH_STATUSES as O, CHARGE_BEARERS as X, CONNECTOR_KEYS as Y, COUNTRY_CODES as Z, CREDENTIALS_TYPES as _, INSTRUCTION_PRIORITIES as a3, PAYMENT_DIRECTIONS as a5, PAYMENT_REQUEST_STATUSES as a6, PAYMENT_STATUSES as a7, PAYMENT_TYPES as a8, isTerminalStatus as aA, account as aB, accountCredentials as aC, batch as aD, ott as aE, payment as aF, paymentRequest as aG, TOKEN_TYPES as ai, accountCredentialsInsertSchema as ak, accountCredentialsSelectSchema as al, accountCredentialsUpdateSchema as am, accountInsertSchema as an, accountSelectSchema as ao, accountUpdateSchema as ap, hasPaymentAccountAssigned as aq, isBatchAuthorized as ar, isBatchCompleted as as, isBatchFailed as at, isBatchInitiated as au, isBatchProcessing as av, isBatchReadyToSign as aw, isPaymentCompleted as ax, isPendingStatus as ay, isProcessedStatus as az, tables as t, ACCOUNT_STATUSES as y };
5395
- export type { ChargeBearer as $, AccountSelectType as A, BatchSelectType as B, ConnectorConfig as C, AccountCredentialsSelectType as D, AccountCredentialsUpdateType as E, AccountPatchType as F, AccountStatus as G, HandleAuthorizationCallbackInput as H, AccountUpdateType as J, AuthorizedBatch as K, LastSyncMetadata as L, PaymentRequestSelectType as P, BankAccountWithLastSync as Q, BankCode as R, BatchInsertType as S, BatchLifecycle as T, BatchMode as U, BatchPayment as V, BatchStatus as W, PaymentSelectType as a, CompletedBatch as a0, CountryCode as a1, CredentialsType as a2, InstructionPriority as a4, PaymentDirection as a9, PaymentFailedInsertType as aa, PaymentInsertType as ab, PaymentLifecycle as ac, PaymentPreparedInsertType as ad, PaymentStatus as ae, ProcessingBatch as af, ReadyToSignBatch as ag, ResolvedCredentials as ah, TokenType as aj, ConnectorKey as b, ConfigEnvironmentBank as c, PaymentType as d, CurrencyCode as e, HandleAuthorizationCallbackOutput as f, ConnectedAccount as g, CredentialsResolver as h, AccountCredentialsInsertType as i, AccountInsertType as j, BatchedPayment as k, InitiatedBatch as l, IncomingPayment as m, InitiatedPayment as n, ParsedBankPayment as o, PaymentRequestStatus as p, AuthorizationCallbackResult as q, BatchMetadata as r, Currency as s, AccountAssignedPayment as u, PreparedPayment as v, CompletedPayment as w, PaymentRequestInsertType as x, AccountCredentialsPatchType as z };
5394
+ export { CREDENTIALS_TYPES as $, IBankConnector as I, BASE_TERMINAL_STATUSES as N, BATCH_MODES as O, BATCH_STATUSES as Q, CHARGE_BEARERS as Y, CONNECTOR_KEYS as Z, COUNTRY_CODES as _, INSTRUCTION_PRIORITIES as a4, PAYMENT_DIRECTIONS as a6, PAYMENT_REQUEST_STATUSES as a7, PAYMENT_STATUSES as a8, PAYMENT_TYPES as a9, isProcessedStatus as aA, isTerminalStatus as aB, account as aC, accountCredentials as aD, batch as aE, ott as aF, payment as aG, paymentRequest as aH, TOKEN_TYPES as aj, accountCredentialsInsertSchema as al, accountCredentialsSelectSchema as am, accountCredentialsUpdateSchema as an, accountInsertSchema as ao, accountSelectSchema as ap, accountUpdateSchema as aq, hasPaymentAccountAssigned as ar, isBatchAuthorized as as, isBatchCompleted as at, isBatchFailed as au, isBatchInitiated as av, isBatchProcessing as aw, isBatchReadyToSign as ax, isPaymentCompleted as ay, isPendingStatus as az, tables as t, ACCOUNT_STATUSES as y };
5395
+ export type { AccountSelectType as A, BatchSelectType as B, ConnectorConfig as C, AccountCredentialsSelectType as D, EndToEndIdPayment as E, AccountCredentialsUpdateType as F, AccountPatchType as G, HandleAuthorizationCallbackInput as H, AccountStatus as J, AccountUpdateType as K, LastSyncMetadata as L, AuthorizedBatch as M, PaymentRequestSelectType as P, BankAccountWithLastSync as R, BankCode as S, BatchInsertType as T, BatchLifecycle as U, BatchMode as V, BatchPayment as W, BatchStatus as X, PaymentSelectType as a, ChargeBearer as a0, CompletedBatch as a1, CountryCode as a2, CredentialsType as a3, InstructionPriority as a5, PaymentDirection as aa, PaymentFailedInsertType as ab, PaymentInsertType as ac, PaymentLifecycle as ad, PaymentPreparedInsertType as ae, PaymentStatus as af, ProcessingBatch as ag, ReadyToSignBatch as ah, ResolvedCredentials as ai, TokenType as ak, ConnectorKey as b, ConfigEnvironmentBank as c, PaymentType as d, CurrencyCode as e, HandleAuthorizationCallbackOutput as f, ConnectedAccount as g, CredentialsResolver as h, AccountCredentialsInsertType as i, AccountInsertType as j, BatchedPayment as k, InitiatedBatch as l, IncomingPayment as m, InitiatedPayment as n, ParsedBankPayment as o, PaymentRequestStatus as p, AuthorizationCallbackResult as q, BatchMetadata as r, Currency as s, AccountAssignedPayment as u, PreparedPayment as v, CompletedPayment as w, PaymentRequestInsertType as x, AccountCredentialsPatchType as z };
@@ -3606,7 +3606,7 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
3606
3606
  name: string;
3607
3607
  tableName: "payment";
3608
3608
  dataType: "string enum";
3609
- data: "PROCESSING" | "BOOKED" | "REJECTED" | "PENDING" | "CANCELLED" | "SCHEDULED" | "HOLD" | "INFO";
3609
+ data: "PROCESSING" | "PENDING" | "BOOKED" | "CANCELLED" | "REJECTED" | "SCHEDULED" | "HOLD" | "INFO";
3610
3610
  driverParam: string;
3611
3611
  notNull: true;
3612
3612
  hasDefault: false;
@@ -4110,7 +4110,7 @@ declare const paymentRequest: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
4110
4110
  name: string;
4111
4111
  tableName: "payment_request";
4112
4112
  dataType: "string enum";
4113
- data: "AUTHORIZED" | "COMPLETED" | "OPENED" | "BOOKED" | "SETTLED" | "REJECTED" | "CLOSED";
4113
+ data: "AUTHORIZED" | "COMPLETED" | "BOOKED" | "REJECTED" | "OPENED" | "SETTLED" | "CLOSED";
4114
4114
  driverParam: string;
4115
4115
  notNull: true;
4116
4116
  hasDefault: false;
@@ -5391,5 +5391,5 @@ type ParsedBankPayment = {
5391
5391
  */
5392
5392
  type BatchPayment = Omit<PaymentInsertType, 'bankRefId'>;
5393
5393
 
5394
- export { IBankConnector as I, BASE_TERMINAL_STATUSES as M, BATCH_MODES as N, BATCH_STATUSES as O, CHARGE_BEARERS as X, CONNECTOR_KEYS as Y, COUNTRY_CODES as Z, CREDENTIALS_TYPES as _, INSTRUCTION_PRIORITIES as a3, PAYMENT_DIRECTIONS as a5, PAYMENT_REQUEST_STATUSES as a6, PAYMENT_STATUSES as a7, PAYMENT_TYPES as a8, isTerminalStatus as aA, account as aB, accountCredentials as aC, batch as aD, ott as aE, payment as aF, paymentRequest as aG, TOKEN_TYPES as ai, accountCredentialsInsertSchema as ak, accountCredentialsSelectSchema as al, accountCredentialsUpdateSchema as am, accountInsertSchema as an, accountSelectSchema as ao, accountUpdateSchema as ap, hasPaymentAccountAssigned as aq, isBatchAuthorized as ar, isBatchCompleted as as, isBatchFailed as at, isBatchInitiated as au, isBatchProcessing as av, isBatchReadyToSign as aw, isPaymentCompleted as ax, isPendingStatus as ay, isProcessedStatus as az, tables as t, ACCOUNT_STATUSES as y };
5395
- export type { ChargeBearer as $, AccountSelectType as A, BatchSelectType as B, ConnectorConfig as C, AccountCredentialsSelectType as D, AccountCredentialsUpdateType as E, AccountPatchType as F, AccountStatus as G, HandleAuthorizationCallbackInput as H, AccountUpdateType as J, AuthorizedBatch as K, LastSyncMetadata as L, PaymentRequestSelectType as P, BankAccountWithLastSync as Q, BankCode as R, BatchInsertType as S, BatchLifecycle as T, BatchMode as U, BatchPayment as V, BatchStatus as W, PaymentSelectType as a, CompletedBatch as a0, CountryCode as a1, CredentialsType as a2, InstructionPriority as a4, PaymentDirection as a9, PaymentFailedInsertType as aa, PaymentInsertType as ab, PaymentLifecycle as ac, PaymentPreparedInsertType as ad, PaymentStatus as ae, ProcessingBatch as af, ReadyToSignBatch as ag, ResolvedCredentials as ah, TokenType as aj, ConnectorKey as b, ConfigEnvironmentBank as c, PaymentType as d, CurrencyCode as e, HandleAuthorizationCallbackOutput as f, ConnectedAccount as g, CredentialsResolver as h, AccountCredentialsInsertType as i, AccountInsertType as j, BatchedPayment as k, InitiatedBatch as l, IncomingPayment as m, InitiatedPayment as n, ParsedBankPayment as o, PaymentRequestStatus as p, AuthorizationCallbackResult as q, BatchMetadata as r, Currency as s, AccountAssignedPayment as u, PreparedPayment as v, CompletedPayment as w, PaymentRequestInsertType as x, AccountCredentialsPatchType as z };
5394
+ export { CREDENTIALS_TYPES as $, IBankConnector as I, BASE_TERMINAL_STATUSES as N, BATCH_MODES as O, BATCH_STATUSES as Q, CHARGE_BEARERS as Y, CONNECTOR_KEYS as Z, COUNTRY_CODES as _, INSTRUCTION_PRIORITIES as a4, PAYMENT_DIRECTIONS as a6, PAYMENT_REQUEST_STATUSES as a7, PAYMENT_STATUSES as a8, PAYMENT_TYPES as a9, isProcessedStatus as aA, isTerminalStatus as aB, account as aC, accountCredentials as aD, batch as aE, ott as aF, payment as aG, paymentRequest as aH, TOKEN_TYPES as aj, accountCredentialsInsertSchema as al, accountCredentialsSelectSchema as am, accountCredentialsUpdateSchema as an, accountInsertSchema as ao, accountSelectSchema as ap, accountUpdateSchema as aq, hasPaymentAccountAssigned as ar, isBatchAuthorized as as, isBatchCompleted as at, isBatchFailed as au, isBatchInitiated as av, isBatchProcessing as aw, isBatchReadyToSign as ax, isPaymentCompleted as ay, isPendingStatus as az, tables as t, ACCOUNT_STATUSES as y };
5395
+ export type { AccountSelectType as A, BatchSelectType as B, ConnectorConfig as C, AccountCredentialsSelectType as D, EndToEndIdPayment as E, AccountCredentialsUpdateType as F, AccountPatchType as G, HandleAuthorizationCallbackInput as H, AccountStatus as J, AccountUpdateType as K, LastSyncMetadata as L, AuthorizedBatch as M, PaymentRequestSelectType as P, BankAccountWithLastSync as R, BankCode as S, BatchInsertType as T, BatchLifecycle as U, BatchMode as V, BatchPayment as W, BatchStatus as X, PaymentSelectType as a, ChargeBearer as a0, CompletedBatch as a1, CountryCode as a2, CredentialsType as a3, InstructionPriority as a5, PaymentDirection as aa, PaymentFailedInsertType as ab, PaymentInsertType as ac, PaymentLifecycle as ad, PaymentPreparedInsertType as ae, PaymentStatus as af, ProcessingBatch as ag, ReadyToSignBatch as ah, ResolvedCredentials as ai, TokenType as ak, ConnectorKey as b, ConfigEnvironmentBank as c, PaymentType as d, CurrencyCode as e, HandleAuthorizationCallbackOutput as f, ConnectedAccount as g, CredentialsResolver as h, AccountCredentialsInsertType as i, AccountInsertType as j, BatchedPayment as k, InitiatedBatch as l, IncomingPayment as m, InitiatedPayment as n, ParsedBankPayment as o, PaymentRequestStatus as p, AuthorizationCallbackResult as q, BatchMetadata as r, Currency as s, AccountAssignedPayment as u, PreparedPayment as v, CompletedPayment as w, PaymentRequestInsertType as x, AccountCredentialsPatchType as z };
@@ -3606,7 +3606,7 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
3606
3606
  name: string;
3607
3607
  tableName: "payment";
3608
3608
  dataType: "string enum";
3609
- data: "PROCESSING" | "BOOKED" | "REJECTED" | "PENDING" | "CANCELLED" | "SCHEDULED" | "HOLD" | "INFO";
3609
+ data: "PROCESSING" | "PENDING" | "BOOKED" | "CANCELLED" | "REJECTED" | "SCHEDULED" | "HOLD" | "INFO";
3610
3610
  driverParam: string;
3611
3611
  notNull: true;
3612
3612
  hasDefault: false;
@@ -4110,7 +4110,7 @@ declare const paymentRequest: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
4110
4110
  name: string;
4111
4111
  tableName: "payment_request";
4112
4112
  dataType: "string enum";
4113
- data: "AUTHORIZED" | "COMPLETED" | "OPENED" | "BOOKED" | "SETTLED" | "REJECTED" | "CLOSED";
4113
+ data: "AUTHORIZED" | "COMPLETED" | "BOOKED" | "REJECTED" | "OPENED" | "SETTLED" | "CLOSED";
4114
4114
  driverParam: string;
4115
4115
  notNull: true;
4116
4116
  hasDefault: false;
@@ -5391,5 +5391,5 @@ type ParsedBankPayment = {
5391
5391
  */
5392
5392
  type BatchPayment = Omit<PaymentInsertType, 'bankRefId'>;
5393
5393
 
5394
- export { IBankConnector as I, BASE_TERMINAL_STATUSES as M, BATCH_MODES as N, BATCH_STATUSES as O, CHARGE_BEARERS as X, CONNECTOR_KEYS as Y, COUNTRY_CODES as Z, CREDENTIALS_TYPES as _, INSTRUCTION_PRIORITIES as a3, PAYMENT_DIRECTIONS as a5, PAYMENT_REQUEST_STATUSES as a6, PAYMENT_STATUSES as a7, PAYMENT_TYPES as a8, isTerminalStatus as aA, account as aB, accountCredentials as aC, batch as aD, ott as aE, payment as aF, paymentRequest as aG, TOKEN_TYPES as ai, accountCredentialsInsertSchema as ak, accountCredentialsSelectSchema as al, accountCredentialsUpdateSchema as am, accountInsertSchema as an, accountSelectSchema as ao, accountUpdateSchema as ap, hasPaymentAccountAssigned as aq, isBatchAuthorized as ar, isBatchCompleted as as, isBatchFailed as at, isBatchInitiated as au, isBatchProcessing as av, isBatchReadyToSign as aw, isPaymentCompleted as ax, isPendingStatus as ay, isProcessedStatus as az, tables as t, ACCOUNT_STATUSES as y };
5395
- export type { ChargeBearer as $, AccountSelectType as A, BatchSelectType as B, ConnectorConfig as C, AccountCredentialsSelectType as D, AccountCredentialsUpdateType as E, AccountPatchType as F, AccountStatus as G, HandleAuthorizationCallbackInput as H, AccountUpdateType as J, AuthorizedBatch as K, LastSyncMetadata as L, PaymentRequestSelectType as P, BankAccountWithLastSync as Q, BankCode as R, BatchInsertType as S, BatchLifecycle as T, BatchMode as U, BatchPayment as V, BatchStatus as W, PaymentSelectType as a, CompletedBatch as a0, CountryCode as a1, CredentialsType as a2, InstructionPriority as a4, PaymentDirection as a9, PaymentFailedInsertType as aa, PaymentInsertType as ab, PaymentLifecycle as ac, PaymentPreparedInsertType as ad, PaymentStatus as ae, ProcessingBatch as af, ReadyToSignBatch as ag, ResolvedCredentials as ah, TokenType as aj, ConnectorKey as b, ConfigEnvironmentBank as c, PaymentType as d, CurrencyCode as e, HandleAuthorizationCallbackOutput as f, ConnectedAccount as g, CredentialsResolver as h, AccountCredentialsInsertType as i, AccountInsertType as j, BatchedPayment as k, InitiatedBatch as l, IncomingPayment as m, InitiatedPayment as n, ParsedBankPayment as o, PaymentRequestStatus as p, AuthorizationCallbackResult as q, BatchMetadata as r, Currency as s, AccountAssignedPayment as u, PreparedPayment as v, CompletedPayment as w, PaymentRequestInsertType as x, AccountCredentialsPatchType as z };
5394
+ export { CREDENTIALS_TYPES as $, IBankConnector as I, BASE_TERMINAL_STATUSES as N, BATCH_MODES as O, BATCH_STATUSES as Q, CHARGE_BEARERS as Y, CONNECTOR_KEYS as Z, COUNTRY_CODES as _, INSTRUCTION_PRIORITIES as a4, PAYMENT_DIRECTIONS as a6, PAYMENT_REQUEST_STATUSES as a7, PAYMENT_STATUSES as a8, PAYMENT_TYPES as a9, isProcessedStatus as aA, isTerminalStatus as aB, account as aC, accountCredentials as aD, batch as aE, ott as aF, payment as aG, paymentRequest as aH, TOKEN_TYPES as aj, accountCredentialsInsertSchema as al, accountCredentialsSelectSchema as am, accountCredentialsUpdateSchema as an, accountInsertSchema as ao, accountSelectSchema as ap, accountUpdateSchema as aq, hasPaymentAccountAssigned as ar, isBatchAuthorized as as, isBatchCompleted as at, isBatchFailed as au, isBatchInitiated as av, isBatchProcessing as aw, isBatchReadyToSign as ax, isPaymentCompleted as ay, isPendingStatus as az, tables as t, ACCOUNT_STATUSES as y };
5395
+ export type { AccountSelectType as A, BatchSelectType as B, ConnectorConfig as C, AccountCredentialsSelectType as D, EndToEndIdPayment as E, AccountCredentialsUpdateType as F, AccountPatchType as G, HandleAuthorizationCallbackInput as H, AccountStatus as J, AccountUpdateType as K, LastSyncMetadata as L, AuthorizedBatch as M, PaymentRequestSelectType as P, BankAccountWithLastSync as R, BankCode as S, BatchInsertType as T, BatchLifecycle as U, BatchMode as V, BatchPayment as W, BatchStatus as X, PaymentSelectType as a, ChargeBearer as a0, CompletedBatch as a1, CountryCode as a2, CredentialsType as a3, InstructionPriority as a5, PaymentDirection as aa, PaymentFailedInsertType as ab, PaymentInsertType as ac, PaymentLifecycle as ad, PaymentPreparedInsertType as ae, PaymentStatus as af, ProcessingBatch as ag, ReadyToSignBatch as ah, ResolvedCredentials as ai, TokenType as ak, ConnectorKey as b, ConfigEnvironmentBank as c, PaymentType as d, CurrencyCode as e, HandleAuthorizationCallbackOutput as f, ConnectedAccount as g, CredentialsResolver as h, AccountCredentialsInsertType as i, AccountInsertType as j, BatchedPayment as k, InitiatedBatch as l, IncomingPayment as m, InitiatedPayment as n, ParsedBankPayment as o, PaymentRequestStatus as p, AuthorizationCallbackResult as q, BatchMetadata as r, Currency as s, AccountAssignedPayment as u, PreparedPayment as v, CompletedPayment as w, PaymentRequestInsertType as x, AccountCredentialsPatchType as z };
@@ -1,4 +1,4 @@
1
- import { e as CurrencyCode, R as BankCode, a1 as CountryCode, P as PaymentRequestSelectType } from './bank.CGVCfq1B.cjs';
1
+ import { e as CurrencyCode, S as BankCode, a2 as CountryCode, P as PaymentRequestSelectType } from './bank.BQwwtIR4.cjs';
2
2
  import { z } from 'zod';
3
3
 
4
4
  type ReferenceType = `${'VS' | 'SS' | 'KS'}:${number}`;
@@ -803,6 +803,31 @@ const calculateCzechIban = (accountNumber, bankCode) => {
803
803
  return `CZ${checkDigits}${basicIban}`;
804
804
  };
805
805
 
806
+ const unsupported = (priority, rail, supported) => {
807
+ throw createInternalError(null, {
808
+ message: `instructionPriority=${priority} is not supported on the ${rail} rail (supported: ${supported}).`,
809
+ code: "UNSUPPORTED_INSTRUCTION_PRIORITY",
810
+ status: 422
811
+ });
812
+ };
813
+ const toFinbricksPriority = (priority) => {
814
+ if (!priority || priority === "NORM") return "NORM";
815
+ if (priority === "INST") return "INST";
816
+ return unsupported(priority, "Finbricks SEPA/domestic", "NORM, INST");
817
+ };
818
+ const toFinbricksForeignPriority = (priority) => {
819
+ if (!priority || priority === "NORM") return "NORM";
820
+ return unsupported(priority, "Finbricks foreign (SWIFT)", "NORM");
821
+ };
822
+ const toErstePriority = (priority) => {
823
+ if (!priority || priority === "NORM") return "NORM";
824
+ if (priority === "HIGH") return "HIGH";
825
+ return unsupported(priority, "Erste ISO 20022", "NORM, HIGH");
826
+ };
827
+ const assertDbuPriority = (priority) => {
828
+ if (priority === "HIGH") unsupported(priority, "DBU domestic", "NORM, INST");
829
+ };
830
+
806
831
  function autoVariableSymbol(paymentId) {
807
832
  let hash = 0;
808
833
  for (let i = 0; i < paymentId.length; i++) {
@@ -1090,7 +1115,7 @@ class FinbricksConnector extends IBankConnector {
1090
1115
  description: this.PROVIDER === "CSOB" ? composeWithUltimateCreditor(p.message, p.creditor, {
1091
1116
  stripDiacritics: p.currency !== "CZK"
1092
1117
  }) : p.message,
1093
- instructionPriority: p.instructionPriority ?? "NORM"
1118
+ instructionPriority: toFinbricksPriority(p.instructionPriority)
1094
1119
  }))
1095
1120
  }
1096
1121
  })
@@ -1114,6 +1139,15 @@ class FinbricksConnector extends IBankConnector {
1114
1139
  initiateForeignBatchImpl(_args) {
1115
1140
  throw new Error("Finbricks: Foreign batch not implemented");
1116
1141
  }
1142
+ /**
1143
+ * endToEndIdentification for the SEPA rail. Optional per the Finbricks spec —
1144
+ * return `undefined` to omit the field entirely, which some executing banks
1145
+ * need because they overwrite the remittance text with it (see
1146
+ * `CreditasConnector`).
1147
+ */
1148
+ buildSepaEndToEndId(payment) {
1149
+ return this.buildEndToEndId(payment);
1150
+ }
1117
1151
  async initiateForeignPayment(payment) {
1118
1152
  const debtorAccount = this.connectedAccounts.find(
1119
1153
  (acc) => acc.iban === payment.debtorIban
@@ -1171,6 +1205,9 @@ class FinbricksConnector extends IBankConnector {
1171
1205
  },
1172
1206
  ...creditorAgent && { creditorAgent },
1173
1207
  ...unstructured && { remittanceInformation: { unstructured } },
1208
+ instructionPriority: toFinbricksForeignPriority(
1209
+ payment.instructionPriority
1210
+ ),
1174
1211
  callbackUrl: `${this.finbricks.REDIRECT_URI}?type=paymentRequest&paymentRequestId=${payment.id}`
1175
1212
  }
1176
1213
  })
@@ -1218,6 +1255,10 @@ class FinbricksConnector extends IBankConnector {
1218
1255
  0,
1219
1256
  140
1220
1257
  );
1258
+ const endToEndIdentification = this.buildSepaEndToEndId({
1259
+ ...payment,
1260
+ id: payment.id
1261
+ });
1221
1262
  const bankRefId = uuidv4();
1222
1263
  const [response, error] = await useResult(
1223
1264
  this.finbricks.request({
@@ -1231,10 +1272,7 @@ class FinbricksConnector extends IBankConnector {
1231
1272
  },
1232
1273
  paymentIdentification: {
1233
1274
  merchantTransactionId: bankRefId,
1234
- endToEndIdentification: this.buildEndToEndId({
1235
- ...payment,
1236
- id: payment.id
1237
- })
1275
+ ...endToEndIdentification && { endToEndIdentification }
1238
1276
  },
1239
1277
  amount: payment.amount,
1240
1278
  debtor: {
@@ -1249,8 +1287,7 @@ class FinbricksConnector extends IBankConnector {
1249
1287
  ...creditorAddress && { postalAddress: creditorAddress }
1250
1288
  },
1251
1289
  remittanceInformation: { unstructured },
1252
- // Finbricks SEPA init accepts only NORM/INST — internal HIGH maps to NORM.
1253
- instructionPriority: payment.instructionPriority === "INST" ? "INST" : "NORM",
1290
+ instructionPriority: toFinbricksPriority(payment.instructionPriority),
1254
1291
  callbackUrl: `${this.finbricks.REDIRECT_URI}?type=paymentRequest&paymentRequestId=${payment.id}`
1255
1292
  }
1256
1293
  })
@@ -1303,7 +1340,7 @@ class FinbricksConnector extends IBankConnector {
1303
1340
  // TEMP: clientId disabled per client request — do not send.
1304
1341
  // clientId,
1305
1342
  paymentProvider: this.PROVIDER,
1306
- instructionPriority: payment.instructionPriority ?? "NORM"
1343
+ instructionPriority: toFinbricksPriority(payment.instructionPriority)
1307
1344
  }
1308
1345
  })
1309
1346
  );
@@ -1825,6 +1862,7 @@ class DbuConnector extends IBankConnector {
1825
1862
  };
1826
1863
  }
1827
1864
  async initiateDomesticPayment(payment) {
1865
+ assertDbuPriority(payment.instructionPriority);
1828
1866
  if (payment.instructionPriority === "INST") {
1829
1867
  return this.initiateInstantPayment(payment);
1830
1868
  }
@@ -2172,7 +2210,7 @@ class ErsteConnector extends IBankConnector {
2172
2210
  instructionIdentification: payment.id
2173
2211
  },
2174
2212
  paymentTypeInformation: {
2175
- instructionPriority: payment.instructionPriority ?? "NORM"
2213
+ instructionPriority: toErstePriority(payment.instructionPriority)
2176
2214
  },
2177
2215
  amount: {
2178
2216
  instructedAmount: { value: payment.amount, currency: payment.currency }
@@ -2475,11 +2513,20 @@ class MockConnector extends IBankConnector {
2475
2513
  async getPaymentStatus(_) {
2476
2514
  return "SETTLED";
2477
2515
  }
2478
- parseAuthorizationCallback(_callbackUrl) {
2516
+ parseAuthorizationCallback(callbackUrl) {
2517
+ const params = new URL(callbackUrl).searchParams;
2518
+ const error = params.get("error");
2519
+ if (error) {
2520
+ return {
2521
+ success: false,
2522
+ error,
2523
+ code: params.get("code")
2524
+ };
2525
+ }
2479
2526
  return {
2480
2527
  success: true,
2481
2528
  type: "paymentRequest",
2482
- paymentRequestId: "mock-pr-id"
2529
+ paymentRequestId: params.get("paymentRequestId") ?? "mock-pr-id"
2483
2530
  };
2484
2531
  }
2485
2532
  }
@@ -1,4 +1,4 @@
1
- import { e as CurrencyCode, R as BankCode, a1 as CountryCode, P as PaymentRequestSelectType } from './bank.CGVCfq1B.js';
1
+ import { e as CurrencyCode, S as BankCode, a2 as CountryCode, P as PaymentRequestSelectType } from './bank.BQwwtIR4.js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  type ReferenceType = `${'VS' | 'SS' | 'KS'}:${number}`;