@davidvornholt/lib-fints 0.0.0-stage → 1.5.401

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.
Files changed (699) hide show
  1. package/FORK.md +40 -0
  2. package/LICENSE +504 -0
  3. package/README.md +423 -2
  4. package/biome.json +35 -0
  5. package/dist/accountBalance.js +1 -0
  6. package/dist/accountDescriptor.js +65 -0
  7. package/dist/bankAccount.js +42 -0
  8. package/dist/bankAnswer.js +1 -0
  9. package/dist/bankTransaction.js +1 -0
  10. package/dist/bankingInformation.js +1 -0
  11. package/dist/bpd.js +1 -0
  12. package/dist/camtParser.js +443 -0
  13. package/dist/client.js +740 -0
  14. package/dist/codes.js +87 -0
  15. package/dist/config.js +241 -0
  16. package/dist/creditCardStatement.js +1 -0
  17. package/dist/dataElements/AlphaNumeric.js +24 -0
  18. package/dist/dataElements/Amount.js +6 -0
  19. package/dist/dataElements/Binary.js +37 -0
  20. package/dist/dataElements/Country.js +6 -0
  21. package/dist/dataElements/Currency.js +6 -0
  22. package/dist/dataElements/Dat.js +18 -0
  23. package/dist/dataElements/DataElement.js +38 -0
  24. package/dist/dataElements/Digits.js +23 -0
  25. package/dist/dataElements/Float.js +21 -0
  26. package/dist/dataElements/Identification.js +6 -0
  27. package/dist/dataElements/Numeric.js +26 -0
  28. package/dist/dataElements/Text.js +21 -0
  29. package/dist/dataElements/Time.js +18 -0
  30. package/dist/dataElements/YesNo.js +18 -0
  31. package/dist/dataGroups/Account.js +12 -0
  32. package/dist/dataGroups/Balance.js +15 -0
  33. package/dist/dataGroups/BankIdentification.js +8 -0
  34. package/dist/dataGroups/DataGroup.js +61 -0
  35. package/dist/dataGroups/InternationalAccount.js +15 -0
  36. package/dist/dataGroups/Money.js +8 -0
  37. package/dist/dataGroups/RefMessage.js +8 -0
  38. package/dist/dataGroups/SepaAccount.js +17 -0
  39. package/dist/dataGroups/TimeStamp.js +8 -0
  40. package/dist/decoder.js +100 -0
  41. package/dist/dialog.js +469 -0
  42. package/dist/electronicStatement.js +1 -0
  43. package/dist/encoder.js +59 -0
  44. package/dist/format.js +6 -0
  45. package/dist/httpClient.js +84 -0
  46. package/dist/index.js +22 -0
  47. package/dist/interactions/balanceInteraction.js +46 -0
  48. package/dist/interactions/creditTransferInteraction.js +499 -0
  49. package/dist/interactions/creditcardStatementInteraction.js +115 -0
  50. package/dist/interactions/creditcardStatementInteractionHKKKU.js +141 -0
  51. package/dist/interactions/customerInteraction.js +121 -0
  52. package/dist/interactions/electronicStatementInteraction.js +89 -0
  53. package/dist/interactions/endDialogInteraction.js +17 -0
  54. package/dist/interactions/initDialogInteraction.js +232 -0
  55. package/dist/interactions/portfolioInteraction.js +65 -0
  56. package/dist/interactions/sepaAccountInteraction.js +51 -0
  57. package/dist/interactions/statementInteractionCAMT.js +71 -0
  58. package/dist/interactions/statementInteractionMT940.js +50 -0
  59. package/dist/interactions/tanMediaInteraction.js +37 -0
  60. package/dist/interactions/transferOutcome.js +364 -0
  61. package/dist/interactions/vopCheck.js +346 -0
  62. package/dist/message.js +239 -0
  63. package/dist/mt535parser.js +151 -0
  64. package/dist/mt940parser.js +313 -0
  65. package/dist/pain001Builder.js +308 -0
  66. package/dist/pain002Parser.js +140 -0
  67. package/dist/parser.js +28 -0
  68. package/dist/partedSegment.js +11 -0
  69. package/dist/segment.js +81 -0
  70. package/dist/segmentDefinition.js +20 -0
  71. package/dist/segmentHeader.js +13 -0
  72. package/dist/segments/DIKKU.js +23 -0
  73. package/dist/segments/DKKKU.js +25 -0
  74. package/dist/segments/HIBPA.js +26 -0
  75. package/dist/segments/HICAZ.js +22 -0
  76. package/dist/segments/HICAZS.js +19 -0
  77. package/dist/segments/HICCSS.js +23 -0
  78. package/dist/segments/HIEKA.js +45 -0
  79. package/dist/segments/HIEKAS.js +18 -0
  80. package/dist/segments/HIKAZ.js +16 -0
  81. package/dist/segments/HIKAZS.js +17 -0
  82. package/dist/segments/HIKIM.js +14 -0
  83. package/dist/segments/HIKKU.js +23 -0
  84. package/dist/segments/HIKKUS.js +18 -0
  85. package/dist/segments/HIKOM.js +26 -0
  86. package/dist/segments/HIPINS.js +22 -0
  87. package/dist/segments/HIRMG.js +23 -0
  88. package/dist/segments/HIRMS.js +23 -0
  89. package/dist/segments/HISAL.js +34 -0
  90. package/dist/segments/HISPA.js +14 -0
  91. package/dist/segments/HISPAS.js +22 -0
  92. package/dist/segments/HISYN.js +19 -0
  93. package/dist/segments/HITAB.js +40 -0
  94. package/dist/segments/HITAN.js +25 -0
  95. package/dist/segments/HITANS.js +53 -0
  96. package/dist/segments/HIUPA.js +21 -0
  97. package/dist/segments/HIUPD.js +41 -0
  98. package/dist/segments/HIVPAS.js +21 -0
  99. package/dist/segments/HIVPP.js +35 -0
  100. package/dist/segments/HIVPPS.js +23 -0
  101. package/dist/segments/HIWPD.js +15 -0
  102. package/dist/segments/HKCAZ.js +28 -0
  103. package/dist/segments/HKCCS.js +30 -0
  104. package/dist/segments/HKEKA.js +43 -0
  105. package/dist/segments/HKEND.js +14 -0
  106. package/dist/segments/HKIDN.js +21 -0
  107. package/dist/segments/HKKAZ.js +27 -0
  108. package/dist/segments/HKKKU.js +26 -0
  109. package/dist/segments/HKSAL.js +24 -0
  110. package/dist/segments/HKSPA.js +21 -0
  111. package/dist/segments/HKSYN.js +14 -0
  112. package/dist/segments/HKTAB.js +15 -0
  113. package/dist/segments/HKTAN.js +38 -0
  114. package/dist/segments/HKVPA.js +19 -0
  115. package/dist/segments/HKVPP.js +33 -0
  116. package/dist/segments/HKVVB.js +21 -0
  117. package/dist/segments/HKWPD.js +23 -0
  118. package/dist/segments/HNHBK.js +23 -0
  119. package/dist/segments/HNHBS.js +14 -0
  120. package/dist/segments/HNSHA.js +20 -0
  121. package/dist/segments/HNSHK.js +54 -0
  122. package/dist/segments/HNVSD.js +14 -0
  123. package/dist/segments/HNVSK.js +52 -0
  124. package/dist/segments/businessTransactionParameter.js +20 -0
  125. package/dist/segments/registry.js +120 -0
  126. package/dist/statement.js +1 -0
  127. package/dist/tanMethod.js +1 -0
  128. package/dist/tests/HIBPA.test.js +26 -0
  129. package/dist/tests/HICAZS.test.js +18 -0
  130. package/dist/tests/HICCSS.test.js +16 -0
  131. package/dist/tests/HIPINS.test.js +14 -0
  132. package/dist/tests/HIRMG.test.js +24 -0
  133. package/dist/tests/HITAB.test.js +26 -0
  134. package/dist/tests/HITANS.test.js +19 -0
  135. package/dist/tests/HIUPA.test.js +11 -0
  136. package/dist/tests/HIUPD.test.js +11 -0
  137. package/dist/tests/HIVPAS.test.js +16 -0
  138. package/dist/tests/HIVPP.test.js +58 -0
  139. package/dist/tests/HIVPPS.test.js +29 -0
  140. package/dist/tests/HIWPD.test.js +25 -0
  141. package/dist/tests/HKCAZ.test.js +43 -0
  142. package/dist/tests/HKCCS.test.js +52 -0
  143. package/dist/tests/HKEKA.test.js +198 -0
  144. package/dist/tests/HKIDN.test.js +22 -0
  145. package/dist/tests/HKKKU.test.js +207 -0
  146. package/dist/tests/HKSAL.test.js +45 -0
  147. package/dist/tests/HKTAN.test.js +22 -0
  148. package/dist/tests/HKVPA.test.js +21 -0
  149. package/dist/tests/HKVPP.test.js +40 -0
  150. package/dist/tests/HKWPD.test.js +38 -0
  151. package/dist/tests/HNSHK.test.js +11 -0
  152. package/dist/tests/HNVSK.test.js +11 -0
  153. package/dist/tests/accountDescriptor.test.js +99 -0
  154. package/dist/tests/accountReference.test.js +126 -0
  155. package/dist/tests/bankReplyChecks.test.js +37 -0
  156. package/dist/tests/camtParser.test.js +988 -0
  157. package/dist/tests/client.test.js +690 -0
  158. package/dist/tests/credentialRedaction.test.js +59 -0
  159. package/dist/tests/creditTransfer.test.js +1475 -0
  160. package/dist/tests/creditTransferBank.js +205 -0
  161. package/dist/tests/creditTransferSafety.test.js +319 -0
  162. package/dist/tests/datatypes.test.js +8 -0
  163. package/dist/tests/dialog.test.js +435 -0
  164. package/dist/tests/httpClientErrorLog.test.js +27 -0
  165. package/dist/tests/interactionAccountDescriptor.test.js +153 -0
  166. package/dist/tests/message.test.js +98 -0
  167. package/dist/tests/mt535parser.test.js +245 -0
  168. package/dist/tests/mt940parser.test.js +82 -0
  169. package/dist/tests/pain001Builder.test.js +291 -0
  170. package/dist/tests/pain002Parser.test.js +152 -0
  171. package/dist/tests/parser.test.js +25 -0
  172. package/dist/tests/partedDialog.test.js +203 -0
  173. package/dist/tests/partedResponse.test.js +181 -0
  174. package/dist/tests/statementParseFailure.test.js +18 -0
  175. package/dist/tests/tanMedia.test.js +125 -0
  176. package/dist/types/accountBalance.d.ts +9 -0
  177. package/dist/types/accountBalance.d.ts.map +1 -0
  178. package/dist/types/accountDescriptor.d.ts +49 -0
  179. package/dist/types/accountDescriptor.d.ts.map +1 -0
  180. package/dist/types/bankAccount.d.ts +39 -0
  181. package/dist/types/bankAccount.d.ts.map +1 -0
  182. package/dist/types/bankAnswer.d.ts +6 -0
  183. package/dist/types/bankAnswer.d.ts.map +1 -0
  184. package/dist/types/bankTransaction.d.ts +22 -0
  185. package/dist/types/bankTransaction.d.ts.map +1 -0
  186. package/dist/types/bankingInformation.d.ts +20 -0
  187. package/dist/types/bankingInformation.d.ts.map +1 -0
  188. package/dist/types/bpd.d.ts +17 -0
  189. package/dist/types/bpd.d.ts.map +1 -0
  190. package/dist/types/camtParser.d.ts +31 -0
  191. package/dist/types/camtParser.d.ts.map +1 -0
  192. package/dist/types/client.d.ts +302 -0
  193. package/dist/types/client.d.ts.map +1 -0
  194. package/dist/types/codes.d.ts +75 -0
  195. package/dist/types/codes.d.ts.map +1 -0
  196. package/dist/types/config.d.ts +127 -0
  197. package/dist/types/config.d.ts.map +1 -0
  198. package/dist/types/creditCardStatement.d.ts +16 -0
  199. package/dist/types/creditCardStatement.d.ts.map +1 -0
  200. package/dist/types/dataElements/AlphaNumeric.d.ts +8 -0
  201. package/dist/types/dataElements/AlphaNumeric.d.ts.map +1 -0
  202. package/dist/types/dataElements/Amount.d.ts +5 -0
  203. package/dist/types/dataElements/Amount.d.ts.map +1 -0
  204. package/dist/types/dataElements/Binary.d.ts +15 -0
  205. package/dist/types/dataElements/Binary.d.ts.map +1 -0
  206. package/dist/types/dataElements/Country.d.ts +5 -0
  207. package/dist/types/dataElements/Country.d.ts.map +1 -0
  208. package/dist/types/dataElements/Currency.d.ts +5 -0
  209. package/dist/types/dataElements/Currency.d.ts.map +1 -0
  210. package/dist/types/dataElements/Dat.d.ts +8 -0
  211. package/dist/types/dataElements/Dat.d.ts.map +1 -0
  212. package/dist/types/dataElements/DataElement.d.ts +14 -0
  213. package/dist/types/dataElements/DataElement.d.ts.map +1 -0
  214. package/dist/types/dataElements/Digits.d.ts +8 -0
  215. package/dist/types/dataElements/Digits.d.ts.map +1 -0
  216. package/dist/types/dataElements/Float.d.ts +8 -0
  217. package/dist/types/dataElements/Float.d.ts.map +1 -0
  218. package/dist/types/dataElements/Identification.d.ts +5 -0
  219. package/dist/types/dataElements/Identification.d.ts.map +1 -0
  220. package/dist/types/dataElements/Numeric.d.ts +9 -0
  221. package/dist/types/dataElements/Numeric.d.ts.map +1 -0
  222. package/dist/types/dataElements/Text.d.ts +8 -0
  223. package/dist/types/dataElements/Text.d.ts.map +1 -0
  224. package/dist/types/dataElements/Time.d.ts +8 -0
  225. package/dist/types/dataElements/Time.d.ts.map +1 -0
  226. package/dist/types/dataElements/YesNo.d.ts +7 -0
  227. package/dist/types/dataElements/YesNo.d.ts.map +1 -0
  228. package/dist/types/dataGroups/Account.d.ts +14 -0
  229. package/dist/types/dataGroups/Account.d.ts.map +1 -0
  230. package/dist/types/dataGroups/Balance.d.ts +12 -0
  231. package/dist/types/dataGroups/Balance.d.ts.map +1 -0
  232. package/dist/types/dataGroups/BankIdentification.d.ts +5 -0
  233. package/dist/types/dataGroups/BankIdentification.d.ts.map +1 -0
  234. package/dist/types/dataGroups/DataGroup.d.ts +10 -0
  235. package/dist/types/dataGroups/DataGroup.d.ts.map +1 -0
  236. package/dist/types/dataGroups/InternationalAccount.d.ts +13 -0
  237. package/dist/types/dataGroups/InternationalAccount.d.ts.map +1 -0
  238. package/dist/types/dataGroups/Money.d.ts +9 -0
  239. package/dist/types/dataGroups/Money.d.ts.map +1 -0
  240. package/dist/types/dataGroups/RefMessage.d.ts +9 -0
  241. package/dist/types/dataGroups/RefMessage.d.ts.map +1 -0
  242. package/dist/types/dataGroups/SepaAccount.d.ts +11 -0
  243. package/dist/types/dataGroups/SepaAccount.d.ts.map +1 -0
  244. package/dist/types/dataGroups/TimeStamp.d.ts +9 -0
  245. package/dist/types/dataGroups/TimeStamp.d.ts.map +1 -0
  246. package/dist/types/decoder.d.ts +4 -0
  247. package/dist/types/decoder.d.ts.map +1 -0
  248. package/dist/types/dialog.d.ts +106 -0
  249. package/dist/types/dialog.d.ts.map +1 -0
  250. package/dist/types/electronicStatement.d.ts +40 -0
  251. package/dist/types/electronicStatement.d.ts.map +1 -0
  252. package/dist/types/encoder.d.ts +3 -0
  253. package/dist/types/encoder.d.ts.map +1 -0
  254. package/dist/types/format.d.ts +3 -0
  255. package/dist/types/format.d.ts.map +1 -0
  256. package/dist/types/httpClient.d.ts +14 -0
  257. package/dist/types/httpClient.d.ts.map +1 -0
  258. package/dist/types/index.d.ts +27 -0
  259. package/dist/types/index.d.ts.map +1 -0
  260. package/dist/types/interactions/balanceInteraction.d.ts +16 -0
  261. package/dist/types/interactions/balanceInteraction.d.ts.map +1 -0
  262. package/dist/types/interactions/creditTransferInteraction.d.ts +228 -0
  263. package/dist/types/interactions/creditTransferInteraction.d.ts.map +1 -0
  264. package/dist/types/interactions/creditcardStatementInteraction.d.ts +19 -0
  265. package/dist/types/interactions/creditcardStatementInteraction.d.ts.map +1 -0
  266. package/dist/types/interactions/creditcardStatementInteractionHKKKU.d.ts +23 -0
  267. package/dist/types/interactions/creditcardStatementInteractionHKKKU.d.ts.map +1 -0
  268. package/dist/types/interactions/customerInteraction.d.ts +84 -0
  269. package/dist/types/interactions/customerInteraction.d.ts.map +1 -0
  270. package/dist/types/interactions/electronicStatementInteraction.d.ts +34 -0
  271. package/dist/types/interactions/electronicStatementInteraction.d.ts.map +1 -0
  272. package/dist/types/interactions/endDialogInteraction.d.ts +13 -0
  273. package/dist/types/interactions/endDialogInteraction.d.ts.map +1 -0
  274. package/dist/types/interactions/initDialogInteraction.d.ts +23 -0
  275. package/dist/types/interactions/initDialogInteraction.d.ts.map +1 -0
  276. package/dist/types/interactions/portfolioInteraction.d.ts +40 -0
  277. package/dist/types/interactions/portfolioInteraction.d.ts.map +1 -0
  278. package/dist/types/interactions/sepaAccountInteraction.d.ts +18 -0
  279. package/dist/types/interactions/sepaAccountInteraction.d.ts.map +1 -0
  280. package/dist/types/interactions/statementInteractionCAMT.d.ts +14 -0
  281. package/dist/types/interactions/statementInteractionCAMT.d.ts.map +1 -0
  282. package/dist/types/interactions/statementInteractionMT940.d.ts +14 -0
  283. package/dist/types/interactions/statementInteractionMT940.d.ts.map +1 -0
  284. package/dist/types/interactions/tanMediaInteraction.d.ts +13 -0
  285. package/dist/types/interactions/tanMediaInteraction.d.ts.map +1 -0
  286. package/dist/types/interactions/transferOutcome.d.ts +129 -0
  287. package/dist/types/interactions/transferOutcome.d.ts.map +1 -0
  288. package/dist/types/interactions/vopCheck.d.ts +107 -0
  289. package/dist/types/interactions/vopCheck.d.ts.map +1 -0
  290. package/dist/types/message.d.ts +30 -0
  291. package/dist/types/message.d.ts.map +1 -0
  292. package/dist/types/mt535parser.d.ts +23 -0
  293. package/dist/types/mt535parser.d.ts.map +1 -0
  294. package/dist/types/mt940parser.d.ts +46 -0
  295. package/dist/types/mt940parser.d.ts.map +1 -0
  296. package/dist/types/pain001Builder.d.ts +96 -0
  297. package/dist/types/pain001Builder.d.ts.map +1 -0
  298. package/dist/types/pain002Parser.d.ts +77 -0
  299. package/dist/types/pain002Parser.d.ts.map +1 -0
  300. package/dist/types/parser.d.ts +2 -0
  301. package/dist/types/parser.d.ts.map +1 -0
  302. package/dist/types/partedSegment.d.ts +15 -0
  303. package/dist/types/partedSegment.d.ts.map +1 -0
  304. package/dist/types/segment.d.ts +11 -0
  305. package/dist/types/segment.d.ts.map +1 -0
  306. package/dist/types/segmentDefinition.d.ts +13 -0
  307. package/dist/types/segmentDefinition.d.ts.map +1 -0
  308. package/dist/types/segmentHeader.d.ts +11 -0
  309. package/dist/types/segmentHeader.d.ts.map +1 -0
  310. package/dist/types/segments/DIKKU.d.ts +20 -0
  311. package/dist/types/segments/DIKKU.d.ts.map +1 -0
  312. package/dist/types/segments/DKKKU.d.ts +24 -0
  313. package/dist/types/segments/DKKKU.d.ts.map +1 -0
  314. package/dist/types/segments/HIBPA.d.ts +28 -0
  315. package/dist/types/segments/HIBPA.d.ts.map +1 -0
  316. package/dist/types/segments/HICAZ.d.ts +22 -0
  317. package/dist/types/segments/HICAZ.d.ts.map +1 -0
  318. package/dist/types/segments/HICAZS.d.ts +17 -0
  319. package/dist/types/segments/HICAZS.d.ts.map +1 -0
  320. package/dist/types/segments/HICCSS.d.ts +23 -0
  321. package/dist/types/segments/HICCSS.d.ts.map +1 -0
  322. package/dist/types/segments/HIEKA.d.ts +52 -0
  323. package/dist/types/segments/HIEKA.d.ts.map +1 -0
  324. package/dist/types/segments/HIEKAS.d.ts +21 -0
  325. package/dist/types/segments/HIEKAS.d.ts.map +1 -0
  326. package/dist/types/segments/HIKAZ.d.ts +17 -0
  327. package/dist/types/segments/HIKAZ.d.ts.map +1 -0
  328. package/dist/types/segments/HIKAZS.d.ts +16 -0
  329. package/dist/types/segments/HIKAZS.d.ts.map +1 -0
  330. package/dist/types/segments/HIKIM.d.ts +18 -0
  331. package/dist/types/segments/HIKIM.d.ts.map +1 -0
  332. package/dist/types/segments/HIKKU.d.ts +25 -0
  333. package/dist/types/segments/HIKKU.d.ts.map +1 -0
  334. package/dist/types/segments/HIKKUS.d.ts +21 -0
  335. package/dist/types/segments/HIKKUS.d.ts.map +1 -0
  336. package/dist/types/segments/HIKOM.d.ts +28 -0
  337. package/dist/types/segments/HIKOM.d.ts.map +1 -0
  338. package/dist/types/segments/HIPINS.d.ts +23 -0
  339. package/dist/types/segments/HIPINS.d.ts.map +1 -0
  340. package/dist/types/segments/HIRMG.d.ts +23 -0
  341. package/dist/types/segments/HIRMG.d.ts.map +1 -0
  342. package/dist/types/segments/HIRMS.d.ts +18 -0
  343. package/dist/types/segments/HIRMS.d.ts.map +1 -0
  344. package/dist/types/segments/HISAL.d.ts +33 -0
  345. package/dist/types/segments/HISAL.d.ts.map +1 -0
  346. package/dist/types/segments/HISPA.d.ts +17 -0
  347. package/dist/types/segments/HISPA.d.ts.map +1 -0
  348. package/dist/types/segments/HISPAS.d.ts +20 -0
  349. package/dist/types/segments/HISPAS.d.ts.map +1 -0
  350. package/dist/types/segments/HISYN.d.ts +20 -0
  351. package/dist/types/segments/HISYN.d.ts.map +1 -0
  352. package/dist/types/segments/HITAB.d.ts +40 -0
  353. package/dist/types/segments/HITAB.d.ts.map +1 -0
  354. package/dist/types/segments/HITAN.d.ts +26 -0
  355. package/dist/types/segments/HITAN.d.ts.map +1 -0
  356. package/dist/types/segments/HITANS.d.ts +46 -0
  357. package/dist/types/segments/HITANS.d.ts.map +1 -0
  358. package/dist/types/segments/HIUPA.d.ts +22 -0
  359. package/dist/types/segments/HIUPA.d.ts.map +1 -0
  360. package/dist/types/segments/HIUPD.d.ts +43 -0
  361. package/dist/types/segments/HIUPD.d.ts.map +1 -0
  362. package/dist/types/segments/HIVPAS.d.ts +21 -0
  363. package/dist/types/segments/HIVPAS.d.ts.map +1 -0
  364. package/dist/types/segments/HIVPP.d.ts +49 -0
  365. package/dist/types/segments/HIVPP.d.ts.map +1 -0
  366. package/dist/types/segments/HIVPPS.d.ts +27 -0
  367. package/dist/types/segments/HIVPPS.d.ts.map +1 -0
  368. package/dist/types/segments/HIWPD.d.ts +22 -0
  369. package/dist/types/segments/HIWPD.d.ts.map +1 -0
  370. package/dist/types/segments/HKCAZ.d.ts +27 -0
  371. package/dist/types/segments/HKCAZ.d.ts.map +1 -0
  372. package/dist/types/segments/HKCCS.d.ts +32 -0
  373. package/dist/types/segments/HKCCS.d.ts.map +1 -0
  374. package/dist/types/segments/HKEKA.d.ts +54 -0
  375. package/dist/types/segments/HKEKA.d.ts.map +1 -0
  376. package/dist/types/segments/HKEND.d.ts +17 -0
  377. package/dist/types/segments/HKEND.d.ts.map +1 -0
  378. package/dist/types/segments/HKIDN.d.ts +23 -0
  379. package/dist/types/segments/HKIDN.d.ts.map +1 -0
  380. package/dist/types/segments/HKKAZ.d.ts +26 -0
  381. package/dist/types/segments/HKKAZ.d.ts.map +1 -0
  382. package/dist/types/segments/HKKKU.d.ts +26 -0
  383. package/dist/types/segments/HKKKU.d.ts.map +1 -0
  384. package/dist/types/segments/HKSAL.d.ts +23 -0
  385. package/dist/types/segments/HKSAL.d.ts.map +1 -0
  386. package/dist/types/segments/HKSPA.d.ts +21 -0
  387. package/dist/types/segments/HKSPA.d.ts.map +1 -0
  388. package/dist/types/segments/HKSYN.d.ts +18 -0
  389. package/dist/types/segments/HKSYN.d.ts.map +1 -0
  390. package/dist/types/segments/HKTAB.d.ts +20 -0
  391. package/dist/types/segments/HKTAB.d.ts.map +1 -0
  392. package/dist/types/segments/HKTAN.d.ts +41 -0
  393. package/dist/types/segments/HKTAN.d.ts.map +1 -0
  394. package/dist/types/segments/HKVPA.d.ts +22 -0
  395. package/dist/types/segments/HKVPA.d.ts.map +1 -0
  396. package/dist/types/segments/HKVPP.d.ts +37 -0
  397. package/dist/types/segments/HKVPP.d.ts.map +1 -0
  398. package/dist/types/segments/HKVVB.d.ts +23 -0
  399. package/dist/types/segments/HKVVB.d.ts.map +1 -0
  400. package/dist/types/segments/HKWPD.d.ts +43 -0
  401. package/dist/types/segments/HKWPD.d.ts.map +1 -0
  402. package/dist/types/segments/HNHBK.d.ts +24 -0
  403. package/dist/types/segments/HNHBK.d.ts.map +1 -0
  404. package/dist/types/segments/HNHBS.d.ts +17 -0
  405. package/dist/types/segments/HNHBS.d.ts.map +1 -0
  406. package/dist/types/segments/HNSHA.d.ts +25 -0
  407. package/dist/types/segments/HNSHA.d.ts.map +1 -0
  408. package/dist/types/segments/HNSHK.d.ts +67 -0
  409. package/dist/types/segments/HNSHK.d.ts.map +1 -0
  410. package/dist/types/segments/HNVSD.d.ts +21 -0
  411. package/dist/types/segments/HNVSD.d.ts.map +1 -0
  412. package/dist/types/segments/HNVSK.d.ts +41 -0
  413. package/dist/types/segments/HNVSK.d.ts.map +1 -0
  414. package/dist/types/segments/businessTransactionParameter.d.ts +18 -0
  415. package/dist/types/segments/businessTransactionParameter.d.ts.map +1 -0
  416. package/dist/types/segments/registry.d.ts +4 -0
  417. package/dist/types/segments/registry.d.ts.map +1 -0
  418. package/dist/types/statement.d.ts +39 -0
  419. package/dist/types/statement.d.ts.map +1 -0
  420. package/dist/types/tanMethod.d.ts +31 -0
  421. package/dist/types/tanMethod.d.ts.map +1 -0
  422. package/dist/types/tests/HIBPA.test.d.ts +2 -0
  423. package/dist/types/tests/HIBPA.test.d.ts.map +1 -0
  424. package/dist/types/tests/HICAZS.test.d.ts +2 -0
  425. package/dist/types/tests/HICAZS.test.d.ts.map +1 -0
  426. package/dist/types/tests/HICCSS.test.d.ts +2 -0
  427. package/dist/types/tests/HICCSS.test.d.ts.map +1 -0
  428. package/dist/types/tests/HIPINS.test.d.ts +2 -0
  429. package/dist/types/tests/HIPINS.test.d.ts.map +1 -0
  430. package/dist/types/tests/HIRMG.test.d.ts +2 -0
  431. package/dist/types/tests/HIRMG.test.d.ts.map +1 -0
  432. package/dist/types/tests/HITAB.test.d.ts +2 -0
  433. package/dist/types/tests/HITAB.test.d.ts.map +1 -0
  434. package/dist/types/tests/HITANS.test.d.ts +2 -0
  435. package/dist/types/tests/HITANS.test.d.ts.map +1 -0
  436. package/dist/types/tests/HIUPA.test.d.ts +2 -0
  437. package/dist/types/tests/HIUPA.test.d.ts.map +1 -0
  438. package/dist/types/tests/HIUPD.test.d.ts +2 -0
  439. package/dist/types/tests/HIUPD.test.d.ts.map +1 -0
  440. package/dist/types/tests/HIVPAS.test.d.ts +2 -0
  441. package/dist/types/tests/HIVPAS.test.d.ts.map +1 -0
  442. package/dist/types/tests/HIVPP.test.d.ts +2 -0
  443. package/dist/types/tests/HIVPP.test.d.ts.map +1 -0
  444. package/dist/types/tests/HIVPPS.test.d.ts +2 -0
  445. package/dist/types/tests/HIVPPS.test.d.ts.map +1 -0
  446. package/dist/types/tests/HIWPD.test.d.ts +2 -0
  447. package/dist/types/tests/HIWPD.test.d.ts.map +1 -0
  448. package/dist/types/tests/HKCAZ.test.d.ts +2 -0
  449. package/dist/types/tests/HKCAZ.test.d.ts.map +1 -0
  450. package/dist/types/tests/HKCCS.test.d.ts +2 -0
  451. package/dist/types/tests/HKCCS.test.d.ts.map +1 -0
  452. package/dist/types/tests/HKEKA.test.d.ts +2 -0
  453. package/dist/types/tests/HKEKA.test.d.ts.map +1 -0
  454. package/dist/types/tests/HKIDN.test.d.ts +2 -0
  455. package/dist/types/tests/HKIDN.test.d.ts.map +1 -0
  456. package/dist/types/tests/HKKKU.test.d.ts +2 -0
  457. package/dist/types/tests/HKKKU.test.d.ts.map +1 -0
  458. package/dist/types/tests/HKSAL.test.d.ts +2 -0
  459. package/dist/types/tests/HKSAL.test.d.ts.map +1 -0
  460. package/dist/types/tests/HKTAN.test.d.ts +2 -0
  461. package/dist/types/tests/HKTAN.test.d.ts.map +1 -0
  462. package/dist/types/tests/HKVPA.test.d.ts +2 -0
  463. package/dist/types/tests/HKVPA.test.d.ts.map +1 -0
  464. package/dist/types/tests/HKVPP.test.d.ts +2 -0
  465. package/dist/types/tests/HKVPP.test.d.ts.map +1 -0
  466. package/dist/types/tests/HKWPD.test.d.ts +2 -0
  467. package/dist/types/tests/HKWPD.test.d.ts.map +1 -0
  468. package/dist/types/tests/HNSHK.test.d.ts +2 -0
  469. package/dist/types/tests/HNSHK.test.d.ts.map +1 -0
  470. package/dist/types/tests/HNVSK.test.d.ts +2 -0
  471. package/dist/types/tests/HNVSK.test.d.ts.map +1 -0
  472. package/dist/types/tests/accountDescriptor.test.d.ts +2 -0
  473. package/dist/types/tests/accountDescriptor.test.d.ts.map +1 -0
  474. package/dist/types/tests/accountReference.test.d.ts +2 -0
  475. package/dist/types/tests/accountReference.test.d.ts.map +1 -0
  476. package/dist/types/tests/bankReplyChecks.test.d.ts +2 -0
  477. package/dist/types/tests/bankReplyChecks.test.d.ts.map +1 -0
  478. package/dist/types/tests/camtParser.test.d.ts +2 -0
  479. package/dist/types/tests/camtParser.test.d.ts.map +1 -0
  480. package/dist/types/tests/client.test.d.ts +2 -0
  481. package/dist/types/tests/client.test.d.ts.map +1 -0
  482. package/dist/types/tests/credentialRedaction.test.d.ts +2 -0
  483. package/dist/types/tests/credentialRedaction.test.d.ts.map +1 -0
  484. package/dist/types/tests/creditTransfer.test.d.ts +2 -0
  485. package/dist/types/tests/creditTransfer.test.d.ts.map +1 -0
  486. package/dist/types/tests/creditTransferBank.d.ts +63 -0
  487. package/dist/types/tests/creditTransferBank.d.ts.map +1 -0
  488. package/dist/types/tests/creditTransferSafety.test.d.ts +2 -0
  489. package/dist/types/tests/creditTransferSafety.test.d.ts.map +1 -0
  490. package/dist/types/tests/datatypes.test.d.ts +2 -0
  491. package/dist/types/tests/datatypes.test.d.ts.map +1 -0
  492. package/dist/types/tests/dialog.test.d.ts +2 -0
  493. package/dist/types/tests/dialog.test.d.ts.map +1 -0
  494. package/dist/types/tests/httpClientErrorLog.test.d.ts +2 -0
  495. package/dist/types/tests/httpClientErrorLog.test.d.ts.map +1 -0
  496. package/dist/types/tests/interactionAccountDescriptor.test.d.ts +2 -0
  497. package/dist/types/tests/interactionAccountDescriptor.test.d.ts.map +1 -0
  498. package/dist/types/tests/message.test.d.ts +2 -0
  499. package/dist/types/tests/message.test.d.ts.map +1 -0
  500. package/dist/types/tests/mt535parser.test.d.ts +2 -0
  501. package/dist/types/tests/mt535parser.test.d.ts.map +1 -0
  502. package/dist/types/tests/mt940parser.test.d.ts +2 -0
  503. package/dist/types/tests/mt940parser.test.d.ts.map +1 -0
  504. package/dist/types/tests/pain001Builder.test.d.ts +2 -0
  505. package/dist/types/tests/pain001Builder.test.d.ts.map +1 -0
  506. package/dist/types/tests/pain002Parser.test.d.ts +2 -0
  507. package/dist/types/tests/pain002Parser.test.d.ts.map +1 -0
  508. package/dist/types/tests/parser.test.d.ts +2 -0
  509. package/dist/types/tests/parser.test.d.ts.map +1 -0
  510. package/dist/types/tests/partedDialog.test.d.ts +2 -0
  511. package/dist/types/tests/partedDialog.test.d.ts.map +1 -0
  512. package/dist/types/tests/partedResponse.test.d.ts +2 -0
  513. package/dist/types/tests/partedResponse.test.d.ts.map +1 -0
  514. package/dist/types/tests/statementParseFailure.test.d.ts +2 -0
  515. package/dist/types/tests/statementParseFailure.test.d.ts.map +1 -0
  516. package/dist/types/tests/tanMedia.test.d.ts +2 -0
  517. package/dist/types/tests/tanMedia.test.d.ts.map +1 -0
  518. package/dist/types/unknownSegment.d.ts +15 -0
  519. package/dist/types/unknownSegment.d.ts.map +1 -0
  520. package/dist/types/upd.d.ts +8 -0
  521. package/dist/types/upd.d.ts.map +1 -0
  522. package/dist/unknownSegment.js +11 -0
  523. package/dist/upd.js +1 -0
  524. package/package.json +59 -5
  525. package/pnpm-workspace.yaml +8 -0
  526. package/src/accountBalance.ts +8 -0
  527. package/src/accountDescriptor.ts +78 -0
  528. package/src/bankAccount.ts +59 -0
  529. package/src/bankAnswer.ts +5 -0
  530. package/src/bankTransaction.ts +25 -0
  531. package/src/bankingInformation.ts +21 -0
  532. package/src/bpd.ts +17 -0
  533. package/src/camtParser.ts +698 -0
  534. package/src/client.ts +1005 -0
  535. package/src/codes.ts +86 -0
  536. package/src/config.ts +338 -0
  537. package/src/creditCardStatement.ts +26 -0
  538. package/src/dataElements/AlphaNumeric.ts +35 -0
  539. package/src/dataElements/Amount.ts +7 -0
  540. package/src/dataElements/Binary.ts +50 -0
  541. package/src/dataElements/Country.ts +7 -0
  542. package/src/dataElements/Currency.ts +7 -0
  543. package/src/dataElements/Dat.ts +22 -0
  544. package/src/dataElements/DataElement.ts +41 -0
  545. package/src/dataElements/Digits.ts +34 -0
  546. package/src/dataElements/Float.ts +31 -0
  547. package/src/dataElements/Identification.ts +7 -0
  548. package/src/dataElements/Numeric.ts +38 -0
  549. package/src/dataElements/Text.ts +31 -0
  550. package/src/dataElements/Time.ts +24 -0
  551. package/src/dataElements/YesNo.ts +23 -0
  552. package/src/dataGroups/Account.ts +31 -0
  553. package/src/dataGroups/Balance.ts +30 -0
  554. package/src/dataGroups/BankIdentification.ts +16 -0
  555. package/src/dataGroups/DataGroup.ts +76 -0
  556. package/src/dataGroups/InternationalAccount.ts +32 -0
  557. package/src/dataGroups/Money.ts +21 -0
  558. package/src/dataGroups/RefMessage.ts +21 -0
  559. package/src/dataGroups/SepaAccount.ts +32 -0
  560. package/src/dataGroups/TimeStamp.ts +21 -0
  561. package/src/decoder.ts +125 -0
  562. package/src/dialog.ts +625 -0
  563. package/src/electronicStatement.ts +51 -0
  564. package/src/encoder.ts +87 -0
  565. package/src/format.ts +7 -0
  566. package/src/httpClient.ts +90 -0
  567. package/src/index.ts +53 -0
  568. package/src/interactions/balanceInteraction.ts +65 -0
  569. package/src/interactions/creditTransferInteraction.ts +667 -0
  570. package/src/interactions/creditcardStatementInteraction.ts +134 -0
  571. package/src/interactions/creditcardStatementInteractionHKKKU.ts +163 -0
  572. package/src/interactions/customerInteraction.ts +191 -0
  573. package/src/interactions/electronicStatementInteraction.ts +132 -0
  574. package/src/interactions/endDialogInteraction.ts +28 -0
  575. package/src/interactions/initDialogInteraction.ts +300 -0
  576. package/src/interactions/portfolioInteraction.ts +97 -0
  577. package/src/interactions/sepaAccountInteraction.ts +68 -0
  578. package/src/interactions/statementInteractionCAMT.ts +87 -0
  579. package/src/interactions/statementInteractionMT940.ts +60 -0
  580. package/src/interactions/tanMediaInteraction.ts +54 -0
  581. package/src/interactions/transferOutcome.ts +513 -0
  582. package/src/interactions/vopCheck.ts +502 -0
  583. package/src/message.ts +305 -0
  584. package/src/mt535parser.ts +199 -0
  585. package/src/mt940parser.ts +395 -0
  586. package/src/pain001Builder.ts +446 -0
  587. package/src/pain002Parser.ts +233 -0
  588. package/src/parser.ts +31 -0
  589. package/src/partedSegment.ts +19 -0
  590. package/src/segment.ts +114 -0
  591. package/src/segmentDefinition.ts +36 -0
  592. package/src/segmentHeader.ts +26 -0
  593. package/src/segments/DIKKU.ts +30 -0
  594. package/src/segments/DKKKU.ts +35 -0
  595. package/src/segments/HIBPA.ts +42 -0
  596. package/src/segments/HICAZ.ts +34 -0
  597. package/src/segments/HICAZS.ts +33 -0
  598. package/src/segments/HICCSS.ts +31 -0
  599. package/src/segments/HIEKA.ts +68 -0
  600. package/src/segments/HIEKAS.ts +36 -0
  601. package/src/segments/HIKAZ.ts +23 -0
  602. package/src/segments/HIKAZS.ts +34 -0
  603. package/src/segments/HIKIM.ts +21 -0
  604. package/src/segments/HIKKU.ts +35 -0
  605. package/src/segments/HIKKUS.ts +36 -0
  606. package/src/segments/HIKOM.ts +49 -0
  607. package/src/segments/HIPINS.ts +48 -0
  608. package/src/segments/HIRMG.ts +41 -0
  609. package/src/segments/HIRMS.ts +35 -0
  610. package/src/segments/HISAL.ts +51 -0
  611. package/src/segments/HISPA.ts +20 -0
  612. package/src/segments/HISPAS.ts +42 -0
  613. package/src/segments/HISYN.ts +28 -0
  614. package/src/segments/HITAB.ts +76 -0
  615. package/src/segments/HITAN.ts +39 -0
  616. package/src/segments/HITANS.ts +102 -0
  617. package/src/segments/HIUPA.ts +32 -0
  618. package/src/segments/HIUPD.ts +82 -0
  619. package/src/segments/HIVPAS.ts +29 -0
  620. package/src/segments/HIVPP.ts +75 -0
  621. package/src/segments/HIVPPS.ts +47 -0
  622. package/src/segments/HIWPD.ts +25 -0
  623. package/src/segments/HKCAZ.ts +42 -0
  624. package/src/segments/HKCCS.ts +43 -0
  625. package/src/segments/HKEKA.ts +69 -0
  626. package/src/segments/HKEND.ts +20 -0
  627. package/src/segments/HKIDN.ts +31 -0
  628. package/src/segments/HKKAZ.ts +40 -0
  629. package/src/segments/HKKKU.ts +41 -0
  630. package/src/segments/HKSAL.ts +35 -0
  631. package/src/segments/HKSPA.ts +28 -0
  632. package/src/segments/HKSYN.ts +21 -0
  633. package/src/segments/HKTAB.ts +23 -0
  634. package/src/segments/HKTAN.ts +72 -0
  635. package/src/segments/HKVPA.ts +26 -0
  636. package/src/segments/HKVPP.ts +46 -0
  637. package/src/segments/HKVVB.ts +32 -0
  638. package/src/segments/HKWPD.ts +52 -0
  639. package/src/segments/HNHBK.ts +33 -0
  640. package/src/segments/HNHBS.ts +20 -0
  641. package/src/segments/HNSHA.ts +38 -0
  642. package/src/segments/HNSHK.ts +145 -0
  643. package/src/segments/HNVSD.ts +22 -0
  644. package/src/segments/HNVSK.ts +110 -0
  645. package/src/segments/businessTransactionParameter.ts +33 -0
  646. package/src/segments/registry.ts +125 -0
  647. package/src/statement.ts +40 -0
  648. package/src/tanMethod.ts +32 -0
  649. package/src/tests/HIBPA.test.ts +33 -0
  650. package/src/tests/HICAZS.test.ts +24 -0
  651. package/src/tests/HICCSS.test.ts +20 -0
  652. package/src/tests/HIPINS.test.ts +19 -0
  653. package/src/tests/HIRMG.test.ts +33 -0
  654. package/src/tests/HITAB.test.ts +33 -0
  655. package/src/tests/HITANS.test.ts +27 -0
  656. package/src/tests/HIUPA.test.ts +13 -0
  657. package/src/tests/HIUPD.test.ts +13 -0
  658. package/src/tests/HIVPAS.test.ts +20 -0
  659. package/src/tests/HIVPP.test.ts +75 -0
  660. package/src/tests/HIVPPS.test.ts +37 -0
  661. package/src/tests/HIWPD.test.ts +32 -0
  662. package/src/tests/HKCAZ.test.ts +56 -0
  663. package/src/tests/HKCCS.test.ts +64 -0
  664. package/src/tests/HKEKA.test.ts +252 -0
  665. package/src/tests/HKIDN.test.ts +26 -0
  666. package/src/tests/HKKKU.test.ts +248 -0
  667. package/src/tests/HKSAL.test.ts +52 -0
  668. package/src/tests/HKTAN.test.ts +26 -0
  669. package/src/tests/HKVPA.test.ts +25 -0
  670. package/src/tests/HKVPP.test.ts +54 -0
  671. package/src/tests/HKWPD.test.ts +47 -0
  672. package/src/tests/HNSHK.test.ts +14 -0
  673. package/src/tests/HNVSK.test.ts +14 -0
  674. package/src/tests/accountDescriptor.test.ts +113 -0
  675. package/src/tests/accountReference.test.ts +150 -0
  676. package/src/tests/bankReplyChecks.test.ts +75 -0
  677. package/src/tests/camtParser.test.ts +1068 -0
  678. package/src/tests/client.test.ts +826 -0
  679. package/src/tests/credentialRedaction.test.ts +75 -0
  680. package/src/tests/creditTransfer.test.ts +2433 -0
  681. package/src/tests/creditTransferBank.ts +245 -0
  682. package/src/tests/creditTransferSafety.test.ts +573 -0
  683. package/src/tests/datatypes.test.ts +9 -0
  684. package/src/tests/dialog.test.ts +579 -0
  685. package/src/tests/httpClientErrorLog.test.ts +41 -0
  686. package/src/tests/interactionAccountDescriptor.test.ts +203 -0
  687. package/src/tests/message.test.ts +130 -0
  688. package/src/tests/mt535parser.test.ts +280 -0
  689. package/src/tests/mt940parser.test.ts +91 -0
  690. package/src/tests/pain001Builder.test.ts +474 -0
  691. package/src/tests/pain002Parser.test.ts +191 -0
  692. package/src/tests/parser.test.ts +34 -0
  693. package/src/tests/partedDialog.test.ts +309 -0
  694. package/src/tests/partedResponse.test.ts +234 -0
  695. package/src/tests/statementParseFailure.test.ts +23 -0
  696. package/src/tests/tanMedia.test.ts +163 -0
  697. package/src/unknownSegment.ts +19 -0
  698. package/src/upd.ts +8 -0
  699. package/tsconfig.json +103 -0
@@ -0,0 +1,2433 @@
1
+ // Added to lib-fints 1.5.4 for @davidvornholt/lib-fints, last on 2026-11-18. FORK.md lists the changes.
2
+ import { readFileSync } from 'node:fs';
3
+ import { afterEach, beforeEach, describe, expect, it, type MockInstance, vi } from 'vitest';
4
+ import { FinTSClient } from '../client.js';
5
+ import { UpdUsage } from '../codes.js';
6
+ import { FinTSConfig } from '../config.js';
7
+ import { extractVopResult } from '../interactions/creditTransferInteraction.js';
8
+ import { InitDialogInteraction } from '../interactions/initDialogInteraction.js';
9
+ import type { Message } from '../message.js';
10
+ import { PAIN_001_001_03, PAIN_001_001_09, SepaValidationError } from '../pain001Builder.js';
11
+ import type { HIVPPSParameter } from '../segments/HIVPPS.js';
12
+ import type { HKCCSSegment } from '../segments/HKCCS.js';
13
+ import type { HKTANSegment } from '../segments/HKTAN.js';
14
+ import type { HKVPASegment } from '../segments/HKVPA.js';
15
+ import type { HKVPPSegment } from '../segments/HKVPP.js';
16
+ import type { HNHBKSegment } from '../segments/HNHBK.js';
17
+
18
+ import {
19
+ ACCOUNT,
20
+ APPROVAL_VOIDED,
21
+ answer,
22
+ bank,
23
+ CHECK_RESULT,
24
+ createBankingInformation,
25
+ endOk,
26
+ hirms,
27
+ hitan,
28
+ hivppPending,
29
+ hivppReport,
30
+ hivppSingle,
31
+ initOk,
32
+ NO_HKVPA_NEEDED,
33
+ OK,
34
+ ORDER_MESSAGE_ID,
35
+ PAYEE_IBAN,
36
+ pain002,
37
+ REPORT_FORMAT,
38
+ sentOrders,
39
+ TAN_REQUIRED,
40
+ TRANSFER,
41
+ tanAccepted,
42
+ WARNINGS,
43
+ } from './creditTransferBank.js';
44
+
45
+ vi.mock('../httpClient.js', async () => ({
46
+ HttpClient: (await import('./creditTransferBank.js')).MockHttpClient,
47
+ }));
48
+
49
+ describe('FinTSClient SEPA credit transfer', () => {
50
+ let config: FinTSConfig;
51
+ let client: FinTSClient;
52
+ let sleep: MockInstance<(milliseconds: number) => Promise<void>>;
53
+
54
+ beforeEach(() => {
55
+ bank.responses = [];
56
+ bank.sent = [];
57
+ bank.orderMessageId = '';
58
+ config = FinTSConfig.fromBankingInformation(
59
+ 'product',
60
+ '1.0',
61
+ createBankingInformation(),
62
+ 'user',
63
+ 'pin',
64
+ 912,
65
+ );
66
+ client = new FinTSClient(config);
67
+ sleep = vi
68
+ .spyOn(
69
+ FinTSClient.prototype as unknown as { sleep: (milliseconds: number) => Promise<void> },
70
+ 'sleep',
71
+ )
72
+ .mockResolvedValue();
73
+ });
74
+
75
+ afterEach(() => {
76
+ vi.restoreAllMocks();
77
+ });
78
+
79
+ const vopParams = () =>
80
+ config.bankingInformation.bpd?.allowedTransactions.find((t) => t.transId === 'HKVPP')
81
+ ?.params as HIVPPSParameter;
82
+
83
+ const removeTransaction = (transId: string) => {
84
+ const bpd = config.bankingInformation.bpd;
85
+ if (bpd) {
86
+ bpd.allowedTransactions = bpd.allowedTransactions.filter((t) => t.transId !== transId);
87
+ }
88
+ };
89
+
90
+ describe('canTransfer', () => {
91
+ it('is true for a bank and an account that support HKCCS', () => {
92
+ expect(client.canTransfer()).toBe(true);
93
+ expect(client.canTransfer(ACCOUNT)).toBe(true);
94
+ });
95
+
96
+ it('is false for an account the UPD does not allow transfers from', () => {
97
+ expect(client.canTransfer('9876543210')).toBe(false);
98
+ });
99
+
100
+ it('leaves an account the UPD does not list HKCCS for to the bank with UPD usage 1', async () => {
101
+ const upd = config.bankingInformation.upd;
102
+ if (upd) {
103
+ upd.usage = UpdUsage.MissingUnknown;
104
+ // The fixture's IBAN for this account has wrong check digits
105
+ upd.bankAccounts[1].iban = 'DE89370400440532013000';
106
+ }
107
+ expect(client.canTransfer('9876543210')).toBe(true);
108
+
109
+ bank.responses.push(initOk(), answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')));
110
+ expect(await client.transfer('9876543210', TRANSFER)).toMatchObject({
111
+ requiresVopConfirmation: true,
112
+ });
113
+ expect(sentOrders()[1]).toEqual(['HKVPP', 'HKCCS', 'HKTAN']);
114
+ });
115
+
116
+ it('is false without a TAN method that can send the HKTAN the transfer requires', () => {
117
+ config.tanMethodId = undefined;
118
+ expect(client.canTransfer(ACCOUNT)).toBe(false);
119
+ });
120
+
121
+ it('is false for an account without IBAN', () => {
122
+ const account = config.bankingInformation.upd?.bankAccounts[0];
123
+ if (account) account.iban = undefined;
124
+ expect(client.canTransfer(ACCOUNT)).toBe(false);
125
+ });
126
+
127
+ it('is false without HKCCS in the BPD', () => {
128
+ removeTransaction('HKCCS');
129
+ expect(client.canTransfer()).toBe(false);
130
+ });
131
+
132
+ it('is false when the bank lists only pain.001 formats this library does not write', () => {
133
+ const hkspa = config.bankingInformation.bpd?.allowedTransactions.find(
134
+ (t) => t.transId === 'HKSPA',
135
+ );
136
+ (hkspa?.params as { supportedSepaFormats: string[] }).supportedSepaFormats = [
137
+ 'urn:iso:std:iso:20022:tech:xsd:pain.001.002.03',
138
+ ];
139
+ expect(client.canTransfer()).toBe(false);
140
+ });
141
+
142
+ it('is false when the bank announces HKVPP but its parameters could not be read', () => {
143
+ const hkvpp = config.bankingInformation.bpd?.allowedTransactions.find(
144
+ (t) => t.transId === 'HKVPP',
145
+ );
146
+ if (hkvpp) hkvpp.params = undefined;
147
+ expect(client.canTransfer()).toBe(false);
148
+ });
149
+
150
+ it('is false when the bank requires VoP but announces no HKVPA', () => {
151
+ removeTransaction('HKVPA');
152
+ expect(client.canTransfer()).toBe(false);
153
+ });
154
+
155
+ it('is true when the bank does not require VoP for HKCCS, or has no HKVPP at all', () => {
156
+ vopParams().vopRequiredTransactions = ['HKCSE'];
157
+ removeTransaction('HKVPA');
158
+ expect(client.canTransfer()).toBe(true);
159
+
160
+ removeTransaction('HKVPP');
161
+ expect(client.canTransfer()).toBe(true);
162
+ });
163
+ });
164
+
165
+ describe('input validation', () => {
166
+ // The cases of invalid input are the builder's tests; here only that nothing is sent
167
+ it('sends no message for invalid input', async () => {
168
+ await expect(
169
+ client.transfer(ACCOUNT, { ...TRANSFER, iban: 'DE02120300000000202052' }),
170
+ ).rejects.toBeInstanceOf(SepaValidationError);
171
+ expect(bank.sent).toHaveLength(0);
172
+ });
173
+
174
+ it('rejects an account holder name the pain.001 cannot carry, naming debtorName', async () => {
175
+ const account = config.bankingInformation.upd?.bankAccounts[0];
176
+ if (account) account.holder1 = 'Erika Mustermann ★';
177
+
178
+ await expect(client.transfer(ACCOUNT, TRANSFER)).rejects.toMatchObject({
179
+ field: 'debtorName',
180
+ });
181
+ expect(bank.sent).toHaveLength(0);
182
+
183
+ bank.responses.push(initOk(), answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')));
184
+ const response = await client.transfer(ACCOUNT, {
185
+ ...TRANSFER,
186
+ debtorName: 'Erika Mustermann',
187
+ });
188
+ expect(response.requiresVopConfirmation).toBe(true);
189
+ });
190
+
191
+ it('rejects an account without IBAN', async () => {
192
+ const account = config.bankingInformation.upd?.bankAccounts[0];
193
+ if (account) account.iban = undefined;
194
+ await expect(client.transfer(ACCOUNT, TRANSFER)).rejects.toThrow(/has no IBAN/);
195
+ expect(bank.sent).toHaveLength(0);
196
+ });
197
+ });
198
+
199
+ describe('payee matches', () => {
200
+ it('goes to the TAN without HKVPA when the bank answers 3091', async () => {
201
+ bank.responses.push(
202
+ initOk(),
203
+ answer(
204
+ WARNINGS,
205
+ hirms(3, NO_HKVPA_NEEDED),
206
+ hirms(5, TAN_REQUIRED),
207
+ hivppSingle('RCVC'),
208
+ hitan(),
209
+ ),
210
+ );
211
+
212
+ const response = await client.transfer(ACCOUNT, TRANSFER);
213
+
214
+ expect(response).toMatchObject({
215
+ success: true,
216
+ requiresTan: true,
217
+ requiresVopConfirmation: false,
218
+ tanReference: 'TAN-REF-1',
219
+ endToEndId: 'E2E-0001',
220
+ vop: { result: 'match', code: 'RCVC', iban: PAYEE_IBAN },
221
+ });
222
+ expect(response.vop?.notice).toBe('Bei Abweichungen haftet die Bank nicht.');
223
+ expect(sentOrders()).toEqual([
224
+ ['HKIDN', 'HKVVB', 'HKTAN'],
225
+ ['HKVPP', 'HKCCS', 'HKTAN'],
226
+ ]);
227
+
228
+ const hkvpp = bank.sent[1].findSegment<HKVPPSegment>('HKVPP');
229
+ expect(hkvpp?.supportedReports).toEqual(['urn:iso:std:iso:20022:tech:xsd:pain.002.001.10']);
230
+ expect(hkvpp?.pollingId).toBeUndefined();
231
+ const hkccs = bank.sent[1].findSegment<HKCCSSegment>('HKCCS');
232
+ expect(hkccs?.sepaDescriptor).toBe(PAIN_001_001_09);
233
+ expect(hkccs?.account).toEqual({ iban: 'DE89370400440532013000', bic: undefined });
234
+ expect(bank.sent[1].findSegment<HKTANSegment>('HKTAN')).toMatchObject({
235
+ tanProcess: '4',
236
+ segId: 'HKCCS',
237
+ });
238
+
239
+ bank.responses.push(tanAccepted(), endOk());
240
+ const done = await client.transferWithTan('TAN-REF-1', '123456');
241
+
242
+ expect(done).toMatchObject({
243
+ success: true,
244
+ requiresTan: false,
245
+ requiresVopConfirmation: false,
246
+ vop: { result: 'match' },
247
+ });
248
+ expect(sentOrders().slice(2)).toEqual([['HKTAN'], ['HKEND']]);
249
+ expect(bank.sent[2].findSegment<HKTANSegment>('HKTAN')).toMatchObject({
250
+ tanProcess: '2',
251
+ segId: 'HKCCS',
252
+ orderRef: 'TAN-REF-1',
253
+ });
254
+ expect(bank.responses).toHaveLength(0);
255
+ });
256
+
257
+ it('sends HKVPA with the TAN when the bank does not answer 3091', async () => {
258
+ bank.responses.push(
259
+ initOk(),
260
+ answer(OK, hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
261
+ );
262
+
263
+ const response = await client.transfer(ACCOUNT, TRANSFER);
264
+ expect(response).toMatchObject({ requiresTan: true, requiresVopConfirmation: false });
265
+
266
+ bank.responses.push(tanAccepted(), endOk());
267
+ const done = await client.transferWithTan('TAN-REF-1', '123456');
268
+
269
+ expect(done).toMatchObject({ success: true, requiresTan: false });
270
+ expect(sentOrders()[2]).toEqual(['HKVPA', 'HKTAN']);
271
+ expect(bank.sent[2].findSegment<HKVPASegment>('HKVPA')?.vopId).toBe('VOP-01');
272
+ });
273
+
274
+ it('sends HKVPA only with the first status request of a decoupled TAN method', async () => {
275
+ client.selectTanMethod(946);
276
+ bank.responses.push(
277
+ initOk(),
278
+ answer(
279
+ OK,
280
+ hirms(5, TAN_REQUIRED, '3955::Bitte bestaetigen Sie den Auftrag in Ihrer App.'),
281
+ hivppSingle('RCVC'),
282
+ hitan(),
283
+ ),
284
+ );
285
+
286
+ const response = await client.transfer(ACCOUNT, TRANSFER);
287
+ expect(response).toMatchObject({ requiresTan: true, vop: { result: 'match' } });
288
+
289
+ bank.responses.push(
290
+ answer(
291
+ WARNINGS,
292
+ hirms(4, '3956::Starke Kundenauthentifizierung noch ausstehend.'),
293
+ hitan('TAN-REF-1', 'S'),
294
+ ),
295
+ );
296
+ const pending = await client.transferWithTan('TAN-REF-1');
297
+ expect(pending).toMatchObject({ success: true, requiresTan: true });
298
+
299
+ bank.responses.push(tanAccepted(), endOk());
300
+ const done = await client.transferWithTan('TAN-REF-1');
301
+
302
+ expect(done).toMatchObject({ success: true, requiresTan: false });
303
+ expect(sentOrders().slice(2)).toEqual([['HKVPA', 'HKTAN'], ['HKTAN'], ['HKEND']]);
304
+ expect(bank.sent[3].findSegment<HKTANSegment>('HKTAN')?.tanProcess).toBe('S');
305
+ });
306
+
307
+ it('hands a match back for confirmation when the bank asks for no TAN yet', async () => {
308
+ bank.responses.push(initOk(), answer(OK, hirms(3, CHECK_RESULT), hivppSingle('RCVC')));
309
+
310
+ const response = await client.transfer(ACCOUNT, TRANSFER);
311
+
312
+ expect(response).toMatchObject({
313
+ success: true,
314
+ requiresTan: false,
315
+ requiresVopConfirmation: true,
316
+ vop: { result: 'match' },
317
+ });
318
+ });
319
+
320
+ it('hands a match back for confirmation when the bank voids the approval (3945, observed at Commerzbank)', async () => {
321
+ const report = pain002('RCVC');
322
+ bank.responses.push(
323
+ initOk(),
324
+ answer(WARNINGS, hirms(5, TAN_REQUIRED, APPROVAL_VOIDED), hivppReport(report), hitan()),
325
+ );
326
+
327
+ const response = await client.transfer(ACCOUNT, TRANSFER);
328
+
329
+ expect(response).toMatchObject({
330
+ success: true,
331
+ requiresTan: false,
332
+ requiresVopConfirmation: true,
333
+ vop: { result: 'match', code: 'RCVC', iban: PAYEE_IBAN },
334
+ });
335
+ expect(response.tanReference).toBeUndefined();
336
+ expect(response.vop?.paymentStatusReport?.transactions[0].endToEndId).toBe('E2E-0001');
337
+
338
+ bank.responses.push(answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')));
339
+ const confirmed = await client.confirmTransfer(response.transferId);
340
+ expect(confirmed).toMatchObject({ requiresTan: true, tanReference: 'TAN-REF-2' });
341
+ expect(sentOrders()[2]).toEqual(['HKVPA', 'HKCCS', 'HKTAN']);
342
+ });
343
+
344
+ it('asks the caller when the bank voids the approval only in answer to the TAN (E.8.1 rule 5)', async () => {
345
+ bank.responses.push(
346
+ initOk(),
347
+ answer(OK, hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
348
+ answer(WARNINGS, hirms(3, APPROVAL_VOIDED)),
349
+ );
350
+
351
+ const { transferId } = await client.transfer(ACCOUNT, TRANSFER);
352
+ const response = await client.transferWithTan('TAN-REF-1', '123456');
353
+
354
+ expect(response).toMatchObject({
355
+ success: true,
356
+ requiresTan: false,
357
+ requiresVopConfirmation: true,
358
+ });
359
+
360
+ bank.responses.push(
361
+ answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')),
362
+ tanAccepted(),
363
+ endOk(),
364
+ );
365
+ await client.confirmTransfer(transferId);
366
+ const done = await client.transferWithTan('TAN-REF-2', '654321');
367
+
368
+ expect(done).toMatchObject({ success: true, requiresTan: false });
369
+ expect(sentOrders().slice(2)).toEqual([
370
+ ['HKVPA', 'HKTAN'],
371
+ ['HKVPA', 'HKCCS', 'HKTAN'],
372
+ ['HKTAN'],
373
+ ['HKEND'],
374
+ ]);
375
+ });
376
+ });
377
+
378
+ describe('payee deviates', () => {
379
+ it('reports a close match with the suggested name and continues only on confirmTransfer()', async () => {
380
+ vopParams().noticeStructured = true;
381
+ bank.responses.push(
382
+ initOk(),
383
+ // Sparkassen fire the pushTAN already with the first message (reported in
384
+ // python-fints PR #223); the TAN is dropped, confirmTransfer brings a new one
385
+ answer(
386
+ WARNINGS,
387
+ hirms(3, CHECK_RESULT),
388
+ hirms(5, TAN_REQUIRED),
389
+ hivppSingle('RVMC', { closeMatchName: 'Max Mustermann' }),
390
+ hitan(),
391
+ ),
392
+ );
393
+
394
+ const response = await client.transfer(ACCOUNT, { ...TRANSFER, name: 'Max Musterman' });
395
+
396
+ expect(response).toMatchObject({
397
+ success: true,
398
+ requiresTan: false,
399
+ requiresVopConfirmation: true,
400
+ vop: {
401
+ result: 'closeMatch',
402
+ code: 'RVMC',
403
+ suggestedName: 'Max Mustermann',
404
+ notice: 'Bei Abweichungen haftet die Bank nicht.',
405
+ noticeStructured: true,
406
+ },
407
+ });
408
+ expect(response.tanReference).toBeUndefined();
409
+ expect(response.tanChallenge).toBeUndefined();
410
+ expect(bank.sent).toHaveLength(2);
411
+
412
+ bank.responses.push(answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')));
413
+ const confirmed = await client.confirmTransfer(response.transferId);
414
+
415
+ expect(confirmed).toMatchObject({
416
+ success: true,
417
+ requiresTan: true,
418
+ requiresVopConfirmation: false,
419
+ tanReference: 'TAN-REF-2',
420
+ vop: { result: 'closeMatch' },
421
+ });
422
+ expect(sentOrders()[2]).toEqual(['HKVPA', 'HKCCS', 'HKTAN']);
423
+ expect(bank.sent[2].findSegment<HKVPASegment>('HKVPA')?.vopId).toBe('VOP-01');
424
+ // The identical order, not a new one
425
+ expect(bank.sent[2].findSegment<HKCCSSegment>('HKCCS')?.sepaPainMessage).toBe(
426
+ bank.sent[1].findSegment<HKCCSSegment>('HKCCS')?.sepaPainMessage,
427
+ );
428
+
429
+ bank.responses.push(tanAccepted(), endOk());
430
+ const done = await client.transferWithTan('TAN-REF-2', '123456');
431
+
432
+ expect(done).toMatchObject({ success: true, requiresTan: false });
433
+ expect(sentOrders().slice(3)).toEqual([['HKTAN'], ['HKEND']]);
434
+ });
435
+
436
+ it('reads the close match name from the pain.002 reason, decoded as UTF-8', async () => {
437
+ const report = pain002('RVMC', 'Jürgen Müller');
438
+ bank.responses.push(initOk(), answer(WARNINGS, hirms(3, CHECK_RESULT), hivppReport(report)));
439
+
440
+ const response = await client.transfer(ACCOUNT, TRANSFER);
441
+
442
+ expect(response.vop).toMatchObject({
443
+ result: 'closeMatch',
444
+ suggestedName: 'Jürgen Müller',
445
+ reasons: ['Jürgen Müller'],
446
+ });
447
+ });
448
+
449
+ it('reports no match, and cancelTransfer() ends the dialog without sending the order again', async () => {
450
+ bank.responses.push(initOk(), answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')));
451
+
452
+ const response = await client.transfer(ACCOUNT, TRANSFER);
453
+ expect(response).toMatchObject({
454
+ requiresVopConfirmation: true,
455
+ vop: { result: 'noMatch', code: 'RVNM' },
456
+ });
457
+
458
+ bank.responses.push(endOk());
459
+ await client.cancelTransfer(response.transferId);
460
+
461
+ expect(sentOrders().slice(2)).toEqual([['HKEND']]);
462
+ await expect(client.confirmTransfer(response.transferId)).rejects.toThrow(
463
+ /no transfer is waiting/,
464
+ );
465
+ });
466
+
467
+ it('reports a check that was not possible, with the reason', async () => {
468
+ bank.responses.push(
469
+ initOk(),
470
+ answer(
471
+ WARNINGS,
472
+ hirms(3, CHECK_RESULT),
473
+ hivppSingle('RVNA', { reason: 'Empfaengerbank nimmt nicht teil' }),
474
+ ),
475
+ );
476
+
477
+ const response = await client.transfer(ACCOUNT, TRANSFER);
478
+
479
+ expect(response).toMatchObject({
480
+ requiresVopConfirmation: true,
481
+ vop: {
482
+ result: 'notApplicable',
483
+ code: 'RVNA',
484
+ notApplicableReason: 'Empfaengerbank nimmt nicht teil',
485
+ },
486
+ });
487
+ });
488
+
489
+ it('reports a VoP ID without any result as not applicable', async () => {
490
+ bank.responses.push(
491
+ initOk(),
492
+ answer(
493
+ WARNINGS,
494
+ hirms(3, CHECK_RESULT),
495
+ "HIVPP:5:1:3+@11@notprovided++++++Der Namensabgleich war nicht moeglich.'",
496
+ ),
497
+ );
498
+
499
+ const response = await client.transfer(ACCOUNT, TRANSFER);
500
+
501
+ expect(response).toMatchObject({
502
+ requiresVopConfirmation: true,
503
+ vop: { result: 'notApplicable', notice: 'Der Namensabgleich war nicht moeglich.' },
504
+ });
505
+ expect(response.vop?.code).toBeUndefined();
506
+
507
+ bank.responses.push(answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')));
508
+ await client.confirmTransfer(response.transferId);
509
+ expect(bank.sent[2].findSegment<HKVPASegment>('HKVPA')?.vopId).toBe('notprovided');
510
+ });
511
+ });
512
+
513
+ describe('asynchronous check', () => {
514
+ it('polls with polling ID and touchdown point, honouring the wait time (as observed at Atruvia banks)', async () => {
515
+ bank.responses.push(
516
+ initOk(),
517
+ answer(
518
+ WARNINGS,
519
+ hirms(3, '3040::Es liegen weitere Informationen vor.:TP-0001'),
520
+ hirms(5, '3905::Es wurde keine Challenge erzeugt.'),
521
+ hivppPending('POLL-0001', 2),
522
+ ),
523
+ answer(
524
+ WARNINGS,
525
+ hirms(3, '3040::Es liegen weitere Informationen vor.:TP-0002'),
526
+ hivppPending('POLL-0001', 1),
527
+ ),
528
+ answer(OK, hirms(3, CHECK_RESULT), hivppReport(pain002('RCVC'))),
529
+ );
530
+
531
+ const response = await client.transfer(ACCOUNT, TRANSFER);
532
+
533
+ expect(response).toMatchObject({
534
+ success: true,
535
+ requiresTan: false,
536
+ requiresVopConfirmation: true,
537
+ vop: { result: 'match' },
538
+ });
539
+ // The answers of every poll, not only of the last one
540
+ expect(response.bankAnswers.map((answer) => answer.code)).toEqual(
541
+ expect.arrayContaining([3040, 3905, 3090]),
542
+ );
543
+ expect(
544
+ response.bankAnswers.filter((answer) => answer.code === 3040).map((a) => a.params?.[0]),
545
+ ).toEqual(['TP-0001', 'TP-0002']);
546
+ expect(sleep.mock.calls).toEqual([[2000], [1000]]);
547
+ expect(sentOrders()).toEqual([
548
+ ['HKIDN', 'HKVVB', 'HKTAN'],
549
+ ['HKVPP', 'HKCCS', 'HKTAN'],
550
+ ['HKVPP'],
551
+ ['HKVPP'],
552
+ ]);
553
+ expect(bank.sent[2].findSegment<HKVPPSegment>('HKVPP')).toMatchObject({
554
+ pollingId: 'POLL-0001',
555
+ touchdownPoint: 'TP-0001',
556
+ });
557
+ expect(bank.sent[3].findSegment<HKVPPSegment>('HKVPP')).toMatchObject({
558
+ pollingId: 'POLL-0001',
559
+ touchdownPoint: 'TP-0002',
560
+ });
561
+
562
+ bank.responses.push(
563
+ answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')),
564
+ tanAccepted(),
565
+ endOk(),
566
+ );
567
+ await client.confirmTransfer(response.transferId);
568
+ const done = await client.transferWithTan('TAN-REF-2', '123456');
569
+
570
+ expect(done).toMatchObject({ success: true, requiresTan: false });
571
+ expect(sentOrders().slice(4)).toEqual([['HKVPA', 'HKCCS', 'HKTAN'], ['HKTAN'], ['HKEND']]);
572
+ });
573
+
574
+ it('polls with the touchdown point alone when the bank sends no polling ID', async () => {
575
+ bank.responses.push(
576
+ initOk(),
577
+ answer(WARNINGS, hirms(3, '3040::Weitere Daten.:TP-1'), "HIVPP:5:1:3++++++++2'"),
578
+ answer(WARNINGS, hirms(3, '3040::Weitere Daten.:TP-2'), "HIVPP:5:1:3++++++++1'"),
579
+ answer(OK, hirms(3, CHECK_RESULT), hivppSingle('RVNM')),
580
+ );
581
+
582
+ const response = await client.transfer(ACCOUNT, TRANSFER);
583
+
584
+ expect(response).toMatchObject({ requiresVopConfirmation: true, vop: { result: 'noMatch' } });
585
+ expect(sentOrders().slice(2)).toEqual([['HKVPP'], ['HKVPP']]);
586
+ const polls = bank.sent.slice(2).map((m) => m.findSegment<HKVPPSegment>('HKVPP'));
587
+ expect(polls[0]?.touchdownPoint).toBe('TP-1');
588
+ expect(polls[0]?.pollingId).toBeUndefined();
589
+ expect(polls[1]?.touchdownPoint).toBe('TP-2');
590
+ });
591
+
592
+ it('asks again only with a current touchdown point, the polling ID alongside it', async () => {
593
+ bank.responses.push(
594
+ initOk(),
595
+ answer(WARNINGS, hirms(3, '3040::Weitere Daten.:TP-1'), hivppPending('POLL-0001', 1)),
596
+ // No 3040: the polling ID alone is no touchdown point to ask again from
597
+ answer(OK, hivppPending('POLL-0001', 1)),
598
+ endOk(),
599
+ );
600
+
601
+ const response = await client.transfer(ACCOUNT, TRANSFER);
602
+
603
+ expect(response).toMatchObject({ success: false, requiresVopConfirmation: false });
604
+ expect(response.failureReason).toMatch(/without a VoP ID/);
605
+ expect(sentOrders().slice(2)).toEqual([['HKVPP'], ['HKEND']]);
606
+ expect(bank.sent[2].findSegment<HKVPPSegment>('HKVPP')).toMatchObject({
607
+ pollingId: 'POLL-0001',
608
+ touchdownPoint: 'TP-1',
609
+ });
610
+ });
611
+
612
+ it('gives up after 60 seconds of waiting without executing anything', async () => {
613
+ bank.responses.push(
614
+ initOk(),
615
+ answer(
616
+ WARNINGS,
617
+ hirms(3, '3040::Bitte erneut anfragen.:TP-0001'),
618
+ hivppPending('POLL-0001', 9),
619
+ ),
620
+ );
621
+ for (let i = 0; i < 6; i++) {
622
+ bank.responses.push(
623
+ answer(
624
+ WARNINGS,
625
+ hirms(3, '3040::Bitte erneut anfragen.:TP-0001'),
626
+ hivppPending('POLL-0001', 9),
627
+ ),
628
+ );
629
+ }
630
+ bank.responses.push(endOk());
631
+
632
+ const response = await client.transfer(ACCOUNT, TRANSFER);
633
+
634
+ expect(response.success).toBe(false);
635
+ expect(response.failureReason).toMatch(/within 60 seconds/);
636
+ expect(sleep).toHaveBeenCalledTimes(6);
637
+ expect(sentOrders().at(-1)).toEqual(['HKEND']);
638
+ expect(sentOrders().filter((segments) => segments.includes('HKCCS'))).toHaveLength(1);
639
+ expect(bank.responses).toHaveLength(0);
640
+ });
641
+ });
642
+
643
+ describe('execution without a decision', () => {
644
+ it('accepts a transfer the bank executed straight away (3091 with 3076)', async () => {
645
+ bank.responses.push(
646
+ initOk(),
647
+ answer(
648
+ WARNINGS,
649
+ hirms(3, NO_HKVPA_NEEDED),
650
+ hirms(5, '3076::Keine starke Kundenauthentifizierung notwendig.'),
651
+ hivppSingle('RCVC'),
652
+ ),
653
+ endOk(),
654
+ );
655
+
656
+ const response = await client.transfer(ACCOUNT, TRANSFER);
657
+
658
+ expect(response).toMatchObject({
659
+ success: true,
660
+ requiresTan: false,
661
+ requiresVopConfirmation: false,
662
+ vop: { result: 'match' },
663
+ });
664
+ expect(sentOrders().at(-1)).toEqual(['HKEND']);
665
+ });
666
+
667
+ it('authorises a match the bank holds without SCA (3076 without 3091) with HKVPA alone', async () => {
668
+ bank.responses.push(
669
+ initOk(),
670
+ answer(
671
+ WARNINGS,
672
+ hirms(5, '3076::Keine starke Kundenauthentifizierung notwendig.'),
673
+ hivppSingle('RCVC'),
674
+ ),
675
+ answer(OK, hirms(3, '0020::Auftrag ausgefuehrt.')),
676
+ endOk(),
677
+ );
678
+
679
+ const first = await client.transfer(ACCOUNT, TRANSFER);
680
+ expect(first).toMatchObject({
681
+ success: true,
682
+ requiresVopConfirmation: true,
683
+ vop: { result: 'match' },
684
+ });
685
+
686
+ const response = await client.confirmTransfer(first.transferId);
687
+
688
+ expect(response).toMatchObject({
689
+ success: true,
690
+ requiresTan: false,
691
+ requiresVopConfirmation: false,
692
+ outcomeUncertain: false,
693
+ });
694
+ expect(sentOrders().slice(1)).toEqual([['HKVPP', 'HKCCS', 'HKTAN'], ['HKVPA'], ['HKEND']]);
695
+ });
696
+
697
+ it('authorises with HKVPA alone a held match whose result came by polling (3076 before it)', async () => {
698
+ bank.responses.push(
699
+ initOk(),
700
+ answer(
701
+ WARNINGS,
702
+ hirms(3, '3040::Weitere Daten.:TP-1'),
703
+ hirms(5, '3076::Keine starke Kundenauthentifizierung notwendig.'),
704
+ hivppPending(),
705
+ ),
706
+ answer(OK, hirms(3, CHECK_RESULT), hivppSingle('RCVC')),
707
+ answer(OK, hirms(3, '0020::Auftrag ausgefuehrt.')),
708
+ endOk(),
709
+ );
710
+
711
+ const first = await client.transfer(ACCOUNT, TRANSFER);
712
+ expect(first).toMatchObject({ requiresVopConfirmation: true, vop: { result: 'match' } });
713
+
714
+ const done = await client.confirmTransfer(first.transferId);
715
+
716
+ expect(done).toMatchObject({ success: true, requiresTan: false, outcomeUncertain: false });
717
+ expect(sentOrders().slice(3)).toEqual([['HKVPA'], ['HKEND']]);
718
+ });
719
+
720
+ it('reports an authorisation alone without an acceptance as an uncertain outcome', async () => {
721
+ bank.responses.push(
722
+ initOk(),
723
+ answer(
724
+ WARNINGS,
725
+ hirms(5, '3076::Keine starke Kundenauthentifizierung notwendig.'),
726
+ hivppSingle('RCVC'),
727
+ ),
728
+ answer(WARNINGS),
729
+ endOk(),
730
+ );
731
+
732
+ const first = await client.transfer(ACCOUNT, TRANSFER);
733
+ const response = await client.confirmTransfer(first.transferId);
734
+
735
+ expect(response).toMatchObject({ success: false, outcomeUncertain: true });
736
+ expect(sentOrders().slice(2)).toEqual([['HKVPA'], ['HKEND']]);
737
+ });
738
+
739
+ it('reports an order the bank accepted as accepted, whatever the result, so it is not sent twice', async () => {
740
+ bank.responses.push(
741
+ initOk(),
742
+ answer(OK, hirms(4, '0020::Auftrag ausgefuehrt.'), hivppSingle('RVNM')),
743
+ endOk(),
744
+ );
745
+
746
+ const response = await client.transfer(ACCOUNT, TRANSFER);
747
+
748
+ expect(response).toMatchObject({
749
+ success: true,
750
+ requiresVopConfirmation: false,
751
+ vop: { result: 'noMatch' },
752
+ });
753
+ await expect(client.confirmTransfer(response.transferId)).rejects.toThrow();
754
+ });
755
+ });
756
+
757
+ describe('payment status reports', () => {
758
+ const COUNTS = (status: string, count = 1) =>
759
+ `<NbOfTxsPerSts><DtldNbOfTxs>${count}</DtldNbOfTxs><DtldSts>${status}</DtldSts></NbOfTxsPerSts>`;
760
+ const withoutTransactions = (report: string, counts: string) =>
761
+ report
762
+ .replace(/<TxInfAndSts>.*?<\/TxInfAndSts>/, counts)
763
+ .replace('</OrgnlGrpInfAndSts>', `${counts}</OrgnlGrpInfAndSts>`);
764
+ const latin1 = (text: string) => Buffer.from(text, 'utf8').toString('latin1');
765
+ const transferWithReport = async (report: string) => {
766
+ bank.responses.push(initOk(), answer(WARNINGS, hirms(3, CHECK_RESULT), hivppReport(report)));
767
+ return client.transfer(ACCOUNT, TRANSFER);
768
+ };
769
+
770
+ it('reads the transaction status below the aggregate status RVCM', async () => {
771
+ const report = pain002('RVMC', 'Erika Mustermann')
772
+ .replace('</OrgnlGrpInfAndSts>', '<GrpSts>RVCM</GrpSts></OrgnlGrpInfAndSts>')
773
+ .replace('<TxInfAndSts>', '<PmtInfSts>RVCM</PmtInfSts><TxInfAndSts>');
774
+
775
+ expect((await transferWithReport(report)).vop).toMatchObject({
776
+ result: 'closeMatch',
777
+ suggestedName: 'Erika Mustermann',
778
+ });
779
+ });
780
+
781
+ it('reads a single match the report gives only as a count', async () => {
782
+ const report = withoutTransactions(pain002('RCVC'), COUNTS('RCVC'));
783
+ bank.responses.push(
784
+ initOk(),
785
+ answer(OK, hirms(3, NO_HKVPA_NEEDED), hirms(5, TAN_REQUIRED), hivppReport(report), hitan()),
786
+ );
787
+
788
+ expect(await client.transfer(ACCOUNT, TRANSFER)).toMatchObject({
789
+ success: true,
790
+ requiresTan: true,
791
+ vop: { result: 'match', code: 'RCVC' },
792
+ });
793
+ });
794
+
795
+ const transferWithTanAndReport = async (report: string) => {
796
+ bank.responses.push(
797
+ initOk(),
798
+ answer(OK, hirms(5, TAN_REQUIRED), hivppReport(report), hitan()),
799
+ endOk(),
800
+ );
801
+ return client.transfer(ACCOUNT, TRANSFER);
802
+ };
803
+
804
+ it('stops at a transaction status the counts contradict', async () => {
805
+ const report = pain002('RCVC').replace(
806
+ '</OrgnlGrpInfAndSts>',
807
+ `${COUNTS('RVNM')}</OrgnlGrpInfAndSts>`,
808
+ );
809
+
810
+ const response = await transferWithTanAndReport(report);
811
+
812
+ expect(response).toMatchObject({ success: false, requiresTan: false });
813
+ expect(response.failureReason).toMatch(/contradicts/);
814
+ });
815
+
816
+ it('stops at a report about another payment', async () => {
817
+ const response = await transferWithTanAndReport(
818
+ pain002('RCVC').replace('E2E-0001', 'OTHER-INVOICE'),
819
+ );
820
+
821
+ expect(response).toMatchObject({ success: false, requiresTan: false });
822
+ expect(response.failureReason).toMatch(/another payment/);
823
+ });
824
+
825
+ it('stops at a report about another order', async () => {
826
+ const response = await transferWithTanAndReport(
827
+ pain002('RCVC').replace(ORDER_MESSAGE_ID, 'SOME-OTHER-ORDER'),
828
+ );
829
+
830
+ expect(response).toMatchObject({ success: false, requiresTan: false });
831
+ expect(response.failureReason).toMatch(/another order/);
832
+ });
833
+
834
+ it('stops at counts that do not name one result', async () => {
835
+ const report = withoutTransactions(pain002('RCVC'), COUNTS('RCVC') + COUNTS('RVNM'));
836
+
837
+ const response = await transferWithReport(report);
838
+
839
+ expect(response).toMatchObject({ success: false, requiresVopConfirmation: false });
840
+ expect(response.failureReason).toMatch(/not executed/);
841
+ });
842
+
843
+ it('stops at a mismatch the report does not detail', async () => {
844
+ const report = pain002('RCVC')
845
+ .replace(/<TxInfAndSts>.*?<\/TxInfAndSts>/, '')
846
+ .replace('</OrgnlGrpInfAndSts>', '<GrpSts>RVCM</GrpSts></OrgnlGrpInfAndSts>');
847
+
848
+ expect(await transferWithReport(report)).toMatchObject({
849
+ success: false,
850
+ requiresVopConfirmation: false,
851
+ });
852
+ });
853
+
854
+ it('joins a payee name continued after 105 characters, dropping the quote mark', async () => {
855
+ const first = 'A'.repeat(105);
856
+ const report = pain002('RVMC', first).replace(
857
+ `${first}</AddtlInf>`,
858
+ `${first}</AddtlInf><AddtlInf>${latin1('“')} GmbH</AddtlInf>`,
859
+ );
860
+
861
+ expect((await transferWithReport(report)).vop?.suggestedName).toBe(`${first} GmbH`);
862
+ });
863
+
864
+ it('keeps the space at the boundary of a continued payee name', async () => {
865
+ const name = `${'A'.repeat(104)} B`;
866
+ const report = pain002(
867
+ 'RVMC',
868
+ `${name.slice(0, 105)}</AddtlInf><AddtlInf>${name.slice(105)}`,
869
+ );
870
+
871
+ expect((await transferWithReport(report)).vop?.suggestedName).toBe(name);
872
+ });
873
+
874
+ it('decodes numeric character references in the payee name', async () => {
875
+ const report = pain002('RVMC', 'J&#252;rgen M&#xFC;ller');
876
+
877
+ expect((await transferWithReport(report)).vop?.suggestedName).toBe('Jürgen Müller');
878
+ });
879
+
880
+ it('reads the reason code of a check that was not possible', async () => {
881
+ const report = pain002('RVNA', 'timed out').replace(
882
+ '<AddtlInf>timed out</AddtlInf>',
883
+ '<Rsn><Cd>AB11</Cd></Rsn>',
884
+ );
885
+
886
+ expect((await transferWithReport(report)).vop).toMatchObject({
887
+ result: 'notApplicable',
888
+ notApplicableReason: 'AB11',
889
+ });
890
+ });
891
+
892
+ it('joins a report the bank splits across two answers', async () => {
893
+ const report = pain002('RVMC', 'Jürgen Müller');
894
+ const cut = report.indexOf('M', report.indexOf('<AddtlInf>')) + 3;
895
+ const [head, tail] = [report.slice(0, cut), report.slice(cut)];
896
+ bank.responses.push(
897
+ initOk(),
898
+ answer(
899
+ WARNINGS,
900
+ hirms(3, '3040::Weitere Daten.:TP-1'),
901
+ `HIVPP:5:1:3+++@4@POLL+${REPORT_FORMAT}+@${head.length}@${head}'`,
902
+ ),
903
+ answer(OK, hirms(3, CHECK_RESULT), hivppReport(tail)),
904
+ );
905
+
906
+ const response = await client.transfer(ACCOUNT, TRANSFER);
907
+
908
+ expect(response.vop).toMatchObject({ result: 'closeMatch', suggestedName: 'Jürgen Müller' });
909
+ });
910
+
911
+ it('takes a complete report in place of an earlier one', async () => {
912
+ const pending = pain002('PDNG');
913
+ bank.responses.push(
914
+ initOk(),
915
+ answer(
916
+ WARNINGS,
917
+ hirms(3, '3040::Weitere Daten.:TP-1'),
918
+ `HIVPP:5:1:3+++@4@POLL+${REPORT_FORMAT}+@${pending.length}@${pending}'`,
919
+ ),
920
+ answer(OK, hirms(3, CHECK_RESULT), hivppReport(pain002('RVNM'))),
921
+ );
922
+
923
+ expect((await client.transfer(ACCOUNT, TRANSFER)).vop).toMatchObject({ result: 'noMatch' });
924
+ });
925
+
926
+ it('keeps the transaction details of an earlier delivery when the last one has only counts', async () => {
927
+ vopParams().reportDelivery = 'S';
928
+ const before = pain002('RVMC', 'Company A');
929
+ const after = withoutTransactions(pain002('RVMC'), COUNTS('RVMC'));
930
+ bank.responses.push(
931
+ initOk(),
932
+ answer(
933
+ WARNINGS,
934
+ hirms(3, '3040::Weitere Daten.:TP-1'),
935
+ `HIVPP:5:1:3+++@1@P+${REPORT_FORMAT}+@${before.length}@${before}'`,
936
+ ),
937
+ answer(OK, hirms(3, CHECK_RESULT), hivppReport(after)),
938
+ );
939
+
940
+ expect((await client.transfer(ACCOUNT, TRANSFER)).vop).toMatchObject({
941
+ result: 'closeMatch',
942
+ suggestedName: 'Company A',
943
+ });
944
+ });
945
+
946
+ it('keeps the notice and reason lines of the delivery whose details it keeps', async () => {
947
+ vopParams().reportDelivery = 'S';
948
+ const before = pain002('RVMC', 'Company A').replace(
949
+ '</OrgnlGrpInfAndSts>',
950
+ '<StsRsnInf><AddtlInf>RVMC Achtung.</AddtlInf></StsRsnInf></OrgnlGrpInfAndSts>',
951
+ );
952
+ const after = withoutTransactions(pain002('RVMC'), COUNTS('RVMC'));
953
+ bank.responses.push(
954
+ initOk(),
955
+ answer(
956
+ WARNINGS,
957
+ hirms(3, '3040::Weitere Daten.:TP-1'),
958
+ `HIVPP:5:1:3+++@1@P+${REPORT_FORMAT}+@${before.length}@${before}++Hinweis.'`,
959
+ ),
960
+ answer(OK, hirms(3, CHECK_RESULT), hivppReport(after)),
961
+ );
962
+
963
+ expect((await client.transfer(ACCOUNT, TRANSFER)).vop).toMatchObject({
964
+ result: 'closeMatch',
965
+ suggestedName: 'Company A',
966
+ notice: 'Hinweis.',
967
+ reasons: ['RVMC Achtung.', 'Company A'],
968
+ paymentStatusReport: { groupReasons: ['RVMC Achtung.'] },
969
+ });
970
+ });
971
+
972
+ it('checks the payee of an earlier delivery whose details it keeps', async () => {
973
+ vopParams().reportDelivery = 'S';
974
+ const before = pain002('RVMC', 'Company A', 'Erika Musterfrau');
975
+ const after = withoutTransactions(pain002('RVMC'), COUNTS('RVMC'));
976
+ bank.responses.push(
977
+ initOk(),
978
+ answer(
979
+ WARNINGS,
980
+ hirms(3, '3040::Weitere Daten.:TP-1'),
981
+ `HIVPP:5:1:3+++@1@P+${REPORT_FORMAT}+@${before.length}@${before}'`,
982
+ ),
983
+ answer(OK, hirms(3, CHECK_RESULT), hivppReport(after)),
984
+ endOk(),
985
+ );
986
+
987
+ const response = await client.transfer(ACCOUNT, TRANSFER);
988
+
989
+ expect(response).toMatchObject({ success: false, requiresVopConfirmation: false });
990
+ expect(response.failureReason).toMatch(/another payee name/);
991
+ });
992
+
993
+ it('takes white space after the end of a report as part of it', async () => {
994
+ const report = pain002('RVNM');
995
+ bank.responses.push(
996
+ initOk(),
997
+ answer(
998
+ WARNINGS,
999
+ hirms(3, '3040::Weitere Daten.:TP-1'),
1000
+ `HIVPP:5:1:3+++@1@P+${REPORT_FORMAT}+@${report.length}@${report}'`,
1001
+ ),
1002
+ answer(OK, hirms(3, CHECK_RESULT), hivppReport('\r\n')),
1003
+ );
1004
+
1005
+ expect(await client.transfer(ACCOUNT, TRANSFER)).toMatchObject({
1006
+ requiresVopConfirmation: true,
1007
+ vop: { result: 'noMatch' },
1008
+ });
1009
+ });
1010
+
1011
+ it('does not take an earlier pending transaction for the final match', async () => {
1012
+ vopParams().reportDelivery = 'S';
1013
+ const before = pain002('PDNG');
1014
+ const after = withoutTransactions(pain002('RCVC'), COUNTS('RCVC'));
1015
+ bank.responses.push(
1016
+ initOk(),
1017
+ answer(
1018
+ WARNINGS,
1019
+ hirms(3, '3040::Weitere Daten.:TP-1'),
1020
+ `HIVPP:5:1:3+++@1@P+${REPORT_FORMAT}+@${before.length}@${before}'`,
1021
+ ),
1022
+ answer(OK, hirms(3, CHECK_RESULT), hivppReport(after)),
1023
+ );
1024
+
1025
+ expect((await client.transfer(ACCOUNT, TRANSFER)).vop).toMatchObject({ result: 'match' });
1026
+ });
1027
+ });
1028
+
1029
+ it('reports banking information the dialog initialisation updated', async () => {
1030
+ bank.responses.push(
1031
+ answer(OK, "HIRMS:3:2:3+0020::Auftrag ausgefuehrt.'", "HIKIM:4:2:3+Notice+Changed.'"),
1032
+ answer(OK, hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
1033
+ );
1034
+
1035
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1036
+
1037
+ expect(response).toMatchObject({ success: true, requiresTan: true });
1038
+ expect(response.bankingInformationUpdated).toBe(true);
1039
+ });
1040
+
1041
+ it('reports updated banking information also when only closing the executed transfer failed', async () => {
1042
+ bank.responses.push(
1043
+ answer(OK, "HIRMS:3:2:3+0020::Auftrag ausgefuehrt.'", "HIKIM:4:2:3+Notice+Changed.'"),
1044
+ answer(OK, hirms(4, '0020::Auftrag ausgefuehrt.'), hivppSingle('RCVC')),
1045
+ new Error('lost the answer to HKEND'),
1046
+ );
1047
+
1048
+ expect(await client.transfer(ACCOUNT, TRANSFER)).toMatchObject({
1049
+ success: true,
1050
+ bankingInformationUpdated: true,
1051
+ });
1052
+ });
1053
+
1054
+ it('reads a HIVPP whose binary VoP ID ends in a question mark', async () => {
1055
+ bank.responses.push(
1056
+ initOk(),
1057
+ answer(
1058
+ WARNINGS,
1059
+ hirms(3, CHECK_RESULT),
1060
+ hivppSingle('RVMC', { closeMatchName: 'Herr Meier' }).replace('@6@VOP-01', '@3@AB?'),
1061
+ ),
1062
+ );
1063
+
1064
+ expect((await client.transfer(ACCOUNT, TRANSFER)).vop?.suggestedName).toBe('Herr Meier');
1065
+ });
1066
+
1067
+ describe('results for another payee', () => {
1068
+ const OTHER_IBAN = 'DE89370400440532013000';
1069
+
1070
+ it('stops at a match for another IBAN instead of asking for the TAN', async () => {
1071
+ bank.responses.push(
1072
+ initOk(),
1073
+ answer(
1074
+ OK,
1075
+ hirms(5, TAN_REQUIRED),
1076
+ hivppSingle('RCVC').replace(PAYEE_IBAN, OTHER_IBAN),
1077
+ hitan(),
1078
+ ),
1079
+ endOk(),
1080
+ );
1081
+
1082
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1083
+
1084
+ expect(response).toMatchObject({
1085
+ success: false,
1086
+ requiresTan: false,
1087
+ requiresVopConfirmation: false,
1088
+ outcomeUncertain: false,
1089
+ });
1090
+ expect(response.failureReason).toMatch(/another IBAN/);
1091
+ expect(response.failureReason).not.toContain(OTHER_IBAN);
1092
+ expect(sentOrders().at(-1)).toEqual(['HKEND']);
1093
+ });
1094
+
1095
+ it('accepts the IBAN of the result in another notation', async () => {
1096
+ bank.responses.push(
1097
+ initOk(),
1098
+ answer(
1099
+ OK,
1100
+ hirms(5, TAN_REQUIRED),
1101
+ hivppSingle('RCVC').replace(PAYEE_IBAN, 'de02 1203 0000 0000 2020 51'),
1102
+ hitan(),
1103
+ ),
1104
+ );
1105
+
1106
+ expect(await client.transfer(ACCOUNT, TRANSFER)).toMatchObject({
1107
+ success: true,
1108
+ requiresTan: true,
1109
+ });
1110
+ });
1111
+
1112
+ it('stops at a report about a payee name other than the submitted one', async () => {
1113
+ bank.responses.push(
1114
+ initOk(),
1115
+ answer(
1116
+ WARNINGS,
1117
+ hirms(3, CHECK_RESULT),
1118
+ hivppReport(pain002('RVNM', undefined, 'Erika Musterfrau')),
1119
+ ),
1120
+ endOk(),
1121
+ );
1122
+
1123
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1124
+
1125
+ expect(response).toMatchObject({ success: false, requiresVopConfirmation: false });
1126
+ expect(response.failureReason).toMatch(/another payee name/);
1127
+ expect(response.failureReason).not.toContain('Erika');
1128
+ });
1129
+
1130
+ it('accepts the submitted name in other case and spacing', async () => {
1131
+ bank.responses.push(
1132
+ initOk(),
1133
+ answer(
1134
+ WARNINGS,
1135
+ hirms(3, CHECK_RESULT),
1136
+ hivppReport(pain002('RVNM', undefined, 'MAX MUSTERMANN')),
1137
+ ),
1138
+ );
1139
+
1140
+ expect(await client.transfer(ACCOUNT, TRANSFER)).toMatchObject({
1141
+ success: true,
1142
+ requiresVopConfirmation: true,
1143
+ });
1144
+ });
1145
+
1146
+ it('ends the transfer when 3945 at the TAN step comes with another result', async () => {
1147
+ bank.responses.push(
1148
+ initOk(),
1149
+ answer(OK, hirms(3, NO_HKVPA_NEEDED), hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
1150
+ answer(
1151
+ WARNINGS,
1152
+ hirms(3, APPROVAL_VOIDED),
1153
+ hivppSingle('RVNM').replace('VOP-01', 'VOP-02'),
1154
+ ),
1155
+ endOk(),
1156
+ );
1157
+
1158
+ await client.transfer(ACCOUNT, TRANSFER);
1159
+ const response = await client.transferWithTan('TAN-REF-1', '123456');
1160
+
1161
+ // The caller decided on the match; the bank voided the approval, so nothing executes
1162
+ expect(response).toMatchObject({
1163
+ success: false,
1164
+ requiresVopConfirmation: false,
1165
+ requiresTan: false,
1166
+ outcomeUncertain: false,
1167
+ vop: { result: 'noMatch', code: 'RVNM' },
1168
+ });
1169
+ await expect(client.confirmTransfer(response.transferId)).rejects.toThrow();
1170
+ expect(sentOrders().filter((segments) => segments.includes('HKCCS'))).toHaveLength(1);
1171
+ });
1172
+
1173
+ it('asks for the confirmation again when 3945 at the TAN step comes with the same result', async () => {
1174
+ bank.responses.push(
1175
+ initOk(),
1176
+ answer(OK, hirms(3, NO_HKVPA_NEEDED), hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
1177
+ answer(WARNINGS, hirms(3, APPROVAL_VOIDED), hivppSingle('RCVC')),
1178
+ );
1179
+
1180
+ await client.transfer(ACCOUNT, TRANSFER);
1181
+ const response = await client.transferWithTan('TAN-REF-1', '123456');
1182
+
1183
+ expect(response).toMatchObject({
1184
+ success: true,
1185
+ requiresVopConfirmation: true,
1186
+ vop: { result: 'match' },
1187
+ });
1188
+
1189
+ bank.responses.push(answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')));
1190
+ await client.confirmTransfer(response.transferId);
1191
+
1192
+ const hkvpa = bank.sent.at(-1)?.findSegment<HKVPASegment>('HKVPA');
1193
+ expect(hkvpa?.vopId).toBe('VOP-01');
1194
+ });
1195
+
1196
+ it('stops instead of continuing the approval when a later answer brings a deviation', async () => {
1197
+ client.selectTanMethod(946);
1198
+ bank.responses.push(
1199
+ initOk(),
1200
+ answer(OK, hirms(3, NO_HKVPA_NEEDED), hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
1201
+ answer(
1202
+ WARNINGS,
1203
+ hirms(3, '3956::Freigabe noch ausstehend.'),
1204
+ hivppSingle('RVNM'),
1205
+ hitan('TAN-REF-2', 'S'),
1206
+ ),
1207
+ endOk(),
1208
+ );
1209
+
1210
+ await client.transfer(ACCOUNT, TRANSFER);
1211
+ const response = await client.transferWithTan('TAN-REF-1');
1212
+
1213
+ // The approval the bank still waits for may go through all the same
1214
+ expect(response).toMatchObject({
1215
+ success: false,
1216
+ outcomeUncertain: true,
1217
+ requiresTan: false,
1218
+ requiresVopConfirmation: false,
1219
+ vop: { result: 'noMatch' },
1220
+ });
1221
+ expect(sentOrders().slice(3)).toEqual([['HKEND']]);
1222
+ });
1223
+
1224
+ it('ends the transfer when a later answer replaces the match with no result (notprovided)', async () => {
1225
+ bank.responses.push(
1226
+ initOk(),
1227
+ answer(OK, hirms(3, NO_HKVPA_NEEDED), hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
1228
+ answer(
1229
+ WARNINGS,
1230
+ hirms(3, APPROVAL_VOIDED, CHECK_RESULT),
1231
+ "HIVPP:5:1:3+@11@notprovided++++++Bitte erneut pruefen.'",
1232
+ ),
1233
+ endOk(),
1234
+ );
1235
+
1236
+ await client.transfer(ACCOUNT, TRANSFER);
1237
+ const response = await client.transferWithTan('TAN-REF-1', '123456');
1238
+
1239
+ expect(response).toMatchObject({
1240
+ success: false,
1241
+ requiresVopConfirmation: false,
1242
+ vop: { result: 'notApplicable', notice: 'Bitte erneut pruefen.' },
1243
+ });
1244
+ expect(response.vop?.code).toBeUndefined();
1245
+ });
1246
+
1247
+ it('does not authorise a later result before its own VoP ID arrives', async () => {
1248
+ bank.responses.push(
1249
+ initOk(),
1250
+ answer(OK, hirms(3, NO_HKVPA_NEEDED), hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
1251
+ answer(WARNINGS, hirms(3, APPROVAL_VOIDED), hivppSingle('RVNM').replace('@6@VOP-01', '')),
1252
+ endOk(),
1253
+ );
1254
+
1255
+ await client.transfer(ACCOUNT, TRANSFER);
1256
+ const response = await client.transferWithTan('TAN-REF-1', '123456');
1257
+
1258
+ expect(response).toMatchObject({ success: false, requiresVopConfirmation: false });
1259
+ expect(response.vop).toBeUndefined();
1260
+ expect(response.failureReason).toMatch(/without a VoP ID/);
1261
+ expect(bank.sent.some((message) => message.findSegment('HKVPA'))).toBe(false);
1262
+ });
1263
+
1264
+ it('stops when the result at the TAN step is for another IBAN', async () => {
1265
+ bank.responses.push(
1266
+ initOk(),
1267
+ answer(OK, hirms(3, NO_HKVPA_NEEDED), hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
1268
+ answer(
1269
+ WARNINGS,
1270
+ hirms(3, APPROVAL_VOIDED),
1271
+ hivppSingle('RVNM').replace(PAYEE_IBAN, OTHER_IBAN),
1272
+ ),
1273
+ endOk(),
1274
+ );
1275
+
1276
+ await client.transfer(ACCOUNT, TRANSFER);
1277
+ const response = await client.transferWithTan('TAN-REF-1', '123456');
1278
+
1279
+ expect(response).toMatchObject({ success: false, requiresVopConfirmation: false });
1280
+ expect(response.failureReason).toMatch(/another IBAN/);
1281
+ });
1282
+ });
1283
+
1284
+ describe('outcome codes', () => {
1285
+ const OTHER = 'DE89370400440532013000';
1286
+ const RECEIVED = '0010::Auftrag entgegengenommen.';
1287
+ const EXECUTED = '0020::Auftrag ausgefuehrt.';
1288
+ const PROCESSING = '3070::Auftrag wird unter Referenz R-1 verarbeitet.:R-1';
1289
+ const MORE = '3040::Weitere Informationen.:TP-0001';
1290
+ const POLL_REJECTED = '9210::Polling-ID ungueltig.';
1291
+ const TAN_WRONG = '9941::TAN ungueltig.';
1292
+ const NO_SCA = '3076::Keine starke Kundenauthentifizierung notwendig.';
1293
+ const matchWithTan = () =>
1294
+ answer(OK, hirms(3, NO_HKVPA_NEEDED), hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan());
1295
+
1296
+ type Row = {
1297
+ /** The bank's answers after the dialog initialisation */
1298
+ answers: Message[];
1299
+ /** What the caller does after the first response */
1300
+ next?: 'tan' | 'confirm';
1301
+ withoutCheck?: true;
1302
+ decoupled?: true;
1303
+ /** The bank ends the dialog itself, which the library takes 9000 to mean */
1304
+ endedByBank?: true;
1305
+ expected: {
1306
+ success: boolean;
1307
+ outcomeUncertain: boolean;
1308
+ requiresVopConfirmation?: boolean;
1309
+ };
1310
+ /** How often HKCCS goes out, once unless given */
1311
+ payments?: number;
1312
+ reason?: RegExp;
1313
+ };
1314
+
1315
+ // Each row is one combination of codes; every terminal outcome leaves nothing to
1316
+ // confirm, and an uncertain one says to check the account
1317
+ const rows: Record<string, Row> = {
1318
+ '0010 to the order while the check is pending is no execution (P3)': {
1319
+ answers: [
1320
+ answer(
1321
+ WARNINGS,
1322
+ hirms(3, MORE, '3093::Namensabgleich in Bearbeitung.'),
1323
+ hirms(4, RECEIVED),
1324
+ hirms(5, '3905::Es wurde keine Challenge erzeugt.'),
1325
+ hivppPending(),
1326
+ ),
1327
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')),
1328
+ ],
1329
+ expected: { success: true, outcomeUncertain: false, requiresVopConfirmation: true },
1330
+ },
1331
+ '0010 to the order next to a deviation is no execution (P3)': {
1332
+ answers: [
1333
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hirms(4, RECEIVED), hivppSingle('RVNM')),
1334
+ ],
1335
+ expected: { success: true, outcomeUncertain: false, requiresVopConfirmation: true },
1336
+ },
1337
+ '9000 to the order (M5)': {
1338
+ answers: [answer(OK, hirms(4, '9000::Status indifferent.'))],
1339
+ endedByBank: true,
1340
+ expected: { success: false, outcomeUncertain: true },
1341
+ },
1342
+ '0020 to the order next to a failed check (M4)': {
1343
+ answers: [
1344
+ answer(
1345
+ "HIRMG:2:2+9050::Die Nachricht enthaelt Fehler.'",
1346
+ hirms(3, '9210::Namensabgleich abgelehnt.'),
1347
+ hirms(4, EXECUTED),
1348
+ ),
1349
+ ],
1350
+ expected: { success: false, outcomeUncertain: true },
1351
+ },
1352
+ '0020 to the order next to a deviation (M4)': {
1353
+ answers: [answer(OK, hirms(4, EXECUTED), hivppSingle('RVNM'))],
1354
+ expected: { success: true, outcomeUncertain: false },
1355
+ },
1356
+ '3091 with 3076: executed without a challenge (E.8.1 rule 2)': {
1357
+ answers: [
1358
+ answer(WARNINGS, hirms(3, NO_HKVPA_NEEDED), hirms(5, NO_SCA), hivppSingle('RCVC')),
1359
+ ],
1360
+ expected: { success: true, outcomeUncertain: false },
1361
+ },
1362
+ '3070 to the order next to a match offers no confirmation (M5)': {
1363
+ answers: [answer(WARNINGS, hirms(4, PROCESSING), hivppSingle('RCVC'))],
1364
+ expected: { success: false, outcomeUncertain: true },
1365
+ reason: /R-1/,
1366
+ },
1367
+ '3070 to the order, then a deviation by polling (M5)': {
1368
+ answers: [
1369
+ answer(WARNINGS, hirms(3, MORE), hirms(4, PROCESSING), hivppPending()),
1370
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')),
1371
+ ],
1372
+ expected: { success: false, outcomeUncertain: true },
1373
+ },
1374
+ '3958 to a decoupled approval': {
1375
+ decoupled: true,
1376
+ answers: [
1377
+ answer(OK, hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
1378
+ answer(WARNINGS, hirms(4, '3958::Freigabe-Anwendung unterstuetzt das Verfahren nicht.')),
1379
+ ],
1380
+ next: 'tan',
1381
+ expected: { success: false, outcomeUncertain: false },
1382
+ reason: /3958/,
1383
+ },
1384
+ 'a TAN answered with 3040 alone': {
1385
+ answers: [matchWithTan(), answer(WARNINGS, hirms(3, '3040::Weitere Informationen.:MORE'))],
1386
+ next: 'tan',
1387
+ expected: { success: false, outcomeUncertain: true },
1388
+ },
1389
+ '3040 alone to an order without check': {
1390
+ withoutCheck: true,
1391
+ answers: [answer(WARNINGS, hirms(3, '3040::Auftrag nur teilweise ausgefuehrt.:MORE'))],
1392
+ expected: { success: false, outcomeUncertain: true },
1393
+ },
1394
+ '0020 to an order without check': {
1395
+ withoutCheck: true,
1396
+ answers: [answer(OK, hirms(3, EXECUTED))],
1397
+ expected: { success: true, outcomeUncertain: false },
1398
+ },
1399
+ 'R7a: 0010 alone to an order without check is no execution': {
1400
+ withoutCheck: true,
1401
+ answers: [answer(OK, hirms(3, '0010::Auftrag zur Ausfuehrung vorgemerkt.'))],
1402
+ expected: { success: false, outcomeUncertain: true },
1403
+ reason: /0010/,
1404
+ },
1405
+ 'R7b: a TAN answered with 0010 to HKVPA and 3905 to HKTAN': {
1406
+ answers: [
1407
+ answer(OK, hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
1408
+ answer(WARNINGS, hirms(3, RECEIVED), hirms(4, '3905::Keine Challenge erzeugt.')),
1409
+ ],
1410
+ next: 'tan',
1411
+ expected: { success: false, outcomeUncertain: true },
1412
+ },
1413
+ 'R7c: 0020 to an order without check next to an unexpected result': {
1414
+ withoutCheck: true,
1415
+ answers: [answer(OK, hirms(3, EXECUTED), hivppSingle('RCVC'))],
1416
+ expected: { success: true, outcomeUncertain: false },
1417
+ },
1418
+ 'R7d: 9000 next to a TAN request without HITAN': {
1419
+ answers: [answer(WARNINGS, hirms(4, '9000::Status indifferent.'), hirms(5, TAN_REQUIRED))],
1420
+ endedByBank: true,
1421
+ expected: { success: false, outcomeUncertain: true },
1422
+ },
1423
+ 'R2: 0020 to the order while 3945 voids the approval': {
1424
+ answers: [
1425
+ answer(WARNINGS, hirms(4, EXECUTED), hirms(5, APPROVAL_VOIDED), hivppSingle('RVNM')),
1426
+ ],
1427
+ expected: { success: false, outcomeUncertain: true },
1428
+ },
1429
+ 'R4: a receipt next to 3945 and a result for another IBAN at the TAN': {
1430
+ answers: [
1431
+ matchWithTan(),
1432
+ answer(
1433
+ WARNINGS,
1434
+ hirms(3, RECEIVED, APPROVAL_VOIDED),
1435
+ hivppSingle('RVNM').replace(PAYEE_IBAN, OTHER),
1436
+ ),
1437
+ ],
1438
+ next: 'tan',
1439
+ expected: { success: false, outcomeUncertain: true },
1440
+ reason: /another IBAN/,
1441
+ },
1442
+ 'R6: 0010 to the order, then a failed poll': {
1443
+ answers: [
1444
+ answer(WARNINGS, hirms(3, MORE), hirms(4, RECEIVED), hivppPending()),
1445
+ answer(WARNINGS, hirms(3, POLL_REJECTED)),
1446
+ ],
1447
+ expected: { success: false, outcomeUncertain: true },
1448
+ },
1449
+ 'R6: 3070 to the order, then a failed poll': {
1450
+ answers: [
1451
+ answer(WARNINGS, hirms(3, MORE), hirms(4, PROCESSING), hivppPending()),
1452
+ answer(WARNINGS, hirms(3, POLL_REJECTED)),
1453
+ ],
1454
+ expected: { success: false, outcomeUncertain: true },
1455
+ },
1456
+ 'R6: 0010 to the order, then polling that takes too long': {
1457
+ answers: [answer(WARNINGS, hirms(3, MORE), hirms(4, RECEIVED), hivppPending('P', 61))],
1458
+ expected: { success: false, outcomeUncertain: true },
1459
+ reason: /within 60 seconds/,
1460
+ },
1461
+ 'a failed poll without any receipt': {
1462
+ answers: [
1463
+ answer(WARNINGS, hirms(3, MORE), hivppPending()),
1464
+ answer(WARNINGS, hirms(3, POLL_REJECTED)),
1465
+ ],
1466
+ expected: { success: false, outcomeUncertain: false },
1467
+ },
1468
+ 'an error to the order itself': {
1469
+ answers: [answer("HIRMG:2:2+9050::Teilweise fehlerhaft.'", hirms(4, '9210::Abgelehnt.'))],
1470
+ expected: { success: false, outcomeUncertain: false },
1471
+ reason: /not executed/,
1472
+ },
1473
+ '0010 to the order, then the confirmed order rejected': {
1474
+ answers: [
1475
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hirms(4, RECEIVED), hivppSingle('RVNM')),
1476
+ answer("HIRMG:2:2+9050::Teilweise fehlerhaft.'", hirms(4, '9210::Abgelehnt.')),
1477
+ ],
1478
+ next: 'confirm',
1479
+ payments: 2,
1480
+ expected: { success: false, outcomeUncertain: false },
1481
+ },
1482
+ 'an order held after a match (3076), then HKVPA rejected': {
1483
+ answers: [
1484
+ answer(WARNINGS, hirms(5, NO_SCA), hivppSingle('RCVC')),
1485
+ answer("HIRMG:2:2+9050::Teilweise fehlerhaft.'", hirms(3, '9210::Abgelehnt.')),
1486
+ ],
1487
+ next: 'confirm',
1488
+ expected: { success: false, outcomeUncertain: true },
1489
+ },
1490
+ '0010 to the order, then a wrong TAN': {
1491
+ answers: [
1492
+ answer(
1493
+ OK,
1494
+ hirms(3, NO_HKVPA_NEEDED),
1495
+ hirms(4, RECEIVED),
1496
+ hirms(5, TAN_REQUIRED),
1497
+ hivppSingle('RCVC'),
1498
+ hitan(),
1499
+ ),
1500
+ answer("HIRMG:2:2+9050::Teilweise fehlerhaft.'", hirms(3, TAN_WRONG)),
1501
+ ],
1502
+ next: 'tan',
1503
+ expected: { success: false, outcomeUncertain: true },
1504
+ },
1505
+ 'a wrong TAN without any receipt': {
1506
+ answers: [
1507
+ matchWithTan(),
1508
+ answer("HIRMG:2:2+9050::Teilweise fehlerhaft.'", hirms(3, TAN_WRONG)),
1509
+ ],
1510
+ next: 'tan',
1511
+ expected: { success: false, outcomeUncertain: false },
1512
+ },
1513
+ };
1514
+
1515
+ it.each(Object.entries(rows))('%s', async (_name, row) => {
1516
+ if (row.withoutCheck) {
1517
+ removeTransaction('HKVPP');
1518
+ }
1519
+
1520
+ if (row.decoupled) {
1521
+ client.selectTanMethod(946);
1522
+ }
1523
+
1524
+ bank.responses.push(initOk(), ...row.answers, endOk());
1525
+ let response = await client.transfer(ACCOUNT, TRANSFER);
1526
+
1527
+ if (row.next === 'tan') {
1528
+ expect(response.requiresTan).toBe(true);
1529
+ response = await client.transferWithTan(
1530
+ response.tanReference ?? '',
1531
+ row.decoupled ? undefined : '123456',
1532
+ );
1533
+ } else if (row.next === 'confirm') {
1534
+ expect(response.requiresVopConfirmation).toBe(true);
1535
+ response = await client.confirmTransfer(response.transferId);
1536
+ }
1537
+
1538
+ expect(response).toMatchObject({
1539
+ requiresVopConfirmation: false,
1540
+ requiresTan: false,
1541
+ ...row.expected,
1542
+ });
1543
+ expect(sentOrders().filter((segments) => segments.includes('HKCCS'))).toHaveLength(
1544
+ row.payments ?? 1,
1545
+ );
1546
+
1547
+ if (row.reason) {
1548
+ expect(response.failureReason).toMatch(row.reason);
1549
+ }
1550
+
1551
+ if (row.expected.outcomeUncertain) {
1552
+ expect(response.failureReason).toMatch(/Check the account/);
1553
+ expect(response.failureReason).not.toMatch(/rejected|not executed/);
1554
+ }
1555
+
1556
+ if (!row.expected.requiresVopConfirmation) {
1557
+ const sent = bank.sent.length;
1558
+ await expect(client.confirmTransfer(response.transferId)).rejects.toThrow();
1559
+ expect(bank.sent).toHaveLength(sent);
1560
+
1561
+ if (!row.endedByBank) {
1562
+ expect(sentOrders().at(-1)).toEqual(['HKEND']);
1563
+ }
1564
+ }
1565
+ });
1566
+ });
1567
+
1568
+ describe('fails closed', () => {
1569
+ const expectStopped = (response: Awaited<ReturnType<FinTSClient['transfer']>>) => {
1570
+ expect(response.success).toBe(false);
1571
+ expect(response.requiresTan).toBe(false);
1572
+ expect(response.requiresVopConfirmation).toBe(false);
1573
+ expect(response.tanReference).toBeUndefined();
1574
+ expect(response.failureReason).toBeTruthy();
1575
+ expect(sentOrders().at(-1)).toEqual(['HKEND']);
1576
+ expect(sentOrders().filter((segments) => segments.includes('HKCCS'))).toHaveLength(1);
1577
+ };
1578
+
1579
+ it('on an unknown result code', async () => {
1580
+ bank.responses.push(
1581
+ initOk(),
1582
+ answer(OK, hirms(5, TAN_REQUIRED), hivppSingle('RXXX'), hitan()),
1583
+ endOk(),
1584
+ );
1585
+
1586
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1587
+
1588
+ expectStopped(response);
1589
+ expect(response.failureReason).toMatch(/unknown Verification of Payee result 'RXXX'/);
1590
+ });
1591
+
1592
+ it('on a pending result that comes with a VoP ID', async () => {
1593
+ bank.responses.push(initOk(), answer(OK, hivppReport(pain002('PDNG'))), endOk());
1594
+ expectStopped(await client.transfer(ACCOUNT, TRANSFER));
1595
+ });
1596
+
1597
+ it('on an unreadable pain.002', async () => {
1598
+ bank.responses.push(initOk(), answer(OK, hivppReport('<Document><Unclosed>')), endOk());
1599
+ expectStopped(await client.transfer(ACCOUNT, TRANSFER));
1600
+ });
1601
+
1602
+ it('on a result without VoP ID and without polling ID', async () => {
1603
+ bank.responses.push(initOk(), answer(OK, `HIVPP:5:1:3+++++${PAYEE_IBAN}::::RVMC'`), endOk());
1604
+
1605
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1606
+
1607
+ expectStopped(response);
1608
+ expect(response.failureReason).toMatch(/without a VoP ID/);
1609
+ });
1610
+
1611
+ it('on a TAN request without any VoP result', async () => {
1612
+ bank.responses.push(initOk(), answer(OK, hirms(5, TAN_REQUIRED), hitan()), endOk());
1613
+
1614
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1615
+
1616
+ expectStopped(response);
1617
+ expect(response.failureReason).toMatch(/without a Verification of Payee result/);
1618
+ });
1619
+
1620
+ it('on a TAN request before the asynchronous result is complete', async () => {
1621
+ bank.responses.push(
1622
+ initOk(),
1623
+ answer(OK, hirms(5, TAN_REQUIRED), hivppPending(), hitan()),
1624
+ endOk(),
1625
+ );
1626
+ expectStopped(await client.transfer(ACCOUNT, TRANSFER));
1627
+ });
1628
+
1629
+ it('on an error code, even next to a TAN request', async () => {
1630
+ bank.responses.push(
1631
+ initOk(),
1632
+ answer(
1633
+ "HIRMG:2:2+9050::Die Nachricht enthaelt Fehler.'",
1634
+ hirms(3, '9210::Auftrag abgelehnt.'),
1635
+ hirms(5, TAN_REQUIRED),
1636
+ hivppSingle('RCVC'),
1637
+ hitan(),
1638
+ ),
1639
+ endOk(),
1640
+ );
1641
+
1642
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1643
+
1644
+ expectStopped(response);
1645
+ expect(response.bankAnswers.map((a) => a.code)).toContain(9210);
1646
+ expect(response.outcomeUncertain).toBe(false);
1647
+ });
1648
+
1649
+ it('on a code asking for a TAN without HITAN, instead of throwing', async () => {
1650
+ bank.responses.push(
1651
+ initOk(),
1652
+ answer(OK, hirms(5, TAN_REQUIRED), hivppSingle('RCVC')),
1653
+ endOk(),
1654
+ );
1655
+
1656
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1657
+
1658
+ expectStopped(response);
1659
+ expect(response.failureReason).toMatch(/Unexpected answer/);
1660
+ });
1661
+
1662
+ it('on 3945 after the caller has already confirmed', async () => {
1663
+ bank.responses.push(
1664
+ initOk(),
1665
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')),
1666
+ answer(WARNINGS, hirms(5, APPROVAL_VOIDED)),
1667
+ endOk(),
1668
+ );
1669
+
1670
+ const { transferId } = await client.transfer(ACCOUNT, TRANSFER);
1671
+ const response = await client.confirmTransfer(transferId);
1672
+
1673
+ expect(response.success).toBe(false);
1674
+ expect(response.requiresVopConfirmation).toBe(false);
1675
+ expect(sentOrders().at(-1)).toEqual(['HKEND']);
1676
+ });
1677
+
1678
+ it('on a poll answered with a TAN request', async () => {
1679
+ bank.responses.push(
1680
+ initOk(),
1681
+ answer(WARNINGS, hirms(3, '3040::Bitte erneut anfragen.:TP-0001'), hivppPending()),
1682
+ answer(OK, hirms(3, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
1683
+ endOk(),
1684
+ );
1685
+
1686
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1687
+
1688
+ expect(response.success).toBe(false);
1689
+ expect(sentOrders().at(-1)).toEqual(['HKEND']);
1690
+ });
1691
+ });
1692
+
1693
+ describe('parameters at the time of the order', () => {
1694
+ /** Changes the banking information the way a dialog initialisation answer would */
1695
+ const atInitialisation = (change: () => void) => {
1696
+ const original = InitDialogInteraction.prototype.handleResponse;
1697
+ vi.spyOn(InitDialogInteraction.prototype, 'handleResponse').mockImplementation(function (
1698
+ this: InitDialogInteraction,
1699
+ ...args
1700
+ ) {
1701
+ original.apply(this, args);
1702
+ change();
1703
+ });
1704
+ };
1705
+ const hkspaParams = () =>
1706
+ config.bankingInformation.bpd?.allowedTransactions.find((t) => t.transId === 'HKSPA')
1707
+ ?.params as { supportedSepaFormats: string[] };
1708
+
1709
+ it('refuses an account the UPD does not allow transfers from, as canTransfer() does', async () => {
1710
+ expect(client.canTransfer('9876543210')).toBe(false);
1711
+
1712
+ await expect(client.transfer('9876543210', TRANSFER)).rejects.toThrow(
1713
+ /does not allow SEPA credit transfers/,
1714
+ );
1715
+ expect(bank.sent).toHaveLength(0);
1716
+ });
1717
+
1718
+ it('sends the payment from the account as they were when the transfer was called', async () => {
1719
+ removeTransaction('HKVPP');
1720
+ config.bankingInformation.upd?.bankAccounts[1].allowedTransactions?.push({
1721
+ transId: 'HKCCS',
1722
+ numSignatures: 1,
1723
+ });
1724
+ const account = structuredClone(config.bankingInformation.upd?.bankAccounts[0]);
1725
+ const form = { ...TRANSFER };
1726
+ bank.responses.push(initOk(), answer(OK, hirms(3, '0020::Auftrag ausgefuehrt.')), endOk());
1727
+
1728
+ if (!account) throw new Error('no account');
1729
+ const started = client.transfer(account, form);
1730
+ // Changed while the login is still under way
1731
+ form.amount = 100;
1732
+ form.iban = 'DE02100100100006820101';
1733
+ form.name = 'Someone Else';
1734
+ account.accountNumber = '9876543210';
1735
+
1736
+ expect((await started).success).toBe(true);
1737
+ const xml = bank.sent[1].findSegment<HKCCSSegment>('HKCCS')?.sepaPainMessage ?? '';
1738
+ expect({
1739
+ amount: xml.match(/<InstdAmt[^>]*>([^<]+)/)?.[1],
1740
+ payee: xml.match(/<CdtrAcct><Id><IBAN>([^<]+)/)?.[1],
1741
+ name: xml.match(/<Cdtr><Nm>([^<]+)/)?.[1],
1742
+ debtor: xml.match(/<DbtrAcct><Id><IBAN>([^<]+)/)?.[1],
1743
+ }).toEqual({
1744
+ amount: '42.50',
1745
+ payee: TRANSFER.iban,
1746
+ name: TRANSFER.name,
1747
+ debtor: 'DE89370400440532013000',
1748
+ });
1749
+ });
1750
+
1751
+ it('sends no order when the TAN method the HKTAN needs is gone after the login', async () => {
1752
+ atInitialisation(() => {
1753
+ config.tanMethodId = undefined;
1754
+ });
1755
+ bank.responses.push(initOk(), endOk());
1756
+
1757
+ await expect(client.transfer(ACCOUNT, TRANSFER)).rejects.toThrow(/no TAN method/);
1758
+ expect(sentOrders()).toEqual([['HKIDN', 'HKVVB', 'HKTAN'], ['HKEND']]);
1759
+ });
1760
+
1761
+ it('confirms no order without a TAN method that can send its HKTAN', async () => {
1762
+ bank.responses.push(initOk(), answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')));
1763
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1764
+ config.tanMethodId = undefined;
1765
+ bank.responses.push(endOk());
1766
+
1767
+ await expect(client.confirmTransfer(response.transferId)).rejects.toThrow(/TAN method/);
1768
+ expect(sentOrders().filter((segments) => segments.includes('HKCCS'))).toHaveLength(1);
1769
+ });
1770
+
1771
+ it('checks the payee when the dialog initialisation brings parameters that require it', async () => {
1772
+ const withVop = config.bankingInformation.bpd?.allowedTransactions ?? [];
1773
+ removeTransaction('HKVPP');
1774
+ atInitialisation(() => {
1775
+ const bpd = config.bankingInformation.bpd;
1776
+ if (bpd) bpd.allowedTransactions = withVop;
1777
+ });
1778
+ bank.responses.push(
1779
+ initOk(),
1780
+ answer(
1781
+ WARNINGS,
1782
+ hirms(3, CHECK_RESULT),
1783
+ hirms(5, TAN_REQUIRED),
1784
+ hivppSingle('RVNM'),
1785
+ hitan(),
1786
+ ),
1787
+ );
1788
+
1789
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1790
+
1791
+ expect(response).toMatchObject({ requiresVopConfirmation: true, vop: { result: 'noMatch' } });
1792
+ expect(sentOrders()[1]).toEqual(['HKVPP', 'HKCCS', 'HKTAN']);
1793
+ });
1794
+
1795
+ it('writes the pain.001 format the dialog initialisation announces, and confirms the same bytes', async () => {
1796
+ atInitialisation(() => {
1797
+ hkspaParams().supportedSepaFormats = [PAIN_001_001_03];
1798
+ });
1799
+ bank.responses.push(initOk(), answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')));
1800
+
1801
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1802
+ bank.responses.push(answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')));
1803
+ await client.confirmTransfer(response.transferId);
1804
+
1805
+ const submitted = bank.sent[1].findSegment<HKCCSSegment>('HKCCS');
1806
+ const confirmed = bank.sent[2].findSegment<HKCCSSegment>('HKCCS');
1807
+ expect(submitted?.sepaDescriptor).toBe(PAIN_001_001_03);
1808
+ expect(submitted?.sepaPainMessage).toContain('pain.001.001.03');
1809
+ expect(confirmed?.sepaDescriptor).toBe(PAIN_001_001_03);
1810
+ expect(confirmed?.sepaPainMessage).toBe(submitted?.sepaPainMessage);
1811
+ });
1812
+
1813
+ it('sends no order from an account the dialog initialisation withdrew transfers from', async () => {
1814
+ atInitialisation(() => {
1815
+ const account = config.bankingInformation.upd?.bankAccounts[0];
1816
+ if (account) account.allowedTransactions = [{ transId: 'HKSAL', numSignatures: 1 }];
1817
+ });
1818
+ bank.responses.push(initOk(), endOk());
1819
+
1820
+ await expect(client.transfer(ACCOUNT, TRANSFER)).rejects.toThrow(
1821
+ /does not allow SEPA credit transfers/,
1822
+ );
1823
+ expect(sentOrders()).toEqual([['HKIDN', 'HKVVB', 'HKTAN'], ['HKEND']]);
1824
+ expect(bank.sent[1].findSegment<HNHBKSegment>('HNHBK')?.msgNr).toBe(2);
1825
+ });
1826
+
1827
+ it('stops for the caller when the bank reports a check its stored parameters do not ask for', async () => {
1828
+ removeTransaction('HKVPP');
1829
+ bank.responses.push(
1830
+ initOk(),
1831
+ answer(
1832
+ WARNINGS,
1833
+ hirms(3, CHECK_RESULT),
1834
+ hirms(4, TAN_REQUIRED),
1835
+ hivppSingle('RVNM'),
1836
+ hitan(),
1837
+ ),
1838
+ endOk(),
1839
+ );
1840
+
1841
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1842
+
1843
+ expect(response).toMatchObject({
1844
+ success: false,
1845
+ requiresTan: false,
1846
+ requiresVopConfirmation: false,
1847
+ });
1848
+ expect(response.failureReason).toMatch(/Verification of Payee/);
1849
+ expect(sentOrders().slice(1)).toEqual([['HKCCS', 'HKTAN'], ['HKEND']]);
1850
+ });
1851
+
1852
+ it('sends HKTAN with the check and with the authorisation where the bank requires no TAN for HKCCS (E.8.1)', async () => {
1853
+ const hkccs = config.bankingInformation.bpd?.allowedTransactions.find(
1854
+ (t) => t.transId === 'HKCCS',
1855
+ );
1856
+ if (hkccs) hkccs.tanRequired = false;
1857
+ bank.responses.push(initOk(), answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')));
1858
+
1859
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1860
+ bank.responses.push(answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')));
1861
+ await client.confirmTransfer(response.transferId);
1862
+
1863
+ expect(sentOrders().slice(1)).toEqual([
1864
+ ['HKVPP', 'HKCCS', 'HKTAN'],
1865
+ ['HKVPA', 'HKCCS', 'HKTAN'],
1866
+ ]);
1867
+ });
1868
+ });
1869
+
1870
+ describe('without Verification of Payee', () => {
1871
+ it('sends HKCCS alone when the bank does not require the check for HKCCS', async () => {
1872
+ vopParams().vopRequiredTransactions = ['HKCSE'];
1873
+ bank.responses.push(
1874
+ initOk(),
1875
+ answer(OK, "HIRMS:3:2:4+0030::Sicherheitsfreigabe erforderlich.'", hitan()),
1876
+ tanAccepted(),
1877
+ endOk(),
1878
+ );
1879
+
1880
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1881
+ expect(response).toMatchObject({
1882
+ success: true,
1883
+ requiresTan: true,
1884
+ requiresVopConfirmation: false,
1885
+ });
1886
+ expect(response.vop).toBeUndefined();
1887
+
1888
+ const done = await client.transferWithTan('TAN-REF-1', '123456');
1889
+
1890
+ expect(done).toMatchObject({ success: true, requiresTan: false });
1891
+ expect(sentOrders().slice(1)).toEqual([['HKCCS', 'HKTAN'], ['HKTAN'], ['HKEND']]);
1892
+ });
1893
+
1894
+ it('writes pain.001.001.03 for a bank that lists only that', async () => {
1895
+ removeTransaction('HKVPP');
1896
+ const hkspa = config.bankingInformation.bpd?.allowedTransactions.find(
1897
+ (t) => t.transId === 'HKSPA',
1898
+ );
1899
+ (hkspa?.params as { supportedSepaFormats: string[] }).supportedSepaFormats = [
1900
+ PAIN_001_001_03,
1901
+ ];
1902
+ bank.responses.push(initOk(), answer(OK, "HIRMS:3:2:3+0020::Auftrag ausgefuehrt.'"), endOk());
1903
+
1904
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1905
+
1906
+ expect(response).toMatchObject({ success: true, requiresTan: false });
1907
+ expect(bank.sent[1].findSegment<HKCCSSegment>('HKCCS')?.sepaDescriptor).toBe(PAIN_001_001_03);
1908
+ });
1909
+
1910
+ it('stops when the bank asks for a check its parameters do not announce', async () => {
1911
+ removeTransaction('HKVPP');
1912
+ bank.responses.push(initOk(), answer(WARNINGS, hirms(3, APPROVAL_VOIDED)), endOk());
1913
+
1914
+ const response = await client.transfer(ACCOUNT, TRANSFER);
1915
+
1916
+ expect(response.success).toBe(false);
1917
+ expect(response.failureReason).toMatch(/3945/);
1918
+ });
1919
+ });
1920
+
1921
+ describe('the README example', () => {
1922
+ /** The transfer example of the README, run as it stands, without its type assertions */
1923
+ const example = (() => {
1924
+ const readme = readFileSync(new URL('../../README.md', import.meta.url), 'utf8');
1925
+ const section = readme.slice(readme.indexOf('### SEPA credit transfers'));
1926
+ const code = /```typescript\n([\s\S]*?)```/.exec(section)?.[1] ?? '';
1927
+ return code.replace(/(\w)!(?=[.,);])/g, '$1');
1928
+ })();
1929
+ const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
1930
+
1931
+ const runExample = async (answers: string[]) => {
1932
+ const printed: string[] = [];
1933
+ const questions: string[] = [];
1934
+ const rl = {
1935
+ question: async (question: string) => {
1936
+ questions.push(question);
1937
+ return answers.shift() ?? '';
1938
+ },
1939
+ };
1940
+ const log = { log: (...values: unknown[]) => printed.push(values.map(String).join(' ')) };
1941
+ await new AsyncFunction('client', 'account', 'rl', 'console', example)(
1942
+ client,
1943
+ ACCOUNT,
1944
+ rl,
1945
+ log,
1946
+ );
1947
+ return { printed, questions };
1948
+ };
1949
+
1950
+ it('asks for the decision the bank wants after the TAN (3945) before reporting acceptance', async () => {
1951
+ bank.responses.push(
1952
+ initOk(),
1953
+ answer(OK, hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
1954
+ answer(WARNINGS, hirms(3, APPROVAL_VOIDED)),
1955
+ answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')),
1956
+ tanAccepted(),
1957
+ endOk(),
1958
+ );
1959
+
1960
+ const { printed, questions } = await runExample(['123456', 'yes', '654321']);
1961
+
1962
+ expect(questions).toHaveLength(3);
1963
+ expect(questions[1]).toMatch(/anyway/);
1964
+ expect(printed).toContain('Bei Abweichungen haftet die Bank nicht.');
1965
+ expect(printed.at(-1)).toBe('The bank accepted the transfer INVOICE-2026-001');
1966
+ });
1967
+
1968
+ it('shows the notice of the report and asks after a TAN for the login, then cancels', async () => {
1969
+ // The example's own end-to-end reference
1970
+ const report = pain002('RVNM')
1971
+ .replace('E2E-0001', 'INVOICE-2026-001')
1972
+ .replace(
1973
+ '</OrgnlGrpInfAndSts>',
1974
+ '<GrpSts>RVCM</GrpSts><StsRsnInf><AddtlInf>RVNM Bei Abweichungen haftet die Bank nicht.</AddtlInf></StsRsnInf></OrgnlGrpInfAndSts>',
1975
+ );
1976
+ bank.responses.push(
1977
+ answer(OK, "HIRMS:3:2:5+0030::Sicherheitsfreigabe erforderlich.'", hitan('INIT-REF')),
1978
+ initOk(),
1979
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hivppReport(report)),
1980
+ endOk(),
1981
+ );
1982
+
1983
+ const { printed, questions } = await runExample(['111111', 'no']);
1984
+
1985
+ expect(questions).toHaveLength(2);
1986
+ expect(questions[1]).toMatch(/anyway/);
1987
+ expect(printed).toContain('Verification of Payee: noMatch');
1988
+ expect(printed).toContain('Bei Abweichungen haftet die Bank nicht.');
1989
+ expect(printed.join('\n')).not.toMatch(/accepted/);
1990
+ expect(sentOrders().at(-1)).toEqual(['HKEND']);
1991
+ });
1992
+ });
1993
+
1994
+ describe('dialog handling', () => {
1995
+ it('continues with the transfer after a TAN for the dialog initialisation', async () => {
1996
+ bank.responses.push(
1997
+ answer(OK, "HIRMS:3:2:5+0030::Sicherheitsfreigabe erforderlich.'", hitan('INIT-REF')),
1998
+ );
1999
+
2000
+ const response = await client.transfer(ACCOUNT, TRANSFER);
2001
+
2002
+ expect(response).toMatchObject({
2003
+ success: true,
2004
+ requiresTan: true,
2005
+ requiresVopConfirmation: false,
2006
+ tanReference: 'INIT-REF',
2007
+ endToEndId: 'E2E-0001',
2008
+ });
2009
+
2010
+ bank.responses.push(
2011
+ initOk(),
2012
+ answer(
2013
+ WARNINGS,
2014
+ hirms(3, NO_HKVPA_NEEDED),
2015
+ hirms(5, TAN_REQUIRED),
2016
+ hivppSingle('RCVC'),
2017
+ hitan(),
2018
+ ),
2019
+ );
2020
+ const submitted = await client.transferWithTan('INIT-REF', '111111');
2021
+
2022
+ expect(submitted).toMatchObject({ requiresTan: true, tanReference: 'TAN-REF-1' });
2023
+ expect(bank.sent[1].findSegment<HKTANSegment>('HKTAN')).toMatchObject({
2024
+ segId: 'HKIDN',
2025
+ orderRef: 'INIT-REF',
2026
+ });
2027
+ expect(sentOrders()[2]).toEqual(['HKVPP', 'HKCCS', 'HKTAN']);
2028
+ });
2029
+
2030
+ it('reports a failed initialisation as a transfer that was not executed', async () => {
2031
+ bank.responses.push(answer("HIRMG:2:2+9800::Dialog abgebrochen.'"), endOk());
2032
+
2033
+ const response = await client.transfer(ACCOUNT, TRANSFER);
2034
+
2035
+ expect(response.success).toBe(false);
2036
+ expect(response.failureReason).toMatch(/not executed/);
2037
+ expect(sentOrders().some((segments) => segments.includes('HKCCS'))).toBe(false);
2038
+ });
2039
+
2040
+ it('allows one transfer at a time', async () => {
2041
+ bank.responses.push(initOk(), answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')));
2042
+ await client.transfer(ACCOUNT, TRANSFER);
2043
+
2044
+ await expect(client.transfer(ACCOUNT, TRANSFER)).rejects.toThrow(/already in progress/);
2045
+ });
2046
+
2047
+ it('refuses continuations that do not fit the state of the transfer', async () => {
2048
+ await expect(client.confirmTransfer('T')).rejects.toThrow(/no transfer is waiting/);
2049
+ await expect(client.transferWithTan('REF', '123456')).rejects.toThrow(
2050
+ /no transfer is waiting/,
2051
+ );
2052
+
2053
+ bank.responses.push(initOk(), answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVMC')));
2054
+ await client.transfer(ACCOUNT, TRANSFER);
2055
+ await expect(client.transferWithTan('TAN-REF-1', '123456')).rejects.toThrow(
2056
+ /no transfer is waiting for a TAN/,
2057
+ );
2058
+ });
2059
+
2060
+ it('requires the TAN for a TAN method that is not decoupled, without dropping the transfer', async () => {
2061
+ bank.responses.push(
2062
+ initOk(),
2063
+ answer(
2064
+ WARNINGS,
2065
+ hirms(3, NO_HKVPA_NEEDED),
2066
+ hirms(5, TAN_REQUIRED),
2067
+ hivppSingle('RCVC'),
2068
+ hitan(),
2069
+ ),
2070
+ );
2071
+ await client.transfer(ACCOUNT, TRANSFER);
2072
+
2073
+ await expect(client.transferWithTan('TAN-REF-1')).rejects.toThrow(/TAN must be provided/);
2074
+
2075
+ bank.responses.push(tanAccepted(), endOk());
2076
+ expect(await client.transferWithTan('TAN-REF-1', '123456')).toMatchObject({ success: true });
2077
+ });
2078
+
2079
+ it('still reports success when only ending the dialog fails after the bank accepted', async () => {
2080
+ bank.responses.push(
2081
+ initOk(),
2082
+ answer(
2083
+ WARNINGS,
2084
+ hirms(3, NO_HKVPA_NEEDED),
2085
+ hirms(5, TAN_REQUIRED),
2086
+ hivppSingle('RCVC'),
2087
+ hitan(),
2088
+ ),
2089
+ tanAccepted(),
2090
+ new Error('connection reset'),
2091
+ );
2092
+ await client.transfer(ACCOUNT, TRANSFER);
2093
+
2094
+ const done = await client.transferWithTan('TAN-REF-1', '123456');
2095
+
2096
+ expect(done).toMatchObject({ success: true, requiresTan: false });
2097
+ });
2098
+
2099
+ it('passes on a connection error during the TAN step and drops the transfer', async () => {
2100
+ bank.responses.push(
2101
+ initOk(),
2102
+ answer(
2103
+ WARNINGS,
2104
+ hirms(3, NO_HKVPA_NEEDED),
2105
+ hirms(5, TAN_REQUIRED),
2106
+ hivppSingle('RCVC'),
2107
+ hitan(),
2108
+ ),
2109
+ new Error('connection reset'),
2110
+ endOk(),
2111
+ );
2112
+ await client.transfer(ACCOUNT, TRANSFER);
2113
+
2114
+ await expect(client.transferWithTan('TAN-REF-1', '123456')).rejects.toThrow(
2115
+ 'connection reset',
2116
+ );
2117
+ expect(sentOrders().at(-1)).toEqual(['HKEND']);
2118
+ await expect(client.transferWithTan('TAN-REF-1', '123456')).rejects.toThrow(
2119
+ /no transfer is waiting/,
2120
+ );
2121
+ });
2122
+
2123
+ it('cancels a transfer waiting for its TAN', async () => {
2124
+ bank.responses.push(
2125
+ initOk(),
2126
+ answer(
2127
+ WARNINGS,
2128
+ hirms(3, NO_HKVPA_NEEDED),
2129
+ hirms(5, TAN_REQUIRED),
2130
+ hivppSingle('RCVC'),
2131
+ hitan(),
2132
+ ),
2133
+ endOk(),
2134
+ );
2135
+ const { transferId } = await client.transfer(ACCOUNT, TRANSFER);
2136
+
2137
+ await client.cancelTransfer(transferId);
2138
+
2139
+ expect(sentOrders().at(-1)).toEqual(['HKEND']);
2140
+ await client.cancelTransfer(transferId);
2141
+ expect(bank.sent).toHaveLength(3);
2142
+ });
2143
+
2144
+ describe('overlapping calls', () => {
2145
+ /** A bank answer that arrives only when the test delivers it */
2146
+ const deferred = () => {
2147
+ let deliver: (message: Message) => void = () => {};
2148
+ const promise = new Promise<Message>((resolve) => {
2149
+ deliver = resolve;
2150
+ });
2151
+ return { promise, deliver };
2152
+ };
2153
+
2154
+ it('sends a confirmation once when confirmTransfer() is called again before the answer', async () => {
2155
+ bank.responses.push(
2156
+ initOk(),
2157
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')),
2158
+ );
2159
+ const { transferId } = await client.transfer(ACCOUNT, TRANSFER);
2160
+
2161
+ bank.responses.push(
2162
+ answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')),
2163
+ answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-3')),
2164
+ );
2165
+ const [first, second] = await Promise.allSettled([
2166
+ client.confirmTransfer(transferId),
2167
+ client.confirmTransfer(transferId),
2168
+ ]);
2169
+
2170
+ expect(first).toMatchObject({ status: 'fulfilled', value: { tanReference: 'TAN-REF-2' } });
2171
+ expect(second).toMatchObject({ status: 'rejected' });
2172
+ expect((second as PromiseRejectedResult).reason.message).toMatch(/still waiting/);
2173
+ expect(sentOrders().slice(2)).toEqual([['HKVPA', 'HKCCS', 'HKTAN']]);
2174
+ });
2175
+
2176
+ it('sends a TAN once when transferWithTan() is called again before the answer', async () => {
2177
+ bank.responses.push(
2178
+ initOk(),
2179
+ answer(WARNINGS, hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
2180
+ );
2181
+ await client.transfer(ACCOUNT, TRANSFER);
2182
+
2183
+ bank.responses.push(tanAccepted(), endOk(), tanAccepted(), endOk());
2184
+ const [first, second] = await Promise.allSettled([
2185
+ client.transferWithTan('TAN-REF-1', '123456'),
2186
+ client.transferWithTan('TAN-REF-1', '123456'),
2187
+ ]);
2188
+
2189
+ expect(first).toMatchObject({ status: 'fulfilled', value: { success: true } });
2190
+ expect(second).toMatchObject({ status: 'rejected' });
2191
+ expect(sentOrders().slice(2)).toEqual([['HKVPA', 'HKTAN'], ['HKEND']]);
2192
+ });
2193
+
2194
+ it('refuses to cancel while a step waits for its answer, and keeps the transfer', async () => {
2195
+ bank.responses.push(
2196
+ initOk(),
2197
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')),
2198
+ );
2199
+ const { transferId } = await client.transfer(ACCOUNT, TRANSFER);
2200
+
2201
+ const tanAnswer = deferred();
2202
+ bank.responses.push(tanAnswer.promise);
2203
+ const confirmed = client.confirmTransfer(transferId);
2204
+
2205
+ await expect(client.cancelTransfer(transferId)).rejects.toThrow(/still waiting/);
2206
+ await expect(client.transfer(ACCOUNT, TRANSFER)).rejects.toThrow(/already in progress/);
2207
+ expect(bank.sent).toHaveLength(3);
2208
+
2209
+ tanAnswer.deliver(answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')));
2210
+ expect(await confirmed).toMatchObject({ requiresTan: true, tanReference: 'TAN-REF-2' });
2211
+
2212
+ bank.responses.push(tanAccepted(), endOk());
2213
+ expect(await client.transferWithTan('TAN-REF-2', '123456')).toMatchObject({
2214
+ success: true,
2215
+ });
2216
+ });
2217
+
2218
+ it('leaves a transfer alone whose first message still waits for its answer', async () => {
2219
+ const orderAnswer = deferred();
2220
+ bank.responses.push(initOk(), orderAnswer.promise);
2221
+ const submitted = client.transfer(ACCOUNT, TRANSFER);
2222
+ await vi.waitFor(() => expect(bank.sent).toHaveLength(2));
2223
+
2224
+ await client.cancelTransfer('T');
2225
+ await expect(client.confirmTransfer('T')).rejects.toThrow(/still waiting/);
2226
+ await expect(client.transferWithTan('TAN-REF-1', '123456')).rejects.toThrow(
2227
+ /still waiting/,
2228
+ );
2229
+
2230
+ orderAnswer.deliver(answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')));
2231
+ const response = await submitted;
2232
+ expect(response).toMatchObject({ requiresVopConfirmation: true });
2233
+ expect(bank.sent).toHaveLength(2);
2234
+
2235
+ bank.responses.push(endOk());
2236
+ await client.cancelTransfer(response.transferId);
2237
+ expect(sentOrders().at(-1)).toEqual(['HKEND']);
2238
+ });
2239
+ });
2240
+
2241
+ describe('transfer references', () => {
2242
+ it('gives every transfer its own reference, on every response', async () => {
2243
+ bank.responses.push(
2244
+ answer(OK, "HIRMS:3:2:5+0030::Sicherheitsfreigabe erforderlich.'", hitan('INIT-REF')),
2245
+ );
2246
+ const first = await client.transfer(ACCOUNT, TRANSFER);
2247
+
2248
+ bank.responses.push(
2249
+ initOk(),
2250
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')),
2251
+ );
2252
+ const second = await client.transferWithTan('INIT-REF', '111111');
2253
+
2254
+ bank.responses.push(endOk(), initOk(), answer(OK, hirms(4, '0020::Auftrag ausgefuehrt.')));
2255
+ await client.cancelTransfer(second.transferId);
2256
+ const other = await client.transfer(ACCOUNT, TRANSFER);
2257
+
2258
+ expect(first.transferId).toMatch(/^[0-9a-f]{32}$/);
2259
+ expect(second.transferId).toBe(first.transferId);
2260
+ expect(other.transferId).toMatch(/^[0-9a-f]{32}$/);
2261
+ expect(other.transferId).not.toBe(first.transferId);
2262
+ });
2263
+
2264
+ it('does not confirm a later transfer with the reference of an earlier one', async () => {
2265
+ bank.responses.push(
2266
+ initOk(),
2267
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')),
2268
+ );
2269
+ const earlier = await client.transfer(ACCOUNT, TRANSFER);
2270
+ bank.responses.push(endOk());
2271
+ await client.cancelTransfer(earlier.transferId);
2272
+
2273
+ bank.responses.push(
2274
+ initOk(),
2275
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')),
2276
+ );
2277
+ const later = await client.transfer(ACCOUNT, { ...TRANSFER, amount: 100 });
2278
+ const sent = bank.sent.length;
2279
+
2280
+ await expect(client.confirmTransfer(earlier.transferId)).rejects.toThrow(
2281
+ /no transfer is waiting/,
2282
+ );
2283
+ expect(bank.sent).toHaveLength(sent);
2284
+
2285
+ bank.responses.push(answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')));
2286
+ expect(await client.confirmTransfer(later.transferId)).toMatchObject({
2287
+ requiresTan: true,
2288
+ });
2289
+ });
2290
+
2291
+ it('does not cancel a later transfer with the reference of an earlier one', async () => {
2292
+ bank.responses.push(
2293
+ initOk(),
2294
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')),
2295
+ );
2296
+ const earlier = await client.transfer(ACCOUNT, TRANSFER);
2297
+ bank.responses.push(endOk());
2298
+ await client.cancelTransfer(earlier.transferId);
2299
+
2300
+ bank.responses.push(
2301
+ initOk(),
2302
+ answer(WARNINGS, hirms(3, CHECK_RESULT), hivppSingle('RVNM')),
2303
+ );
2304
+ const later = await client.transfer(ACCOUNT, TRANSFER);
2305
+ const sent = bank.sent.length;
2306
+
2307
+ await client.cancelTransfer(earlier.transferId);
2308
+ expect(bank.sent).toHaveLength(sent);
2309
+
2310
+ bank.responses.push(answer(OK, hirms(5, TAN_REQUIRED), hitan('TAN-REF-2')));
2311
+ expect(await client.confirmTransfer(later.transferId)).toMatchObject({
2312
+ requiresTan: true,
2313
+ });
2314
+ });
2315
+
2316
+ it('keeps the outstanding challenge apart from the response the caller may change', async () => {
2317
+ bank.responses.push(
2318
+ initOk(),
2319
+ answer(WARNINGS, hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
2320
+ );
2321
+ const response = await client.transfer(ACCOUNT, TRANSFER);
2322
+ response.tanReference = 'OTHER';
2323
+
2324
+ await expect(client.transferWithTan('OTHER', '123456')).rejects.toThrow(
2325
+ /does not belong to the challenge/,
2326
+ );
2327
+ expect(bank.sent).toHaveLength(2);
2328
+
2329
+ bank.responses.push(tanAccepted(), endOk());
2330
+ expect(await client.transferWithTan('TAN-REF-1', '123456')).toMatchObject({
2331
+ success: true,
2332
+ });
2333
+ });
2334
+
2335
+ it('offers no TAN step a changed response asks for after a deviation', async () => {
2336
+ bank.responses.push(
2337
+ initOk(),
2338
+ answer(
2339
+ WARNINGS,
2340
+ hirms(3, CHECK_RESULT),
2341
+ hirms(5, TAN_REQUIRED),
2342
+ hitan(),
2343
+ hivppSingle('RVNM'),
2344
+ ),
2345
+ );
2346
+ const response = await client.transfer(ACCOUNT, TRANSFER);
2347
+ expect(response.requiresVopConfirmation).toBe(true);
2348
+ Object.assign(response, { requiresTan: true, tanReference: 'TAN-REF-1' });
2349
+
2350
+ await expect(client.transferWithTan('TAN-REF-1', '123456')).rejects.toThrow(
2351
+ /no transfer is waiting for a TAN/,
2352
+ );
2353
+ expect(bank.sent).toHaveLength(2);
2354
+ });
2355
+
2356
+ it('keeps the challenge of the login apart from the response the caller may change', async () => {
2357
+ bank.responses.push(
2358
+ answer(OK, "HIRMS:3:2:5+0030::Sicherheitsfreigabe erforderlich.'", hitan('INIT-REF')),
2359
+ );
2360
+ const response = await client.transfer(ACCOUNT, TRANSFER);
2361
+ response.tanReference = 'OTHER';
2362
+
2363
+ await expect(client.transferWithTan('OTHER', '111111')).rejects.toThrow(
2364
+ /does not belong to the challenge/,
2365
+ );
2366
+ expect(bank.sent).toHaveLength(1);
2367
+
2368
+ bank.responses.push(
2369
+ initOk(),
2370
+ answer(WARNINGS, hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
2371
+ );
2372
+ expect(await client.transferWithTan('INIT-REF', '111111')).toMatchObject({
2373
+ requiresTan: true,
2374
+ tanReference: 'TAN-REF-1',
2375
+ });
2376
+ });
2377
+
2378
+ it('refuses a TAN reference other than the outstanding challenge, keeping the transfer', async () => {
2379
+ bank.responses.push(
2380
+ initOk(),
2381
+ answer(WARNINGS, hirms(5, TAN_REQUIRED), hivppSingle('RCVC'), hitan()),
2382
+ );
2383
+ await client.transfer(ACCOUNT, TRANSFER);
2384
+
2385
+ await expect(client.transferWithTan('PREVIOUS-TRANSFER', '123456')).rejects.toThrow(
2386
+ /does not belong to the challenge/,
2387
+ );
2388
+ expect(bank.sent).toHaveLength(2);
2389
+
2390
+ bank.responses.push(tanAccepted(), endOk());
2391
+ expect(await client.transferWithTan('TAN-REF-1', '123456')).toMatchObject({
2392
+ success: true,
2393
+ });
2394
+ expect(sentOrders().slice(2)).toEqual([['HKVPA', 'HKTAN'], ['HKEND']]);
2395
+ });
2396
+ });
2397
+ });
2398
+ });
2399
+
2400
+ describe('extractVopResult', () => {
2401
+ const report = (status: string, encoding = 'UTF-8', reason = '') =>
2402
+ `<?xml version="1.0" encoding="${encoding}"?><Document><CstmrPmtStsRpt><OrgnlGrpInfAndSts><OrgnlMsgId>M</OrgnlMsgId></OrgnlGrpInfAndSts><OrgnlPmtInfAndSts><TxInfAndSts><TxSts>${status}</TxSts>${reason ? `<StsRsnInf><AddtlInf>${reason}</AddtlInf></StsRsnInf>` : ''}</TxInfAndSts></OrgnlPmtInfAndSts></CstmrPmtStsRpt></Document>`;
2403
+
2404
+ it('lets a deviation win when the single result and the report disagree', () => {
2405
+ const result = extractVopResult(
2406
+ {
2407
+ header: { segId: 'HIVPP', segNr: 5, version: 1 },
2408
+ vopId: 'VOP-01',
2409
+ singleResult: { iban: 'DE02120300000000202051', result: 'RCVC' },
2410
+ paymentStatusReport: report('RVNM'),
2411
+ },
2412
+ undefined,
2413
+ false,
2414
+ );
2415
+
2416
+ expect(result.result).toBe('noMatch');
2417
+ expect(result.code).toBe('RVNM');
2418
+ });
2419
+
2420
+ it('reads a report declared as ISO-8859-1 as it stands', () => {
2421
+ const result = extractVopResult(
2422
+ {
2423
+ header: { segId: 'HIVPP', segNr: 5, version: 1 },
2424
+ vopId: 'VOP-01',
2425
+ paymentStatusReport: report('RVMC', 'ISO-8859-1', 'Jürgen Müller'),
2426
+ },
2427
+ undefined,
2428
+ false,
2429
+ );
2430
+
2431
+ expect(result.suggestedName).toBe('Jürgen Müller');
2432
+ });
2433
+ });