@develit-services/bank 0.8.10 → 0.8.12

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.
@@ -1212,17 +1212,29 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
1212
1212
  { successMessage: "Payment initiated successfully" },
1213
1213
  async (data) => {
1214
1214
  const incomingPayment = mock_connector.toIncomingPayment(data);
1215
+ this._validatePaymentTypeAndCurrency(
1216
+ data.paymentType,
1217
+ data.currency,
1218
+ data.creditor
1219
+ );
1215
1220
  const { accounts } = await this._getAccounts();
1216
1221
  const account = accounts.find(
1217
- (acc) => acc.iban === incomingPayment.debtorIban && acc.currency === incomingPayment.currency
1222
+ (acc) => acc.iban === incomingPayment.debtorIban
1218
1223
  );
1219
1224
  if (!account) {
1220
1225
  throw backendSdk.createInternalError(null, {
1221
- message: `No account found for IBAN ${incomingPayment.debtorIban} with currency ${incomingPayment.currency}`,
1226
+ message: `No account found for IBAN ${incomingPayment.debtorIban}`,
1222
1227
  code: "VALID-B-004",
1223
1228
  status: 422
1224
1229
  });
1225
1230
  }
1231
+ if (account.currency !== data.currency) {
1232
+ throw backendSdk.createInternalError(null, {
1233
+ message: `Account ${account.iban} has currency ${account.currency}, but payment requires ${data.currency}`,
1234
+ code: "VALID-B-010",
1235
+ status: 422
1236
+ });
1237
+ }
1226
1238
  if (account.status !== "AUTHORIZED") {
1227
1239
  throw backendSdk.createInternalError(null, {
1228
1240
  message: `Account ${account.iban} is not authorized (status: ${account.status})`,
@@ -1240,11 +1252,6 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
1240
1252
  status: 422
1241
1253
  });
1242
1254
  }
1243
- this._validatePaymentTypeAndCurrency(
1244
- data.paymentType,
1245
- data.currency,
1246
- data.creditor
1247
- );
1248
1255
  const accountAssigned = mock_connector.assignAccount(incomingPayment, account);
1249
1256
  const batchedPayment = mock_connector.toBatchedPayment(accountAssigned);
1250
1257
  const { command: insertPaymentRequest } = createPaymentRequestCommand(
@@ -1323,17 +1330,29 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
1323
1330
  });
1324
1331
  }
1325
1332
  }
1333
+ for (const p of paymentInputs) {
1334
+ this._validatePaymentTypeAndCurrency(
1335
+ p.paymentType,
1336
+ p.currency,
1337
+ p.creditor
1338
+ );
1339
+ }
1326
1340
  const { accounts } = await this._getAccounts();
1327
- const account = accounts.find(
1328
- (acc) => acc.iban === debtorIban && acc.currency === currency
1329
- );
1341
+ const account = accounts.find((acc) => acc.iban === debtorIban);
1330
1342
  if (!account) {
1331
1343
  throw backendSdk.createInternalError(null, {
1332
- message: `No account found for IBAN ${debtorIban} with currency ${currency}`,
1344
+ message: `No account found for IBAN ${debtorIban}`,
1333
1345
  code: "VALID-B-004",
1334
1346
  status: 422
1335
1347
  });
1336
1348
  }
1349
+ if (account.currency !== currency) {
1350
+ throw backendSdk.createInternalError(null, {
1351
+ message: `Account ${account.iban} has currency ${account.currency}, but payments require ${currency}`,
1352
+ code: "VALID-B-010",
1353
+ status: 422
1354
+ });
1355
+ }
1337
1356
  if (account.status !== "AUTHORIZED") {
1338
1357
  throw backendSdk.createInternalError(null, {
1339
1358
  message: `Account ${account.iban} is not authorized (status: ${account.status})`,
@@ -1358,13 +1377,6 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
1358
1377
  status: 422
1359
1378
  });
1360
1379
  }
1361
- for (const p of paymentInputs) {
1362
- this._validatePaymentTypeAndCurrency(
1363
- p.paymentType,
1364
- p.currency,
1365
- p.creditor
1366
- );
1367
- }
1368
1380
  const incomingPayments = paymentInputs.map(mock_connector.toIncomingPayment);
1369
1381
  const batchedPayments = incomingPayments.map(
1370
1382
  (p) => mock_connector.toBatchedPayment(mock_connector.assignAccount(p, account))
@@ -1210,17 +1210,29 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1210
1210
  { successMessage: "Payment initiated successfully" },
1211
1211
  async (data) => {
1212
1212
  const incomingPayment = toIncomingPayment(data);
1213
+ this._validatePaymentTypeAndCurrency(
1214
+ data.paymentType,
1215
+ data.currency,
1216
+ data.creditor
1217
+ );
1213
1218
  const { accounts } = await this._getAccounts();
1214
1219
  const account = accounts.find(
1215
- (acc) => acc.iban === incomingPayment.debtorIban && acc.currency === incomingPayment.currency
1220
+ (acc) => acc.iban === incomingPayment.debtorIban
1216
1221
  );
1217
1222
  if (!account) {
1218
1223
  throw createInternalError(null, {
1219
- message: `No account found for IBAN ${incomingPayment.debtorIban} with currency ${incomingPayment.currency}`,
1224
+ message: `No account found for IBAN ${incomingPayment.debtorIban}`,
1220
1225
  code: "VALID-B-004",
1221
1226
  status: 422
1222
1227
  });
1223
1228
  }
1229
+ if (account.currency !== data.currency) {
1230
+ throw createInternalError(null, {
1231
+ message: `Account ${account.iban} has currency ${account.currency}, but payment requires ${data.currency}`,
1232
+ code: "VALID-B-010",
1233
+ status: 422
1234
+ });
1235
+ }
1224
1236
  if (account.status !== "AUTHORIZED") {
1225
1237
  throw createInternalError(null, {
1226
1238
  message: `Account ${account.iban} is not authorized (status: ${account.status})`,
@@ -1238,11 +1250,6 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1238
1250
  status: 422
1239
1251
  });
1240
1252
  }
1241
- this._validatePaymentTypeAndCurrency(
1242
- data.paymentType,
1243
- data.currency,
1244
- data.creditor
1245
- );
1246
1253
  const accountAssigned = assignAccount(incomingPayment, account);
1247
1254
  const batchedPayment = toBatchedPayment(accountAssigned);
1248
1255
  const { command: insertPaymentRequest } = createPaymentRequestCommand(
@@ -1321,17 +1328,29 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1321
1328
  });
1322
1329
  }
1323
1330
  }
1331
+ for (const p of paymentInputs) {
1332
+ this._validatePaymentTypeAndCurrency(
1333
+ p.paymentType,
1334
+ p.currency,
1335
+ p.creditor
1336
+ );
1337
+ }
1324
1338
  const { accounts } = await this._getAccounts();
1325
- const account = accounts.find(
1326
- (acc) => acc.iban === debtorIban && acc.currency === currency
1327
- );
1339
+ const account = accounts.find((acc) => acc.iban === debtorIban);
1328
1340
  if (!account) {
1329
1341
  throw createInternalError(null, {
1330
- message: `No account found for IBAN ${debtorIban} with currency ${currency}`,
1342
+ message: `No account found for IBAN ${debtorIban}`,
1331
1343
  code: "VALID-B-004",
1332
1344
  status: 422
1333
1345
  });
1334
1346
  }
1347
+ if (account.currency !== currency) {
1348
+ throw createInternalError(null, {
1349
+ message: `Account ${account.iban} has currency ${account.currency}, but payments require ${currency}`,
1350
+ code: "VALID-B-010",
1351
+ status: 422
1352
+ });
1353
+ }
1335
1354
  if (account.status !== "AUTHORIZED") {
1336
1355
  throw createInternalError(null, {
1337
1356
  message: `Account ${account.iban} is not authorized (status: ${account.status})`,
@@ -1356,13 +1375,6 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1356
1375
  status: 422
1357
1376
  });
1358
1377
  }
1359
- for (const p of paymentInputs) {
1360
- this._validatePaymentTypeAndCurrency(
1361
- p.paymentType,
1362
- p.currency,
1363
- p.creditor
1364
- );
1365
- }
1366
1378
  const incomingPayments = paymentInputs.map(toIncomingPayment);
1367
1379
  const batchedPayments = incomingPayments.map(
1368
1380
  (p) => toBatchedPayment(assignAccount(p, account))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-services/bank",
3
- "version": "0.8.10",
3
+ "version": "0.8.12",
4
4
  "author": "Develit.io s.r.o.",
5
5
  "type": "module",
6
6
  "exports": {