@mojaloop/sdk-scheme-adapter 11.18.8

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 (277) hide show
  1. package/.env.example +140 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.json +30 -0
  4. package/.nvmrc +1 -0
  5. package/.versionrc +15 -0
  6. package/CHANGELOG.md +118 -0
  7. package/InboundServer/api.yaml +3594 -0
  8. package/InboundServer/api_template.yaml +69 -0
  9. package/InboundServer/handlers.js +940 -0
  10. package/InboundServer/index.js +205 -0
  11. package/InboundServer/middlewares.js +426 -0
  12. package/OAuthTestServer/index.js +66 -0
  13. package/OAuthTestServer/model.js +70 -0
  14. package/OutboundServer/api.yaml +2732 -0
  15. package/OutboundServer/api_interfaces/index.d.ts +117 -0
  16. package/OutboundServer/api_interfaces/openapi.d.ts +1475 -0
  17. package/OutboundServer/api_template/components/parameters/bulkQuoteId.yaml +9 -0
  18. package/OutboundServer/api_template/components/parameters/bulkTransferId.yaml +9 -0
  19. package/OutboundServer/api_template/components/parameters/requestToPayTransactionId.yaml +9 -0
  20. package/OutboundServer/api_template/components/parameters/transferId.yaml +9 -0
  21. package/OutboundServer/api_template/components/responses/accountsCreationCompleted.yaml +5 -0
  22. package/OutboundServer/api_template/components/responses/accountsCreationError.yaml +5 -0
  23. package/OutboundServer/api_template/components/responses/accountsCreationTimeout.yaml +5 -0
  24. package/OutboundServer/api_template/components/responses/authorizationPostSuccess.yaml +5 -0
  25. package/OutboundServer/api_template/components/responses/authorizationsServerError.yaml +5 -0
  26. package/OutboundServer/api_template/components/responses/bulkQuoteBadRequest.yaml +5 -0
  27. package/OutboundServer/api_template/components/responses/bulkQuoteServerError.yaml +5 -0
  28. package/OutboundServer/api_template/components/responses/bulkQuoteSuccess.yaml +5 -0
  29. package/OutboundServer/api_template/components/responses/bulkQuoteTimeout.yaml +5 -0
  30. package/OutboundServer/api_template/components/responses/bulkTransferBadRequest.yaml +5 -0
  31. package/OutboundServer/api_template/components/responses/bulkTransferServerError.yaml +5 -0
  32. package/OutboundServer/api_template/components/responses/bulkTransferSuccess.yaml +5 -0
  33. package/OutboundServer/api_template/components/responses/bulkTransferTimeout.yaml +5 -0
  34. package/OutboundServer/api_template/components/responses/partiesByIdError404.yaml +9 -0
  35. package/OutboundServer/api_template/components/responses/partiesByIdSuccess.yaml +5 -0
  36. package/OutboundServer/api_template/components/responses/quotesPostSuccess.yaml +5 -0
  37. package/OutboundServer/api_template/components/responses/quotesServerError.yaml +5 -0
  38. package/OutboundServer/api_template/components/responses/requestToPaySuccess.yaml +5 -0
  39. package/OutboundServer/api_template/components/responses/requestToPayTransferBadRequest.yaml +5 -0
  40. package/OutboundServer/api_template/components/responses/requestToPayTransferSuccess.yaml +5 -0
  41. package/OutboundServer/api_template/components/responses/simpleTransfersPostSuccess.yaml +5 -0
  42. package/OutboundServer/api_template/components/responses/simpleTransfersServerError.yaml +5 -0
  43. package/OutboundServer/api_template/components/responses/transferBadRequest.yaml +5 -0
  44. package/OutboundServer/api_template/components/responses/transferServerError.yaml +5 -0
  45. package/OutboundServer/api_template/components/responses/transferSuccess.yaml +5 -0
  46. package/OutboundServer/api_template/components/responses/transferTimeout.yaml +5 -0
  47. package/OutboundServer/api_template/components/schemas/accountCreationStatus.yaml +18 -0
  48. package/OutboundServer/api_template/components/schemas/accountsCreationState.yaml +4 -0
  49. package/OutboundServer/api_template/components/schemas/accountsRequest.yaml +20 -0
  50. package/OutboundServer/api_template/components/schemas/accountsResponse.yaml +15 -0
  51. package/OutboundServer/api_template/components/schemas/async2SyncCurrentState.yaml +5 -0
  52. package/OutboundServer/api_template/components/schemas/authorizationsPostRequest.yaml +15 -0
  53. package/OutboundServer/api_template/components/schemas/authorizationsPostResponse.yaml +19 -0
  54. package/OutboundServer/api_template/components/schemas/bulkQuoteErrorResponse.yaml +8 -0
  55. package/OutboundServer/api_template/components/schemas/bulkQuoteRequest.yaml +26 -0
  56. package/OutboundServer/api_template/components/schemas/bulkQuoteResponse.yaml +21 -0
  57. package/OutboundServer/api_template/components/schemas/bulkQuoteStatus.yaml +4 -0
  58. package/OutboundServer/api_template/components/schemas/bulkQuoteStatusResponse.yaml +17 -0
  59. package/OutboundServer/api_template/components/schemas/bulkTransferErrorResponse.yaml +8 -0
  60. package/OutboundServer/api_template/components/schemas/bulkTransferRequest.yaml +26 -0
  61. package/OutboundServer/api_template/components/schemas/bulkTransferResponse.yaml +16 -0
  62. package/OutboundServer/api_template/components/schemas/bulkTransferStatus.yaml +4 -0
  63. package/OutboundServer/api_template/components/schemas/bulkTransferStatusResponse.yaml +17 -0
  64. package/OutboundServer/api_template/components/schemas/errorAccountsResponse.yaml +8 -0
  65. package/OutboundServer/api_template/components/schemas/errorAuthorizationsResponse.yaml +3 -0
  66. package/OutboundServer/api_template/components/schemas/errorQuotesResponse.yaml +9 -0
  67. package/OutboundServer/api_template/components/schemas/errorResponse.yaml +8 -0
  68. package/OutboundServer/api_template/components/schemas/errorSimpleTransfersResponse.yaml +3 -0
  69. package/OutboundServer/api_template/components/schemas/errorTransferResponse.yaml +8 -0
  70. package/OutboundServer/api_template/components/schemas/extensionListEmptiable.yaml +6 -0
  71. package/OutboundServer/api_template/components/schemas/individualQuote.yaml +32 -0
  72. package/OutboundServer/api_template/components/schemas/individualQuoteResult.yaml +28 -0
  73. package/OutboundServer/api_template/components/schemas/individualTransfer.yaml +32 -0
  74. package/OutboundServer/api_template/components/schemas/individualTransferFulfilment.yaml +13 -0
  75. package/OutboundServer/api_template/components/schemas/individualTransferResult.yaml +41 -0
  76. package/OutboundServer/api_template/components/schemas/mojaloopError.yaml +5 -0
  77. package/OutboundServer/api_template/components/schemas/mojaloopTransactionRequestState.yaml +2 -0
  78. package/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml +13 -0
  79. package/OutboundServer/api_template/components/schemas/quote.yaml +3 -0
  80. package/OutboundServer/api_template/components/schemas/quoteError.yaml +16 -0
  81. package/OutboundServer/api_template/components/schemas/quotesPostRequest.yaml +13 -0
  82. package/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml +48 -0
  83. package/OutboundServer/api_template/components/schemas/requestToPayRequest.yaml +39 -0
  84. package/OutboundServer/api_template/components/schemas/requestToPayResponse.yaml +41 -0
  85. package/OutboundServer/api_template/components/schemas/requestToPayTransferRequest.yaml +42 -0
  86. package/OutboundServer/api_template/components/schemas/requestToPayTransferResponse.yaml +58 -0
  87. package/OutboundServer/api_template/components/schemas/simpleTransferServerError.yaml +5 -0
  88. package/OutboundServer/api_template/components/schemas/simpleTransfersPostRequest.yaml +12 -0
  89. package/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml +11 -0
  90. package/OutboundServer/api_template/components/schemas/transactionType.yaml +4 -0
  91. package/OutboundServer/api_template/components/schemas/transferContinuationAcceptOTP.yaml +9 -0
  92. package/OutboundServer/api_template/components/schemas/transferContinuationAcceptParty.yaml +8 -0
  93. package/OutboundServer/api_template/components/schemas/transferContinuationAcceptQuote.yaml +9 -0
  94. package/OutboundServer/api_template/components/schemas/transferError.yaml +16 -0
  95. package/OutboundServer/api_template/components/schemas/transferFulfilment.yaml +3 -0
  96. package/OutboundServer/api_template/components/schemas/transferParty.yaml +40 -0
  97. package/OutboundServer/api_template/components/schemas/transferRequest.yaml +37 -0
  98. package/OutboundServer/api_template/components/schemas/transferResponse.yaml +58 -0
  99. package/OutboundServer/api_template/components/schemas/transferStatus.yaml +6 -0
  100. package/OutboundServer/api_template/components/schemas/transferStatusResponse.yaml +13 -0
  101. package/OutboundServer/api_template/health.yaml +12 -0
  102. package/OutboundServer/api_template/openapi.yaml +55 -0
  103. package/OutboundServer/api_template/paths/accounts.yaml +26 -0
  104. package/OutboundServer/api_template/paths/authorizations.yaml +19 -0
  105. package/OutboundServer/api_template/paths/bulkQuotes.yaml +23 -0
  106. package/OutboundServer/api_template/paths/bulkQuotes_bulkQuoteId.yaml +24 -0
  107. package/OutboundServer/api_template/paths/bulkTransfers.yaml +23 -0
  108. package/OutboundServer/api_template/paths/bulkTransfers_bulkTransferId.yaml +24 -0
  109. package/OutboundServer/api_template/paths/parties_Type_ID.yaml +20 -0
  110. package/OutboundServer/api_template/paths/parties_Type_ID_SubId.yaml +22 -0
  111. package/OutboundServer/api_template/paths/quotes.yaml +20 -0
  112. package/OutboundServer/api_template/paths/requestToPay.yaml +22 -0
  113. package/OutboundServer/api_template/paths/requestToPayTransfer.yaml +57 -0
  114. package/OutboundServer/api_template/paths/requestToPayTransfer_requestToPayTransactionId.yaml +34 -0
  115. package/OutboundServer/api_template/paths/simpleTransfers.yaml +19 -0
  116. package/OutboundServer/api_template/paths/transfers.yaml +55 -0
  117. package/OutboundServer/api_template/paths/transfers_transferId.yaml +58 -0
  118. package/OutboundServer/handlers.js +622 -0
  119. package/OutboundServer/index.js +137 -0
  120. package/OutboundServer/middlewares.js +67 -0
  121. package/TestServer/api.yaml +62 -0
  122. package/TestServer/handlers.js +63 -0
  123. package/TestServer/index.js +215 -0
  124. package/audit-resolve.json +65 -0
  125. package/babel.config.js +3 -0
  126. package/config.js +158 -0
  127. package/index.d.ts +1 -0
  128. package/index.js +149 -0
  129. package/jest.config.js +15 -0
  130. package/lib/api/index.js +12 -0
  131. package/lib/cache.js +352 -0
  132. package/lib/check.js +25 -0
  133. package/lib/model/AccountsModel.js +396 -0
  134. package/lib/model/Async2SyncModel.js +283 -0
  135. package/lib/model/AuthorizationsModel.js +86 -0
  136. package/lib/model/InboundTransfersModel.js +730 -0
  137. package/lib/model/OutboundBulkQuotesModel.js +485 -0
  138. package/lib/model/OutboundBulkTransfersModel.js +479 -0
  139. package/lib/model/OutboundRequestToPayModel.js +517 -0
  140. package/lib/model/OutboundRequestToPayTransferModel.js +893 -0
  141. package/lib/model/OutboundTransfersModel.js +823 -0
  142. package/lib/model/PartiesModel.js +70 -0
  143. package/lib/model/ProxyModel/MatchRules/Expression.js +48 -0
  144. package/lib/model/ProxyModel/MatchRules/Headers.js +65 -0
  145. package/lib/model/ProxyModel/MatchRules/MatchRule.js +27 -0
  146. package/lib/model/ProxyModel/MatchRules/Path.js +36 -0
  147. package/lib/model/ProxyModel/MatchRules/Query.js +65 -0
  148. package/lib/model/ProxyModel/MatchRules/index.js +19 -0
  149. package/lib/model/ProxyModel/Route.js +82 -0
  150. package/lib/model/ProxyModel/configSchema.json +118 -0
  151. package/lib/model/ProxyModel/index.js +138 -0
  152. package/lib/model/QuotesModel.js +94 -0
  153. package/lib/model/TransfersModel.js +81 -0
  154. package/lib/model/common/BackendError.js +26 -0
  155. package/lib/model/common/PersistentStateMachine.js +93 -0
  156. package/lib/model/common/index.js +18 -0
  157. package/lib/model/index.js +43 -0
  158. package/lib/model/lib/deferredJob.js +113 -0
  159. package/lib/model/lib/index.js +9 -0
  160. package/lib/model/lib/requests/backendRequests.js +227 -0
  161. package/lib/model/lib/requests/common.js +76 -0
  162. package/lib/model/lib/requests/index.js +19 -0
  163. package/lib/model/lib/shared.js +468 -0
  164. package/lib/randomphrase/index.js +21 -0
  165. package/lib/randomphrase/words.json +3397 -0
  166. package/lib/router.js +28 -0
  167. package/lib/validate.js +205 -0
  168. package/package.json +102 -0
  169. package/test/__mocks__/@mojaloop/sdk-standard-components.js +152 -0
  170. package/test/__mocks__/javascript-state-machine.js +21 -0
  171. package/test/__mocks__/redis.js +49 -0
  172. package/test/__mocks__/uuidv4.js +16 -0
  173. package/test/config/integration.env +136 -0
  174. package/test/integration/lib/Outbound/authorizations.test.js +58 -0
  175. package/test/integration/lib/Outbound/data/authorizationsPostRequest.json +43 -0
  176. package/test/integration/lib/Outbound/data/quotesPostRequest.json +52 -0
  177. package/test/integration/lib/Outbound/data/transfersPostRequest.json +24 -0
  178. package/test/integration/lib/Outbound/parties.test.js +28 -0
  179. package/test/integration/lib/Outbound/quotes.test.js +58 -0
  180. package/test/integration/lib/Outbound/simpleTransfers.test.js +67 -0
  181. package/test/integration/lib/cache.test.js +80 -0
  182. package/test/integration/testEnv.js +7 -0
  183. package/test/unit/InboundServer.test.js +443 -0
  184. package/test/unit/TestServer.test.js +394 -0
  185. package/test/unit/api/accounts/accounts.test.js +128 -0
  186. package/test/unit/api/accounts/data/postAccountsBody.json +7 -0
  187. package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +25 -0
  188. package/test/unit/api/accounts/data/postAccountsErrorTimeoutResponse.json +19 -0
  189. package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +17 -0
  190. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +21 -0
  191. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +21 -0
  192. package/test/unit/api/accounts/utils.js +65 -0
  193. package/test/unit/api/proxy/data/proxyConfig.yaml +82 -0
  194. package/test/unit/api/proxy/data/requestBody.json +22 -0
  195. package/test/unit/api/proxy/data/requestHeaders.json +5 -0
  196. package/test/unit/api/proxy/data/requestQuery.json +6 -0
  197. package/test/unit/api/proxy/data/responseBody.json +21 -0
  198. package/test/unit/api/proxy/data/responseHeaders.json +5 -0
  199. package/test/unit/api/proxy/proxy.test.js +220 -0
  200. package/test/unit/api/proxy/utils.js +79 -0
  201. package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +21 -0
  202. package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +17 -0
  203. package/test/unit/api/transfers/data/postQuotesBody.json +52 -0
  204. package/test/unit/api/transfers/data/postTransfersBadBody.json +17 -0
  205. package/test/unit/api/transfers/data/postTransfersBody.json +24 -0
  206. package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +53 -0
  207. package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +47 -0
  208. package/test/unit/api/transfers/data/postTransfersSimpleBody.json +26 -0
  209. package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +101 -0
  210. package/test/unit/api/transfers/data/putPartiesBody.json +20 -0
  211. package/test/unit/api/transfers/data/putQuotesBody.json +37 -0
  212. package/test/unit/api/transfers/data/putTransfersBody.json +17 -0
  213. package/test/unit/api/transfers/transfers.test.js +191 -0
  214. package/test/unit/api/transfers/utils.js +183 -0
  215. package/test/unit/api/utils.js +75 -0
  216. package/test/unit/config.test.js +119 -0
  217. package/test/unit/data/commonHttpHeaders.json +6 -0
  218. package/test/unit/data/defaultConfig.json +58 -0
  219. package/test/unit/data/postQuotesBody.json +52 -0
  220. package/test/unit/data/putParticipantsBody.json +12 -0
  221. package/test/unit/data/putPartiesBody.json +20 -0
  222. package/test/unit/data/testFile.json +29 -0
  223. package/test/unit/data/testFile.yaml +14 -0
  224. package/test/unit/inboundApi/data/mockArguments.json +117 -0
  225. package/test/unit/inboundApi/data/mockTransactionRequest.json +42 -0
  226. package/test/unit/inboundApi/handlers.test.js +799 -0
  227. package/test/unit/index.test.js +55 -0
  228. package/test/unit/lib/cache.test.js +146 -0
  229. package/test/unit/lib/model/AccountsModel.test.js +121 -0
  230. package/test/unit/lib/model/AuthorizationsModel.test.js +460 -0
  231. package/test/unit/lib/model/InboundTransfersModel.test.js +628 -0
  232. package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +249 -0
  233. package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +244 -0
  234. package/test/unit/lib/model/OutboundRequestToPayModel.test.js +166 -0
  235. package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +245 -0
  236. package/test/unit/lib/model/OutboundTransfersModel.test.js +836 -0
  237. package/test/unit/lib/model/PartiesModel.test.js +468 -0
  238. package/test/unit/lib/model/QuotesModel.test.js +470 -0
  239. package/test/unit/lib/model/TransfersModel.test.js +474 -0
  240. package/test/unit/lib/model/common/PersistentStateMachine.test.js +179 -0
  241. package/test/unit/lib/model/data/authorizationsResponse.json +13 -0
  242. package/test/unit/lib/model/data/bulkQuoteRequest.json +27 -0
  243. package/test/unit/lib/model/data/bulkQuoteResponse.json +35 -0
  244. package/test/unit/lib/model/data/bulkTransferFulfil.json +13 -0
  245. package/test/unit/lib/model/data/bulkTransferRequest.json +29 -0
  246. package/test/unit/lib/model/data/defaultConfig.json +47 -0
  247. package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +42 -0
  248. package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +22 -0
  249. package/test/unit/lib/model/data/getTransfersBackendResponse.json +34 -0
  250. package/test/unit/lib/model/data/getTransfersMojaloopResponse.json +17 -0
  251. package/test/unit/lib/model/data/mockArguments.json +131 -0
  252. package/test/unit/lib/model/data/mockTxnRequestsArguments.json +63 -0
  253. package/test/unit/lib/model/data/notificationToPayee.json +10 -0
  254. package/test/unit/lib/model/data/payeeParty.json +16 -0
  255. package/test/unit/lib/model/data/putAuthorizationsResponse.json +10 -0
  256. package/test/unit/lib/model/data/putQuotesResponse.json +33 -0
  257. package/test/unit/lib/model/data/putTransfersResponse.json +5 -0
  258. package/test/unit/lib/model/data/quoteResponse.json +31 -0
  259. package/test/unit/lib/model/data/requestToPayRequest.json +20 -0
  260. package/test/unit/lib/model/data/requestToPayTransferRequest.json +27 -0
  261. package/test/unit/lib/model/data/transactionRequestResponse.json +18 -0
  262. package/test/unit/lib/model/data/transferFulfil.json +8 -0
  263. package/test/unit/lib/model/data/transferRequest.json +26 -0
  264. package/test/unit/lib/model/mockedLibRequests.js +74 -0
  265. package/test/unit/mockLogger.js +39 -0
  266. package/test/unit/outboundApi/data/bulkQuoteRequest.json +28 -0
  267. package/test/unit/outboundApi/data/bulkTransferRequest.json +28 -0
  268. package/test/unit/outboundApi/data/mockBulkQuoteError.json +45 -0
  269. package/test/unit/outboundApi/data/mockBulkTransferError.json +48 -0
  270. package/test/unit/outboundApi/data/mockError.json +41 -0
  271. package/test/unit/outboundApi/data/mockGetPartiesError.json +4 -0
  272. package/test/unit/outboundApi/data/mockRequestToPayError.json +32 -0
  273. package/test/unit/outboundApi/data/mockRequestToPayTransferError.json +39 -0
  274. package/test/unit/outboundApi/data/requestToPay.json +21 -0
  275. package/test/unit/outboundApi/data/requestToPayTransferRequest.json +20 -0
  276. package/test/unit/outboundApi/data/transferRequest.json +21 -0
  277. package/test/unit/outboundApi/handlers.test.js +986 -0
@@ -0,0 +1,19 @@
1
+ post:
2
+ description: The HTTP request `POST /authorizations` is used to request the Payer to enter the applicable credentials in the PISP system.
3
+ summary: Authorizations endpoint
4
+ operationId: AuthorizationsPost
5
+ tags:
6
+ - authorizations
7
+ requestBody:
8
+ description: Perform authorization
9
+ required: true
10
+ content:
11
+ application/json:
12
+ schema:
13
+ $ref: '../components/schemas/authorizationsPostRequest.yaml'
14
+ responses:
15
+ 200:
16
+ $ref: '../components/responses/authorizationPostSuccess.yaml'
17
+ 500:
18
+ $ref: '../components/responses/authorizationsServerError.yaml'
19
+
@@ -0,0 +1,23 @@
1
+ post:
2
+ summary: Request bulk quotes for the provided financial transactions
3
+ description: >
4
+ The HTTP request `POST /bulkQuotes` is used to request a bulk quote to
5
+ fascilitate funds transfer from payer DFSP to payees' DFSP.
6
+ tags:
7
+ - BulkQuotes
8
+ requestBody:
9
+ description: Bulk quote request body
10
+ content:
11
+ application/json:
12
+ schema:
13
+ $ref: ../components/schemas/bulkQuoteRequest.yaml
14
+ required: true
15
+ responses:
16
+ '200':
17
+ $ref: ../components/responses/bulkQuoteSuccess.yaml
18
+ '400':
19
+ $ref: ../components/responses/bulkQuoteBadRequest.yaml
20
+ '500':
21
+ $ref: ../components/responses/bulkQuoteServerError.yaml
22
+ '504':
23
+ $ref: ../components/responses/bulkQuoteTimeout.yaml
@@ -0,0 +1,24 @@
1
+ get:
2
+ summary: Retrieves information for a specific bulk quote
3
+ description: >-
4
+ The HTTP request `GET /bulkQuotes/{bulktQuoteId}` is used to get information
5
+ regarding a bulk quote created or requested earlier. The `{bulkQuoteId}` in
6
+ the URI should contain the `bulkQuoteId` that was used for the creation of
7
+ the bulk quote.
8
+ tags:
9
+ - BulkQuotes
10
+ parameters:
11
+ - $ref: ../components/parameters/bulkQuoteId.yaml
12
+ responses:
13
+ '200':
14
+ description: Bulk quote information successfully retrieved
15
+ content:
16
+ application/json:
17
+ schema:
18
+ $ref: ../components/schemas/bulkQuoteStatusResponse.yaml
19
+ '500':
20
+ description: An error occurred processing the bulk quote
21
+ content:
22
+ application/json:
23
+ schema:
24
+ $ref: ../components/schemas/errorResponse.yaml
@@ -0,0 +1,23 @@
1
+ post:
2
+ summary: Sends money from one account to multiple accounts
3
+ description: >
4
+ The HTTP request `POST /bulkTransfers` is used to request the movement of
5
+ funds from payer DFSP to payees' DFSP.
6
+ tags:
7
+ - BulkTransfers
8
+ requestBody:
9
+ description: Bulk transfer request body
10
+ content:
11
+ application/json:
12
+ schema:
13
+ $ref: ../components/schemas/bulkTransferRequest.yaml
14
+ required: true
15
+ responses:
16
+ '200':
17
+ $ref: ../components/responses/bulkTransferSuccess.yaml
18
+ '400':
19
+ $ref: ../components/responses/bulkTransferBadRequest.yaml
20
+ '500':
21
+ $ref: ../components/responses/bulkTransferServerError.yaml
22
+ '504':
23
+ $ref: ../components/responses/bulkTransferTimeout.yaml
@@ -0,0 +1,24 @@
1
+ get:
2
+ summary: Retrieves information for a specific bulk transfer
3
+ description: >-
4
+ The HTTP request `GET /bulkTransfers/{bulktTransferId}` is used to get
5
+ information regarding a bulk transfer created or requested earlier. The
6
+ `{bulkTransferId}` in the URI should contain the `bulkTransferId` that was
7
+ used for the creation of the bulk transfer.
8
+ tags:
9
+ - BulkTransfers
10
+ parameters:
11
+ - $ref: ../components/parameters/bulkTransferId.yaml
12
+ responses:
13
+ '200':
14
+ description: Bulk transfer information successfully retrieved
15
+ content:
16
+ application/json:
17
+ schema:
18
+ $ref: ../components/schemas/bulkTransferStatusResponse.yaml
19
+ '500':
20
+ description: An error occurred processing the bulk transfer
21
+ content:
22
+ application/json:
23
+ schema:
24
+ $ref: ../components/schemas/errorResponse.yaml
@@ -0,0 +1,20 @@
1
+ parameters:
2
+ - $ref: >-
3
+ ../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/parameters/Type.yaml
4
+ - $ref: >-
5
+ ../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/parameters/ID.yaml
6
+ get:
7
+ description: >-
8
+ The HTTP request GET /parties// (or GET /parties///) is used to lookup
9
+ information regarding the requested Party, defined by , and optionally (for
10
+ example, GET /parties/MSISDN/123456789, or GET
11
+ /parties/BUSINESS/shoecompany/employee1).
12
+ summary: PartiesByTypeAndID
13
+ tags:
14
+ - parties
15
+ operationId: PartiesByTypeAndID
16
+ responses:
17
+ '200':
18
+ $ref: ../components/responses/partiesByIdSuccess.yaml
19
+ '404':
20
+ $ref: ../components/responses/partiesByIdError404.yaml
@@ -0,0 +1,22 @@
1
+ parameters:
2
+ - $ref: >-
3
+ ../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/parameters/Type.yaml
4
+ - $ref: >-
5
+ ../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/parameters/ID.yaml
6
+ - $ref: >-
7
+ ../../../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/parameters/SubId.yaml
8
+ get:
9
+ description: >-
10
+ The HTTP request GET /parties// (or GET /parties///) is used to lookup
11
+ information regarding the requested Party, defined by , and optionally (for
12
+ example, GET /parties/MSISDN/123456789, or GET
13
+ /parties/BUSINESS/shoecompany/employee1).
14
+ summary: PartiesSubIdByTypeAndID
15
+ tags:
16
+ - parties
17
+ operationId: PartiesSubIdByTypeAndID
18
+ responses:
19
+ '200':
20
+ $ref: ../components/responses/partiesByIdSuccess.yaml
21
+ '404':
22
+ $ref: ../components/responses/partiesByIdError404.yaml
@@ -0,0 +1,20 @@
1
+ post:
2
+ summary: Quotes endpoint
3
+ description: >-
4
+ is used to request quotes from other DFSP
5
+ tags:
6
+ - quotes
7
+ operationId: QuotesPost
8
+ requestBody:
9
+ description: Quotes request payload
10
+ content:
11
+ application/json:
12
+ schema:
13
+ $ref: ../components/schemas/quotesPostRequest.yaml
14
+ required: true
15
+ responses:
16
+ '200':
17
+ $ref: ../components/responses/quotesPostSuccess.yaml
18
+ '500':
19
+ $ref: ../components/responses/quotesServerError.yaml
20
+
@@ -0,0 +1,22 @@
1
+ post:
2
+ summary: Receiver requesting funds from Sender
3
+ description: >
4
+ The HTTP request `POST /requestToPay` is used to support Pull Funds pattern
5
+ where in a receiver can request for funds from the Sender.
6
+
7
+ The underlying API has two stages:
8
+
9
+ 1. Party lookup. This facilitates a check by the sending party that the destination party is correct before proceeding with a money movement.
10
+ 2. Transaction Request. This request enables a Payee to request Payer to send electronic funds to the Payee.
11
+ tags:
12
+ - RequestToPay
13
+ requestBody:
14
+ description: RequestToPay request body
15
+ content:
16
+ application/json:
17
+ schema:
18
+ $ref: ../components/schemas/requestToPayRequest.yaml
19
+ required: true
20
+ responses:
21
+ '200':
22
+ $ref: ../components/responses/requestToPaySuccess.yaml
@@ -0,0 +1,57 @@
1
+ post:
2
+ summary: >-
3
+ Used to trigger funds from customer fsp account to merchant fsp account.
4
+ This is a follow-up request to requestToPay.
5
+ description: >
6
+ The HTTP request `POST /requestToPayTransfer` is used to request the
7
+ movement of funds from payer DFSP to payee DFSP.
8
+
9
+ The underlying Mojaloop API has three stages for money transfer:
10
+
11
+ 1. Quotation. This facilitates the exchange of fee information and the construction of a cryptographic "contract" between payee and payer DFSPs before funds are transferred.
12
+ 2. Authorization. This facilitates getting OTP from payee DFSP.
13
+ 3. Transfer. The enactment of the previously agreed "contract"
14
+
15
+ This method has several modes of operation.
16
+
17
+ - If the configuration variable `AUTO_ACCEPT_QUOTES` is set to `"false"`
18
+ this method will terminate and return the quotation when it has been
19
+ received from the payee DFSP.
20
+ If the payee wished to proceed with the otp, then a subsequent `PUT /transfers/{transferId}` request (accepting the quote) is required to continue the operation.
21
+ The scheme adapter will then proceed with the transfer state.
22
+
23
+ - If the configuration variable `AUTO_ACCEPT_OTP` is set to `"false"` this
24
+ method will terminate and return the otp when it has been received from the
25
+ payee DFSP.
26
+ If the payer wished to proceed with the transfer, then a subsequent `PUT /transfers/{transferId}` request (accepting the quote) is required to continue the operation.
27
+ The scheme adapter will then proceed with the transfer state.
28
+
29
+ If the configuration variables `AUTO_ACCEPT_PARTIES` and
30
+ `AUTO_ACCEPT_QUOTES` are both set to `"true"` this method will block until
31
+ all three transfer stages are complete. Upon completion it will return the
32
+ entire set of transfer details received during the operation.
33
+
34
+
35
+ Combinations of settings for `AUTO_ACCEPT...` configuration variables allow
36
+ the scheme adapter user to decide which mode of operation best suits their
37
+ use cases. i.e. the scheme adapter can be configured to "break" the three
38
+ stage transfer at these points in order to execute backend logic such as
39
+ party verification, quoted fees assessments etc...
40
+ tags:
41
+ - RequestToPayTransfer
42
+ requestBody:
43
+ description: Request To Pay Transfer request body
44
+ content:
45
+ application/json:
46
+ schema:
47
+ $ref: ../components/schemas/requestToPayTransferRequest.yaml
48
+ required: true
49
+ responses:
50
+ '200':
51
+ $ref: ../components/responses/requestToPayTransferSuccess.yaml
52
+ '400':
53
+ $ref: ../components/responses/requestToPayTransferBadRequest.yaml
54
+ '500':
55
+ $ref: ../components/responses/transferServerError.yaml
56
+ '504':
57
+ $ref: ../components/responses/transferTimeout.yaml
@@ -0,0 +1,34 @@
1
+ put:
2
+ summary: >-
3
+ Continues a transfer that has paused at the otp stage in order to accept or
4
+ reject quote
5
+ description: >
6
+ The HTTP request `PUT /transfers/{transferId}` is used to continue a
7
+ transfer initiated via the `POST /transfers` method that has halted after
8
+ party lookup and/or quotation stage.
9
+
10
+
11
+ The request body should contain either the "acceptOTP" or "acceptQuote"
12
+ property set to `true` as required to continue the transfer.
13
+
14
+
15
+ See the description of the `POST /requestToPayTransfer` HTTP method for more
16
+ information on modes of transfer.
17
+ tags:
18
+ - RequestToPayTransferID
19
+ requestBody:
20
+ content:
21
+ application/json:
22
+ schema:
23
+ oneOf:
24
+ - $ref: ../components/schemas/transferContinuationAcceptQuote.yaml
25
+ - $ref: ../components/schemas/transferContinuationAcceptOTP.yaml
26
+ parameters:
27
+ - $ref: ../components/parameters/requestToPayTransactionId.yaml
28
+ responses:
29
+ '200':
30
+ $ref: ../components/responses/transferSuccess.yaml
31
+ '500':
32
+ $ref: ../components/responses/transferServerError.yaml
33
+ '504':
34
+ $ref: ../components/responses/transferTimeout.yaml
@@ -0,0 +1,19 @@
1
+ post:
2
+ summary: Simple Transfers endpoint
3
+ description: >-
4
+ is used to request a transfer
5
+ tags:
6
+ - transfers
7
+ operationId: SimpleTransfersPost
8
+ requestBody:
9
+ description: Simple Transfer request payload
10
+ content:
11
+ application/json:
12
+ schema:
13
+ $ref: ../components/schemas/simpleTransfersPostRequest.yaml
14
+ required: true
15
+ responses:
16
+ '200':
17
+ $ref: ../components/responses/simpleTransfersPostSuccess.yaml
18
+ '500':
19
+ $ref: ../components/responses/simpleTransfersServerError.yaml
@@ -0,0 +1,55 @@
1
+ post:
2
+ summary: Sends money from one account to another
3
+ description: >
4
+ The HTTP request `POST /transfers` is used to request the movement of funds
5
+ from payer DFSP to payee DFSP.
6
+
7
+ The underlying Mojaloop API has three stages for money transfer:
8
+
9
+ 1. Party lookup. This facilitates a check by the sending party that the destination party is correct before proceeding with a money movement.
10
+ 2. Quotation. This facilitates the exchange of fee information and the construction of a cryptographic "contract" between payee and payer DFSPs before funds are transferred.
11
+ 3. Transfer. The enactment of the previously agreed "contract"
12
+
13
+ This method has several modes of operation.
14
+
15
+ - If the configuration variables `AUTO_ACCEPT_PARTIES` is set to `"false"`
16
+ this method will terminate when the payee party has been resolved and return
17
+ the payee party details.
18
+ If the payee wishes to proceed with the transfer, then a subsequent `PUT /transfers/{transferId}` request (accepting the payee party) is required to continue the operation.
19
+ The scheme adapter will then proceed with quotation stage...
20
+
21
+ - If the configuration variable `AUTO_ACCEPT_QUOTES` is set to `"false"`
22
+ this method will terminate and return the quotation when it has been
23
+ received from the payee DFSP.
24
+ If the payee wished to proceed with the transfer, then a subsequent `PUT /transfers/{transferId}` request (accepting the quote) is required to continue the operation.
25
+ The scheme adapter will then proceed with the transfer state.
26
+
27
+ If the configuration variables `AUTO_ACCEPT_PARTIES` and
28
+ `AUTO_ACCEPT_QUOTES` are both set to `"true"` this method will block until
29
+ all three transfer stages are complete. Upon completion it will return the
30
+ entire set of transfer details received during the operation.
31
+
32
+
33
+ Combinations of settings for `AUTO_ACCEPT...` configuration variables allow
34
+ the scheme adapter user to decide which mode of operation best suits their
35
+ use cases. i.e. the scheme adapter can be configured to "break" the three
36
+ stage transfer at these points in order to execute backend logic such as
37
+ party verification, quoted fees assessments etc...
38
+ tags:
39
+ - Transfers
40
+ requestBody:
41
+ description: Transfer request body
42
+ content:
43
+ application/json:
44
+ schema:
45
+ $ref: ../components/schemas/transferRequest.yaml
46
+ required: true
47
+ responses:
48
+ '200':
49
+ $ref: ../components/responses/transferSuccess.yaml
50
+ '400':
51
+ $ref: ../components/responses/transferBadRequest.yaml
52
+ '500':
53
+ $ref: ../components/responses/transferServerError.yaml
54
+ '504':
55
+ $ref: ../components/responses/transferTimeout.yaml
@@ -0,0 +1,58 @@
1
+ put:
2
+ summary: >-
3
+ Continues a transfer that has paused at the quote stage in order to accept
4
+ or reject payee party and/or quote
5
+ description: >
6
+ The HTTP request `PUT /transfers/{transferId}` is used to continue a
7
+ transfer initiated via the `POST /transfers` method that has halted after
8
+ party lookup and/or quotation stage.
9
+
10
+
11
+ The request body should contain either the "acceptParty" or "acceptQuote"
12
+ property set to `true` as required to continue the transfer.
13
+
14
+
15
+ See the description of the `POST /transfers` HTTP method for more
16
+ information on modes of transfer.
17
+ tags:
18
+ - Transfers
19
+ requestBody:
20
+ content:
21
+ application/json:
22
+ schema:
23
+ oneOf:
24
+ - $ref: ../components/schemas/transferContinuationAcceptParty.yaml
25
+ - $ref: ../components/schemas/transferContinuationAcceptQuote.yaml
26
+ parameters:
27
+ - $ref: ../components/parameters/transferId.yaml
28
+ responses:
29
+ '200':
30
+ $ref: ../components/responses/transferSuccess.yaml
31
+ '500':
32
+ $ref: ../components/responses/transferServerError.yaml
33
+ '504':
34
+ $ref: ../components/responses/transferTimeout.yaml
35
+ get:
36
+ summary: Retrieves information for a specific transfer
37
+ description: >-
38
+ The HTTP request `GET /transfers/{transferId}` is used to get information
39
+ regarding a transfer created or requested earlier. The `{transferId}` in the
40
+ URI should contain the `transferId` that was used for the creation of the
41
+ transfer.
42
+ tags:
43
+ - Transfers
44
+ parameters:
45
+ - $ref: ../components/parameters/transferId.yaml
46
+ responses:
47
+ '200':
48
+ description: Transfer information successfully retrieved
49
+ content:
50
+ application/json:
51
+ schema:
52
+ $ref: ../components/schemas/transferStatusResponse.yaml
53
+ '500':
54
+ description: An error occurred processing the transfer
55
+ content:
56
+ application/json:
57
+ schema:
58
+ $ref: ../components/schemas/errorResponse.yaml
@@ -0,0 +1,622 @@
1
+ /**************************************************************************
2
+ * (C) Copyright ModusBox Inc. 2019 - All rights reserved. *
3
+ * *
4
+ * This file is made available under the terms of the license agreement *
5
+ * specified in the corresponding source code repository. *
6
+ * *
7
+ * ORIGINAL AUTHOR: *
8
+ * James Bush - james.bush@modusbox.com *
9
+ * CONTRIBUTORS: *
10
+ * Steven Oderayi - steven.oderayi@modusbox.com *
11
+ **************************************************************************/
12
+
13
+ 'use strict';
14
+
15
+
16
+ const util = require('util');
17
+ const {
18
+ AccountsModel,
19
+ OutboundTransfersModel,
20
+ OutboundBulkTransfersModel,
21
+ OutboundRequestToPayTransferModel,
22
+ OutboundRequestToPayModel,
23
+ OutboundBulkQuotesModel,
24
+ PartiesModel,
25
+ QuotesModel,
26
+ TransfersModel,
27
+ AuthorizationsModel
28
+ } = require('../lib/model');
29
+
30
+
31
+ /**
32
+ * Error handling logic shared by outbound API handlers
33
+ */
34
+ const handleError = (method, err, ctx, stateField) => {
35
+ ctx.state.logger.log(`Error handling ${method}: ${util.inspect(err)}`);
36
+ ctx.response.status = err.httpStatusCode || 500;
37
+ ctx.response.body = {
38
+ message: err.message || 'Unspecified error',
39
+ [stateField]: err[stateField] || {},
40
+ statusCode: (err.httpStatusCode || 500).toString()
41
+ };
42
+ if(err[stateField]
43
+ && err[stateField].lastError
44
+ && err[stateField].lastError.mojaloopError
45
+ && err[stateField].lastError.mojaloopError.errorInformation
46
+ && err[stateField].lastError.mojaloopError.errorInformation.errorCode) {
47
+
48
+ // by default we set the statusCode property of the error body to be that of any model state lastError
49
+ // property containing a mojaloop API error structure. This means the caller does not have to inspect
50
+ // the structure of the response object in depth to ascertain an underlying mojaloop API error code.
51
+ const errorInformation = err[stateField].lastError.mojaloopError.errorInformation;
52
+ ctx.response.body.statusCode = errorInformation.errorCode;
53
+
54
+ // if we have been configured to use an error extensionList item as status code, look for it and use
55
+ // it if it is present...
56
+ if(ctx.state.conf.outboundErrorStatusCodeExtensionKey
57
+ && errorInformation.extensionList
58
+ && Array.isArray(errorInformation.extensionList.extension)) {
59
+
60
+ // search the extensionList array for a key that matches what we have been configured to look for...
61
+ // the first one will do - spec is a bit loose on duplicate keys...
62
+ const extensionItem = errorInformation.extensionList.extension.find(e => {
63
+ return e.key === ctx.state.conf.outboundErrorStatusCodeExtensionKey;
64
+ });
65
+
66
+ if(extensionItem) {
67
+ ctx.response.body.statusCode = extensionItem.value;
68
+ }
69
+ }
70
+ }
71
+ };
72
+
73
+ const handleTransferError = (method, err, ctx) =>
74
+ handleError(method, err, ctx, 'transferState');
75
+
76
+ const handleBulkTransferError = (method, err, ctx) =>
77
+ handleError(method, err, ctx, 'bulkTransferState');
78
+
79
+ const handleBulkQuoteError = (method, err, ctx) =>
80
+ handleError(method, err, ctx, 'bulkQuoteState');
81
+
82
+ const handleAccountsError = (method, err, ctx) =>
83
+ handleError(method, err, ctx, 'executionState');
84
+
85
+ const handleRequestToPayError = (method, err, ctx) =>
86
+ handleError(method, err, ctx, 'requestToPayState');
87
+
88
+ const handleRequestToPayTransferError = (method, err, ctx) =>
89
+ handleError(method, err, ctx, 'requestToPayTransferState');
90
+
91
+ const handleRequestPartiesInformationError = (method, err, ctx) =>
92
+ handleError(method, err, ctx, 'requestPartiesInformationState');
93
+
94
+ const handleRequestQuotesInformationError = (method, err, ctx) =>
95
+ handleError(method, err, ctx, 'requestQuotesInformationState');
96
+
97
+ const handleRequestSimpleTransfersInformationError = (method, err, ctx) =>
98
+ handleError(method, err, ctx, 'requestSimpleTransfersInformationState');
99
+
100
+ const handleRequestAuthorizationsInformationError = (method, err, ctx) =>
101
+ handleError(method, err, ctx, 'requestAuthorizationsInformationState');
102
+
103
+ /**
104
+ * Handler for outbound transfer request initiation
105
+ */
106
+ const postTransfers = async (ctx) => {
107
+ try {
108
+ // this requires a multi-stage sequence with the switch.
109
+ let transferRequest = {
110
+ ...ctx.request.body
111
+ };
112
+
113
+ // use the transfers model to execute asynchronous stages with the switch
114
+ const model = new OutboundTransfersModel({
115
+ ...ctx.state.conf,
116
+ cache: ctx.state.cache,
117
+ logger: ctx.state.logger,
118
+ wso2: ctx.state.wso2,
119
+ });
120
+
121
+ // initialize the transfer model and start it running
122
+ await model.initialize(transferRequest);
123
+ const response = await model.run();
124
+
125
+ // return the result
126
+ ctx.response.status = 200;
127
+ ctx.response.body = response;
128
+ }
129
+ catch(err) {
130
+ return handleTransferError('postTransfers', err, ctx);
131
+ }
132
+ };
133
+
134
+ /**
135
+ * Handler for outbound transfer request
136
+ */
137
+ const getTransfers = async (ctx) => {
138
+ try {
139
+ let transferRequest = {
140
+ ...ctx.request.body,
141
+ transferId: ctx.state.path.params.transferId,
142
+ currentState: 'getTransfer',
143
+ };
144
+
145
+ // use the transfers model to execute asynchronous stages with the switch
146
+ const model = new OutboundTransfersModel({
147
+ ...ctx.state.conf,
148
+ cache: ctx.state.cache,
149
+ logger: ctx.state.logger,
150
+ wso2: ctx.state.wso2,
151
+ });
152
+
153
+ // initialize the transfer model and start it running
154
+ await model.initialize(transferRequest);
155
+ const response = await model.run();
156
+
157
+ // return the result
158
+ ctx.response.status = 200;
159
+ ctx.response.body = response;
160
+ }
161
+ catch(err) {
162
+ return handleTransferError('getTransfers', err, ctx);
163
+ }
164
+ };
165
+
166
+ /**
167
+ * Handler for resuming outbound transfers in scenarios where two-step transfers are enabled
168
+ * by disabling the autoAcceptQuote SDK option
169
+ */
170
+ const putTransfers = async (ctx) => {
171
+ try {
172
+ // this requires a multi-stage sequence with the switch.
173
+ // use the transfers model to execute asynchronous stages with the switch
174
+ const model = new OutboundTransfersModel({
175
+ ...ctx.state.conf,
176
+ cache: ctx.state.cache,
177
+ logger: ctx.state.logger,
178
+ wso2: ctx.state.wso2,
179
+ });
180
+
181
+ // TODO: check the incoming body to reject party or quote when requested to do so
182
+
183
+ // load the transfer model from cache and start it running again
184
+ await model.load(ctx.state.path.params.transferId);
185
+
186
+ const response = await model.run();
187
+
188
+ // return the result
189
+ ctx.response.status = 200;
190
+ ctx.response.body = response;
191
+ }
192
+ catch(err) {
193
+ return handleTransferError('putTransfers', err, ctx);
194
+ }
195
+ };
196
+
197
+ /**
198
+ * Handler for outbound bulk transfer request
199
+ */
200
+ const postBulkTransfers = async (ctx) => {
201
+ try {
202
+ // this requires a multi-stage sequence with the switch.
203
+ let bulkTransferRequest = {
204
+ ...ctx.request.body
205
+ };
206
+
207
+ // use the bulk transfers model to execute asynchronous stages with the switch
208
+ const model = new OutboundBulkTransfersModel({
209
+ ...ctx.state.conf,
210
+ cache: ctx.state.cache,
211
+ logger: ctx.state.logger,
212
+ wso2: ctx.state.wso2,
213
+ });
214
+
215
+ await model.initialize(bulkTransferRequest);
216
+ const response = await model.run();
217
+
218
+ // return the result
219
+ ctx.response.status = 200;
220
+ ctx.response.body = response;
221
+ }
222
+ catch (err) {
223
+ return handleBulkTransferError('postBulkTransfers', err, ctx);
224
+ }
225
+ };
226
+
227
+ /**
228
+ * Handler for outbound bulk transfer request
229
+ */
230
+ const getBulkTransfers = async (ctx) => {
231
+ try {
232
+ const bulkTransferRequest = {
233
+ ...ctx.request.body,
234
+ bulkTransferId: ctx.state.path.params.bulkTransferId,
235
+ currentState: 'getBulkTransfer',
236
+ };
237
+
238
+ // use the bulk transfers model to execute asynchronous stages with the switch
239
+ const model = new OutboundBulkTransfersModel({
240
+ ...ctx.state.conf,
241
+ cache: ctx.state.cache,
242
+ logger: ctx.state.logger,
243
+ wso2: ctx.state.wso2,
244
+ });
245
+
246
+ await model.initialize(bulkTransferRequest);
247
+ const response = await model.getBulkTransfer();
248
+
249
+ // return the result
250
+ ctx.response.status = 200;
251
+ ctx.response.body = response;
252
+ }
253
+ catch (err) {
254
+ return handleBulkTransferError('getBulkTransfers', err, ctx);
255
+ }
256
+ };
257
+
258
+ /**
259
+ * Handler for outbound bulk quote request
260
+ */
261
+ const postBulkQuotes = async (ctx) => {
262
+ try {
263
+ let bulkQuoteRequest = {
264
+ ...ctx.request.body
265
+ };
266
+
267
+ // use the bulk quotes model to execute asynchronous request with the switch
268
+ const model = new OutboundBulkQuotesModel({
269
+ ...ctx.state.conf,
270
+ cache: ctx.state.cache,
271
+ logger: ctx.state.logger,
272
+ wso2: ctx.state.wso2,
273
+ });
274
+
275
+ await model.initialize(bulkQuoteRequest);
276
+ const response = await model.run();
277
+
278
+ // return the result
279
+ ctx.response.status = 200;
280
+ ctx.response.body = response;
281
+ }
282
+ catch (err) {
283
+ return handleBulkQuoteError('postBulkQuotes', err, ctx);
284
+ }
285
+ };
286
+
287
+ /**
288
+ * Handler for outbound bulk quote request
289
+ */
290
+ const getBulkQuoteById = async (ctx) => {
291
+ try {
292
+ const bulkQuoteRequest = {
293
+ ...ctx.request.body,
294
+ bulkQuoteId: ctx.state.path.params.bulkQuoteId,
295
+ currentState: 'getBulkQuote',
296
+ };
297
+
298
+ // use the bulk quotes model to execute asynchronous stages with the switch
299
+ const model = new OutboundBulkQuotesModel({
300
+ ...ctx.state.conf,
301
+ cache: ctx.state.cache,
302
+ logger: ctx.state.logger,
303
+ wso2: ctx.state.wso2,
304
+ });
305
+
306
+ await model.initialize(bulkQuoteRequest);
307
+ const response = await model.getBulkQuote();
308
+
309
+ // return the result
310
+ ctx.response.status = 200;
311
+ ctx.response.body = response;
312
+ }
313
+ catch (err) {
314
+ return handleBulkQuoteError('getBulkQuoteById', err, ctx);
315
+ }
316
+ };
317
+
318
+ /**
319
+ * Handler for outbound transfer request initiation
320
+ */
321
+ const postRequestToPayTransfer = async (ctx) => {
322
+ try {
323
+ // this requires a multi-stage sequence with the switch.
324
+ let requestToPayTransferRequest = {
325
+ ...ctx.request.body
326
+ };
327
+
328
+ // use the merchant transfers model to execute asynchronous stages with the switch
329
+ const model = new OutboundRequestToPayTransferModel({
330
+ ...ctx.state.conf,
331
+ cache: ctx.state.cache,
332
+ logger: ctx.state.logger,
333
+ wso2: ctx.state.wso2,
334
+ });
335
+
336
+ // initialize the transfer model and start it running
337
+ await model.initialize(requestToPayTransferRequest);
338
+ const response = await model.run();
339
+ // return the result
340
+ ctx.response.status = 200;
341
+ ctx.response.body = response;
342
+ }
343
+ catch (err) {
344
+ return handleRequestToPayTransferError('postRequestToPayTransfer', err, ctx);
345
+ }
346
+ };
347
+
348
+ /**
349
+ * Handler for resuming outbound transfers in scenarios where two-step transfers are enabled
350
+ * by disabling the autoAcceptQuote SDK option
351
+ */
352
+ const putRequestToPayTransfer = async (ctx) => {
353
+ try {
354
+ // this requires a multi-stage sequence with the switch.
355
+ // use the transfers model to execute asynchronous stages with the switch
356
+ const model = new OutboundRequestToPayTransferModel({
357
+ ...ctx.state.conf,
358
+ cache: ctx.state.cache,
359
+ logger: ctx.state.logger,
360
+ wso2: ctx.state.wso2,
361
+ });
362
+
363
+ // TODO: check the incoming body to reject party or quote when requested to do so
364
+ const data = ctx.request.body;
365
+ // load the transfer model from cache and start it running again
366
+ await model.load(ctx.state.path.params.requestToPayTransactionId);
367
+ let response;
368
+ if(data.acceptQuote === true || data.acceptOTP === true) {
369
+ response = await model.run();
370
+ } else {
371
+ response = await model.rejectRequestToPay();
372
+ }
373
+
374
+ // return the result
375
+ ctx.response.status = 200;
376
+ ctx.response.body = response;
377
+ }
378
+ catch(err) {
379
+ return handleTransferError('putRequestToPayTransfer', err, ctx);
380
+ }
381
+ };
382
+
383
+
384
+ /**
385
+ * Handler for outbound participants request initiation
386
+ */
387
+ const postAccounts = async (ctx) => {
388
+ try {
389
+ const model = new AccountsModel({
390
+ ...ctx.state.conf,
391
+ cache: ctx.state.cache,
392
+ logger: ctx.state.logger,
393
+ wso2: ctx.state.wso2,
394
+ });
395
+
396
+ const state = {
397
+ accounts: ctx.request.body,
398
+ };
399
+
400
+ // initialize the accounts model and run it
401
+ await model.initialize(state);
402
+ const response = await model.run();
403
+
404
+ // return the result
405
+ ctx.response.status = 200;
406
+ ctx.response.body = response;
407
+ }
408
+ catch(err) {
409
+ return handleAccountsError('postAccounts', err, ctx);
410
+ }
411
+ };
412
+
413
+ const postRequestToPay = async (ctx) => {
414
+ try {
415
+ // this requires a multi-stage sequence with the switch.
416
+ let requestToPayInboundRequest = {
417
+ ...ctx.request.body
418
+ };
419
+
420
+ // use the transfers model to execute asynchronous stages with the switch
421
+ const model = new OutboundRequestToPayModel({
422
+ ...ctx.state.conf,
423
+ cache: ctx.state.cache,
424
+ logger: ctx.state.logger,
425
+ wso2: ctx.state.wso2,
426
+ });
427
+
428
+ // initialize the transfer model and start it running
429
+ await model.initialize(requestToPayInboundRequest);
430
+ const response = await model.run();
431
+
432
+ // return the result
433
+ ctx.response.status = 200;
434
+ ctx.response.body = response;
435
+
436
+ } catch(err) {
437
+ return handleRequestToPayError('requestToPayInboundRequest', err, ctx);
438
+ }
439
+ };
440
+
441
+ const healthCheck = async (ctx) => {
442
+ ctx.response.status = 200;
443
+ ctx.response.body = '';
444
+ };
445
+
446
+ const getPartiesByTypeAndId = async (ctx) => {
447
+ const type = ctx.state.path.params.Type;
448
+ const id = ctx.state.path.params.ID;
449
+ const subId = ctx.state.path.params.SubId;
450
+
451
+ const args = { type, id, subId };
452
+
453
+ try {
454
+ // prepare config
455
+ const modelConfig = {
456
+ ...ctx.state.conf,
457
+ cache: ctx.state.cache,
458
+ logger: ctx.state.logger,
459
+ wso2Auth: ctx.state.wso2Auth,
460
+ };
461
+
462
+ const cacheKey = PartiesModel.generateKey(args);
463
+
464
+ // use the parties model to execute asynchronous stages with the switch
465
+ const model = await PartiesModel.create({}, cacheKey, modelConfig);
466
+
467
+ // run model's workflow
468
+ const response = await model.run(args);
469
+
470
+ // return the result
471
+ if (response.errorInformation) {
472
+ ctx.response.status = 404;
473
+ } else {
474
+ ctx.response.status = 200;
475
+ }
476
+ ctx.response.body = response;
477
+ } catch (err) {
478
+ return handleRequestPartiesInformationError('getPartiesByTypeAndId', err, ctx);
479
+ }
480
+ };
481
+
482
+ const postQuotes = async (ctx) => {
483
+ const quote = { ...ctx.request.body.quotesPostRequest };
484
+ const fspId = ctx.request.body.fspId;
485
+ const args = { quoteId: quote.quoteId, fspId, quote };
486
+
487
+ try {
488
+ // prepare config
489
+ const modelConfig = {
490
+ ...ctx.state.conf,
491
+ cache: ctx.state.cache,
492
+ logger: ctx.state.logger,
493
+ wso2Auth: ctx.state.wso2Auth,
494
+ };
495
+
496
+ const cacheKey = QuotesModel.generateKey(args);
497
+
498
+ // use the parties model to execute asynchronous stages with the switch
499
+ const model = await QuotesModel.create({}, cacheKey, modelConfig);
500
+
501
+ // run model's workflow
502
+ const response = await model.run(args);
503
+
504
+ // return the result
505
+ ctx.response.status = 200;
506
+ ctx.response.body = response;
507
+ } catch (err) {
508
+ return handleRequestQuotesInformationError('postQuotes', err, ctx);
509
+ }
510
+ };
511
+
512
+ const postSimpleTransfers = async (ctx) => {
513
+ const transfer = { ...ctx.request.body.transfersPostRequest };
514
+ const fspId = ctx.request.body.fspId;
515
+ const args = { transferId: transfer.transferId, fspId, transfer };
516
+
517
+ try {
518
+ // prepare config
519
+ const modelConfig = {
520
+ ...ctx.state.conf,
521
+ cache: ctx.state.cache,
522
+ logger: ctx.state.logger,
523
+ wso2Auth: ctx.state.wso2Auth,
524
+ };
525
+
526
+ const cacheKey = TransfersModel.generateKey(args);
527
+
528
+ // use the parties model to execute asynchronous stages with the switch
529
+ const model = await TransfersModel.create({}, cacheKey, modelConfig);
530
+
531
+ // run model's workflow
532
+ const response = await model.run(args);
533
+ // return the result
534
+ ctx.response.status = 200;
535
+ ctx.response.body = response;
536
+ } catch (err) {
537
+ return handleRequestSimpleTransfersInformationError('postSimpleTransfers', err, ctx);
538
+ }
539
+ };
540
+
541
+ const postAuthorizations = async (ctx) => {
542
+
543
+ const authorization = { ...ctx.request.body.authorizationsPostRequest };
544
+ const fspId = ctx.request.body.fspId;
545
+ const args = { transactionRequestId: authorization.transactionRequestId, fspId, authorization };
546
+
547
+ try {
548
+ // prepare config
549
+ const modelConfig = {
550
+ ...ctx.state.conf,
551
+ cache: ctx.state.cache,
552
+ logger: ctx.state.logger,
553
+ wso2Auth: ctx.state.wso2Auth,
554
+ };
555
+
556
+ const cacheKey = AuthorizationsModel.generateKey(args);
557
+
558
+ // use the authorizations model to execute asynchronous stages with the switch
559
+ const model = await AuthorizationsModel.create({}, cacheKey, modelConfig);
560
+
561
+ // run model's workflow
562
+ const response = await model.run(args);
563
+
564
+ // return the result
565
+ ctx.response.status = 200;
566
+ ctx.response.body = response;
567
+ } catch (err) {
568
+ return handleRequestAuthorizationsInformationError('postAuthorizations', err, ctx);
569
+ }
570
+ };
571
+
572
+ module.exports = {
573
+ '/': {
574
+ get: healthCheck
575
+ },
576
+ '/transfers': {
577
+ post: postTransfers
578
+ },
579
+ '/transfers/{transferId}': {
580
+ get: getTransfers,
581
+ put: putTransfers
582
+ },
583
+ '/bulkTransfers': {
584
+ post: postBulkTransfers
585
+ },
586
+ '/bulkTransfers/{bulkTransferId}': {
587
+ get: getBulkTransfers,
588
+ },
589
+ '/bulkQuotes': {
590
+ post: postBulkQuotes,
591
+ },
592
+ '/bulkQuotes/{bulkQuoteId}': {
593
+ get: getBulkQuoteById,
594
+ },
595
+ '/accounts': {
596
+ post: postAccounts
597
+ },
598
+ '/requestToPay': {
599
+ post: postRequestToPay
600
+ },
601
+ '/requestToPayTransfer': {
602
+ post: postRequestToPayTransfer
603
+ },
604
+ '/requestToPayTransfer/{requestToPayTransactionId}': {
605
+ put: putRequestToPayTransfer
606
+ },
607
+ '/parties/{Type}/{ID}': {
608
+ get: getPartiesByTypeAndId
609
+ },
610
+ '/parties/{Type}/{ID}/{SubId}': {
611
+ get: getPartiesByTypeAndId
612
+ },
613
+ '/quotes': {
614
+ post: postQuotes
615
+ },
616
+ '/simpleTransfers': {
617
+ post: postSimpleTransfers
618
+ },
619
+ '/authorizations': {
620
+ post: postAuthorizations
621
+ }
622
+ };