@unchainedshop/plugins 4.0.0-rc.15 → 4.0.0-rc.17

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 (302) hide show
  1. package/lib/accounts/google-oauth.d.ts +4 -0
  2. package/lib/accounts/google-oauth.d.ts.map +1 -0
  3. package/lib/accounts/google-oauth.js +145 -0
  4. package/lib/accounts/google-oauth.js.map +1 -0
  5. package/lib/accounts/linkedin-oauth.d.ts +4 -0
  6. package/lib/accounts/linkedin-oauth.d.ts.map +1 -0
  7. package/lib/accounts/linkedin-oauth.js +82 -0
  8. package/lib/accounts/linkedin-oauth.js.map +1 -0
  9. package/lib/delivery/send-message.js.map +1 -1
  10. package/lib/enrollments/licensed.js +15 -2
  11. package/lib/enrollments/licensed.js.map +1 -1
  12. package/lib/files/gridfs/adapter.js +1 -1
  13. package/lib/files/gridfs/adapter.js.map +1 -1
  14. package/lib/files/gridfs/gridfs-adapter.d.ts +3 -0
  15. package/lib/files/gridfs/gridfs-adapter.d.ts.map +1 -0
  16. package/lib/files/gridfs/gridfs-adapter.js +97 -0
  17. package/lib/files/gridfs/gridfs-adapter.js.map +1 -0
  18. package/lib/files/gridfs/gridfs-webhook.d.ts +11 -0
  19. package/lib/files/gridfs/gridfs-webhook.d.ts.map +1 -0
  20. package/lib/files/gridfs/gridfs-webhook.js +84 -0
  21. package/lib/files/gridfs/gridfs-webhook.js.map +1 -0
  22. package/lib/files/gridfs/handler-express.d.ts.map +1 -1
  23. package/lib/files/gridfs/handler-express.js +17 -24
  24. package/lib/files/gridfs/handler-express.js.map +1 -1
  25. package/lib/files/gridfs/handler-fastify.d.ts.map +1 -1
  26. package/lib/files/gridfs/handler-fastify.js +45 -11
  27. package/lib/files/gridfs/handler-fastify.js.map +1 -1
  28. package/lib/files/gridfs/module.d.ts +2 -2
  29. package/lib/files/minio/handler-express.d.ts.map +1 -1
  30. package/lib/files/minio/handler-express.js +4 -7
  31. package/lib/files/minio/handler-express.js.map +1 -1
  32. package/lib/files/minio/handler-fastify.js +2 -2
  33. package/lib/files/minio/handler-fastify.js.map +1 -1
  34. package/lib/files/minio/index.d.ts +1 -1
  35. package/lib/files/minio/index.d.ts.map +1 -1
  36. package/lib/files/minio/index.js +3 -3
  37. package/lib/files/minio/index.js.map +1 -1
  38. package/lib/files/minio/minio-adapter.d.ts +6 -0
  39. package/lib/files/minio/minio-adapter.d.ts.map +1 -0
  40. package/lib/files/minio/minio-adapter.js +181 -0
  41. package/lib/files/minio/minio-adapter.js.map +1 -0
  42. package/lib/files/minio/minio-webhook.d.ts +2 -0
  43. package/lib/files/minio/minio-webhook.d.ts.map +1 -0
  44. package/lib/files/minio/minio-webhook.js +33 -0
  45. package/lib/files/minio/minio-webhook.js.map +1 -0
  46. package/lib/filters/local-search.js +1 -1
  47. package/lib/filters/local-search.js.map +1 -1
  48. package/lib/payment/apple-iap/adapter.js +12 -10
  49. package/lib/payment/apple-iap/adapter.js.map +1 -1
  50. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +1 -1
  51. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts.map +1 -1
  52. package/lib/payment/apple-iap/handler-express.d.ts.map +1 -1
  53. package/lib/payment/apple-iap/handler-express.js +14 -10
  54. package/lib/payment/apple-iap/handler-express.js.map +1 -1
  55. package/lib/payment/apple-iap/handler-fastify.d.ts.map +1 -1
  56. package/lib/payment/apple-iap/handler-fastify.js +15 -8
  57. package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
  58. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
  59. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +1 -0
  60. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +17 -0
  61. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
  62. package/lib/payment/apple-iap/module.d.ts +4 -4
  63. package/lib/payment/apple-iap/module.d.ts.map +1 -1
  64. package/lib/payment/apple-iap/module.js +4 -2
  65. package/lib/payment/apple-iap/module.js.map +1 -1
  66. package/lib/payment/braintree.js +3 -1
  67. package/lib/payment/braintree.js.map +1 -1
  68. package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
  69. package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
  70. package/lib/payment/cryptopay/derive-btc-address.d.ts.map +1 -1
  71. package/lib/payment/cryptopay/derive-btc-address.js +2 -3
  72. package/lib/payment/cryptopay/derive-btc-address.js.map +1 -1
  73. package/lib/payment/cryptopay/derive-eth-address.d.ts.map +1 -1
  74. package/lib/payment/cryptopay/derive-eth-address.js +2 -0
  75. package/lib/payment/cryptopay/derive-eth-address.js.map +1 -1
  76. package/lib/payment/cryptopay/handle-webhook.js +2 -2
  77. package/lib/payment/cryptopay/handle-webhook.js.map +1 -1
  78. package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
  79. package/lib/payment/cryptopay/handler-express.js +4 -7
  80. package/lib/payment/cryptopay/handler-express.js.map +1 -1
  81. package/lib/payment/cryptopay/handler-fastify.js +1 -1
  82. package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
  83. package/lib/payment/cryptopay/middleware.d.ts +2 -0
  84. package/lib/payment/cryptopay/middleware.d.ts.map +1 -0
  85. package/lib/payment/cryptopay/middleware.js +75 -0
  86. package/lib/payment/cryptopay/middleware.js.map +1 -0
  87. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +25 -0
  88. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +1 -0
  89. package/lib/payment/cryptopay/module/configureCryptopayModule.js +75 -0
  90. package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +1 -0
  91. package/lib/payment/cryptopay/module.d.ts +2 -2
  92. package/lib/payment/cryptopay/module.d.ts.map +1 -1
  93. package/lib/payment/cryptopay/module.js +4 -4
  94. package/lib/payment/cryptopay/module.js.map +1 -1
  95. package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
  96. package/lib/payment/cryptopay/plugin.js +18 -4
  97. package/lib/payment/cryptopay/plugin.js.map +1 -1
  98. package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -1
  99. package/lib/payment/datatrans-v2/handler-express.js +13 -11
  100. package/lib/payment/datatrans-v2/handler-express.js.map +1 -1
  101. package/lib/payment/datatrans-v2/handler-fastify.d.ts.map +1 -1
  102. package/lib/payment/datatrans-v2/handler-fastify.js +11 -5
  103. package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -1
  104. package/lib/payment/datatrans-v2/index.js +63 -37
  105. package/lib/payment/datatrans-v2/index.js.map +1 -1
  106. package/lib/payment/datatrans-v2/middleware.d.ts +2 -0
  107. package/lib/payment/datatrans-v2/middleware.d.ts.map +1 -0
  108. package/lib/payment/datatrans-v2/middleware.js +68 -0
  109. package/lib/payment/datatrans-v2/middleware.js.map +1 -0
  110. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +1 -1
  111. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts.map +1 -1
  112. package/lib/payment/paypal-checkout.js +4 -2
  113. package/lib/payment/paypal-checkout.js.map +1 -1
  114. package/lib/payment/payrexx/api/index.d.ts +1 -1
  115. package/lib/payment/payrexx/api/index.d.ts.map +1 -1
  116. package/lib/payment/payrexx/api/makeFetcher.d.ts +1 -1
  117. package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
  118. package/lib/payment/payrexx/api/makeFetcher.js +1 -1
  119. package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
  120. package/lib/payment/payrexx/handler-express.d.ts.map +1 -1
  121. package/lib/payment/payrexx/handler-express.js +15 -15
  122. package/lib/payment/payrexx/handler-express.js.map +1 -1
  123. package/lib/payment/payrexx/handler-fastify.js +23 -15
  124. package/lib/payment/payrexx/handler-fastify.js.map +1 -1
  125. package/lib/payment/payrexx/index.js +21 -15
  126. package/lib/payment/payrexx/index.js.map +1 -1
  127. package/lib/payment/payrexx/middleware.d.ts +2 -0
  128. package/lib/payment/payrexx/middleware.d.ts.map +1 -0
  129. package/lib/payment/payrexx/middleware.js +86 -0
  130. package/lib/payment/payrexx/middleware.js.map +1 -0
  131. package/lib/payment/postfinance-checkout/handler-express.js +7 -8
  132. package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
  133. package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -1
  134. package/lib/payment/postfinance-checkout/handler-fastify.js +6 -4
  135. package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
  136. package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
  137. package/lib/payment/postfinance-checkout/index.js +20 -7
  138. package/lib/payment/postfinance-checkout/index.js.map +1 -1
  139. package/lib/payment/postfinance-checkout/middleware.d.ts +2 -0
  140. package/lib/payment/postfinance-checkout/middleware.d.ts.map +1 -0
  141. package/lib/payment/postfinance-checkout/middleware.js +38 -0
  142. package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
  143. package/lib/payment/saferpay/adapter.d.ts.map +1 -1
  144. package/lib/payment/saferpay/adapter.js +9 -0
  145. package/lib/payment/saferpay/adapter.js.map +1 -1
  146. package/lib/payment/saferpay/handler-express.d.ts.map +1 -1
  147. package/lib/payment/saferpay/handler-express.js +10 -8
  148. package/lib/payment/saferpay/handler-express.js.map +1 -1
  149. package/lib/payment/saferpay/handler-fastify.d.ts.map +1 -1
  150. package/lib/payment/saferpay/handler-fastify.js +11 -5
  151. package/lib/payment/saferpay/handler-fastify.js.map +1 -1
  152. package/lib/payment/saferpay/middleware.d.ts +2 -0
  153. package/lib/payment/saferpay/middleware.d.ts.map +1 -0
  154. package/lib/payment/saferpay/middleware.js +57 -0
  155. package/lib/payment/saferpay/middleware.js.map +1 -0
  156. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +10 -0
  157. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +1 -0
  158. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +24 -0
  159. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +1 -0
  160. package/lib/payment/saferpay/module.d.ts +2 -2
  161. package/lib/payment/stripe/handler-express.js +25 -17
  162. package/lib/payment/stripe/handler-express.js.map +1 -1
  163. package/lib/payment/stripe/handler-fastify.d.ts.map +1 -1
  164. package/lib/payment/stripe/handler-fastify.js +33 -12
  165. package/lib/payment/stripe/handler-fastify.js.map +1 -1
  166. package/lib/payment/stripe/index.js +19 -13
  167. package/lib/payment/stripe/index.js.map +1 -1
  168. package/lib/payment/stripe/middleware.d.ts +6 -0
  169. package/lib/payment/stripe/middleware.d.ts.map +1 -0
  170. package/lib/payment/stripe/middleware.js +114 -0
  171. package/lib/payment/stripe/middleware.js.map +1 -0
  172. package/lib/payment/stripe/stripe.d.ts +2 -2
  173. package/lib/payment/stripe/stripe.d.ts.map +1 -1
  174. package/lib/payment/stripe/stripe.js +14 -11
  175. package/lib/payment/stripe/stripe.js.map +1 -1
  176. package/lib/plugins-index.d.ts +48 -0
  177. package/lib/plugins-index.d.ts.map +1 -0
  178. package/lib/plugins-index.js +107 -0
  179. package/lib/plugins-index.js.map +1 -0
  180. package/lib/presets/all.d.ts +5 -5
  181. package/lib/presets/all.d.ts.map +1 -1
  182. package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
  183. package/lib/pricing/delivery-swiss-tax.js +13 -11
  184. package/lib/pricing/delivery-swiss-tax.js.map +1 -1
  185. package/lib/pricing/order-discount.d.ts.map +1 -1
  186. package/lib/pricing/order-discount.js +5 -3
  187. package/lib/pricing/order-discount.js.map +1 -1
  188. package/lib/pricing/order-round.d.ts.map +1 -1
  189. package/lib/pricing/order-round.js +4 -3
  190. package/lib/pricing/order-round.js.map +1 -1
  191. package/lib/pricing/product-catalog-price.js +4 -4
  192. package/lib/pricing/product-catalog-price.js.map +1 -1
  193. package/lib/pricing/product-price-rateconversion.js +3 -3
  194. package/lib/pricing/product-price-rateconversion.js.map +1 -1
  195. package/lib/pricing/product-swiss-tax.d.ts +1 -4
  196. package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
  197. package/lib/pricing/product-swiss-tax.js +9 -15
  198. package/lib/pricing/product-swiss-tax.js.map +1 -1
  199. package/lib/pricing/tax/ch.d.ts +6 -0
  200. package/lib/pricing/tax/ch.d.ts.map +1 -1
  201. package/lib/pricing/tax/ch.js +10 -0
  202. package/lib/pricing/tax/ch.js.map +1 -1
  203. package/lib/warehousing/eth-minter.js +23 -11
  204. package/lib/warehousing/eth-minter.js.map +1 -1
  205. package/lib/worker/BaseWorker.d.ts +30 -0
  206. package/lib/worker/BaseWorker.d.ts.map +1 -0
  207. package/lib/worker/BaseWorker.js +79 -0
  208. package/lib/worker/BaseWorker.js.map +1 -0
  209. package/lib/worker/EventListenerWorker.d.ts +6 -0
  210. package/lib/worker/EventListenerWorker.d.ts.map +1 -0
  211. package/lib/worker/EventListenerWorker.js +46 -0
  212. package/lib/worker/EventListenerWorker.js.map +1 -0
  213. package/lib/worker/FailedRescheduler.d.ts +15 -0
  214. package/lib/worker/FailedRescheduler.d.ts.map +1 -0
  215. package/lib/worker/FailedRescheduler.js +45 -0
  216. package/lib/worker/FailedRescheduler.js.map +1 -0
  217. package/lib/worker/IntervalWorker.d.ts +10 -0
  218. package/lib/worker/IntervalWorker.d.ts.map +1 -0
  219. package/lib/worker/IntervalWorker.js +37 -0
  220. package/lib/worker/IntervalWorker.js.map +1 -0
  221. package/lib/worker/bulk-import.d.ts +1 -1
  222. package/lib/worker/bulk-import.d.ts.map +1 -1
  223. package/lib/worker/bulk-import.js +11 -33
  224. package/lib/worker/bulk-import.js.map +1 -1
  225. package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
  226. package/lib/worker/enrollment-order-generator.js +7 -49
  227. package/lib/worker/enrollment-order-generator.js.map +1 -1
  228. package/lib/worker/error-notifications.js +1 -1
  229. package/lib/worker/error-notifications.js.map +1 -1
  230. package/lib/worker/export-token.d.ts.map +1 -1
  231. package/lib/worker/export-token.js +0 -1
  232. package/lib/worker/export-token.js.map +1 -1
  233. package/lib/worker/message.d.ts +1 -1
  234. package/lib/worker/message.d.ts.map +1 -1
  235. package/lib/worker/message.js +4 -2
  236. package/lib/worker/message.js.map +1 -1
  237. package/lib/worker/sms.d.ts +2 -0
  238. package/lib/worker/sms.d.ts.map +1 -0
  239. package/lib/worker/sms.js +73 -0
  240. package/lib/worker/sms.js.map +1 -0
  241. package/lib/worker/twilio.js +4 -0
  242. package/lib/worker/twilio.js.map +1 -1
  243. package/package.json +15 -17
  244. package/src/delivery/send-message.ts +1 -1
  245. package/src/enrollments/licensed.ts +15 -2
  246. package/src/files/gridfs/adapter.ts +1 -1
  247. package/src/files/gridfs/handler-express.ts +19 -24
  248. package/src/files/gridfs/handler-fastify.ts +48 -12
  249. package/src/files/minio/handler-express.ts +4 -7
  250. package/src/files/minio/handler-fastify.ts +2 -2
  251. package/src/files/minio/index.ts +12 -12
  252. package/src/filters/local-search.ts +1 -1
  253. package/src/payment/apple-iap/adapter.ts +12 -14
  254. package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +1 -1
  255. package/src/payment/apple-iap/handler-express.ts +17 -11
  256. package/src/payment/apple-iap/handler-fastify.ts +19 -9
  257. package/src/payment/apple-iap/module.ts +9 -4
  258. package/src/payment/braintree.ts +4 -1
  259. package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -1
  260. package/src/payment/cryptopay/derive-btc-address.ts +1 -3
  261. package/src/payment/cryptopay/derive-eth-address.ts +2 -0
  262. package/src/payment/cryptopay/handle-webhook.ts +6 -6
  263. package/src/payment/cryptopay/handler-express.ts +4 -7
  264. package/src/payment/cryptopay/handler-fastify.ts +1 -1
  265. package/src/payment/cryptopay/module.ts +8 -5
  266. package/src/payment/cryptopay/plugin.ts +21 -4
  267. package/src/payment/datatrans-v2/handler-express.ts +17 -12
  268. package/src/payment/datatrans-v2/handler-fastify.ts +15 -6
  269. package/src/payment/datatrans-v2/index.ts +82 -50
  270. package/src/payment/paypal-checkout.ts +4 -2
  271. package/src/payment/payrexx/api/index.ts +1 -1
  272. package/src/payment/payrexx/api/makeFetcher.ts +2 -2
  273. package/src/payment/payrexx/handler-express.ts +24 -32
  274. package/src/payment/payrexx/handler-fastify.ts +33 -33
  275. package/src/payment/payrexx/index.ts +26 -16
  276. package/src/payment/postfinance-checkout/handler-express.ts +8 -8
  277. package/src/payment/postfinance-checkout/handler-fastify.ts +7 -4
  278. package/src/payment/postfinance-checkout/index.ts +20 -8
  279. package/src/payment/saferpay/adapter.ts +14 -2
  280. package/src/payment/saferpay/handler-express.ts +14 -13
  281. package/src/payment/saferpay/handler-fastify.ts +14 -9
  282. package/src/payment/stripe/handler-express.ts +33 -33
  283. package/src/payment/stripe/handler-fastify.ts +40 -27
  284. package/src/payment/stripe/index.ts +17 -13
  285. package/src/payment/stripe/stripe.ts +17 -12
  286. package/src/pricing/delivery-swiss-tax.ts +11 -19
  287. package/src/pricing/order-discount.ts +6 -4
  288. package/src/pricing/order-round.ts +5 -4
  289. package/src/pricing/product-catalog-price.ts +4 -4
  290. package/src/pricing/product-price-rateconversion.ts +3 -3
  291. package/src/pricing/product-swiss-tax.test.ts +1 -86
  292. package/src/pricing/product-swiss-tax.ts +11 -24
  293. package/src/pricing/tax/ch.test.ts +86 -1
  294. package/src/pricing/tax/ch.ts +23 -0
  295. package/src/warehousing/eth-minter.ts +30 -11
  296. package/src/worker/budgetsms.ts +1 -1
  297. package/src/worker/bulk-import.ts +12 -53
  298. package/src/worker/enrollment-order-generator.ts +14 -72
  299. package/src/worker/error-notifications.ts +2 -2
  300. package/src/worker/export-token.ts +0 -1
  301. package/src/worker/message.ts +5 -3
  302. package/src/worker/twilio.ts +10 -3
@@ -1,7 +1,7 @@
1
1
  import { Context } from '@unchainedshop/api';
2
2
  import { createLogger } from '@unchainedshop/logger';
3
3
 
4
- const logger = createLogger('unchained:core-payment:payrexx:handler');
4
+ const logger = createLogger('unchained:payrexx:handler');
5
5
 
6
6
  export const payrexxHandler = async (request, response) => {
7
7
  const resolvedContext = request.unchainedContext as Context;
@@ -13,26 +13,20 @@ export const payrexxHandler = async (request, response) => {
13
13
  logger.info(`unhandled event type`, {
14
14
  type: Object.keys(request.body).join(','),
15
15
  });
16
- response.writeHead(200);
17
- response.end(
18
- JSON.stringify({
19
- ignored: true,
20
- message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
21
- }),
22
- );
16
+ response.status(200).send({
17
+ ignored: true,
18
+ message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
19
+ });
23
20
  return;
24
21
  }
25
22
  if (transaction.referenceId === '__IGNORE_WEBHOOK__' || transaction.status === 'waiting') {
26
23
  // Ignore confirmed transactions, because those hooks are generated through calling the confirm()
27
24
  // method in the payment adapter and could lead to double bookings.
28
25
  logger.info(`unhandled transaction state: ${transaction.status}`);
29
- response.writeHead(200);
30
- response.end(
31
- JSON.stringify({
32
- ignored: true,
33
- message: `Unhandled transaction state: ${transaction.status}`,
34
- }),
35
- );
26
+ response.status(200).send({
27
+ ignored: true,
28
+ message: `Unhandled transaction state: ${transaction.status}`,
29
+ });
36
30
  return;
37
31
  }
38
32
 
@@ -53,14 +47,11 @@ export const payrexxHandler = async (request, response) => {
53
47
  paymentProviderId,
54
48
  userId,
55
49
  });
56
- response.writeHead(200);
57
- response.end(
58
- JSON.stringify({
59
- message: 'registration successful',
60
- paymentProviderId,
61
- userId,
62
- }),
63
- );
50
+ response.status(200).send({
51
+ message: 'registration successful',
52
+ paymentProviderId,
53
+ userId,
54
+ });
64
55
  } else {
65
56
  const { referenceId: orderPaymentId, invoice } = transaction;
66
57
  logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
@@ -79,23 +70,24 @@ export const payrexxHandler = async (request, response) => {
79
70
  gatewayId: invoice.paymentRequestId,
80
71
  },
81
72
  });
73
+ if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
74
+
82
75
  logger.info(`checkout successful`, {
83
76
  orderPaymentId,
84
77
  orderId: order._id,
85
78
  });
86
- response.writeHead(200);
87
- response.end(
88
- JSON.stringify({
89
- message: 'checkout successful',
90
- orderId: order._id,
91
- }),
92
- );
79
+ response.status(200).send({
80
+ message: 'checkout successful',
81
+ orderId: order._id,
82
+ });
93
83
  }
94
84
  } catch (error) {
95
85
  logger.error(error, {
96
86
  transactionId: transaction.id,
97
87
  });
98
- response.writeHead(500);
99
- response.end(error.message);
88
+ response.status(500).send({
89
+ message: error.message,
90
+ name: error.name,
91
+ });
100
92
  }
101
93
  };
@@ -2,42 +2,39 @@ import { Context } from '@unchainedshop/api';
2
2
  import { createLogger } from '@unchainedshop/logger';
3
3
  import { FastifyRequest, RouteHandlerMethod } from 'fastify';
4
4
 
5
- const logger = createLogger('unchained:core-payment:payrexx:handler');
5
+ const logger = createLogger('unchained:payrexx:handler');
6
6
 
7
7
  export const payrexxHandler: RouteHandlerMethod = async (
8
8
  request: FastifyRequest & {
9
9
  unchainedContext: Context;
10
- },
10
+ } & { body: Record<string, any> },
11
11
  reply,
12
12
  ) => {
13
13
  const resolvedContext = request.unchainedContext as Context;
14
14
  const { modules, services } = resolvedContext;
15
15
 
16
- const { transaction } = request.body as Record<string, any>;
17
-
16
+ const { transaction } = request.body;
18
17
  if (!transaction) {
19
18
  logger.info(`unhandled event type`, {
20
19
  type: Object.keys(request.body).join(','),
21
20
  });
22
21
  reply.status(200);
23
- return reply.send(
24
- JSON.stringify({
25
- ignored: true,
26
- message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
27
- }),
28
- );
22
+ return reply.send({
23
+ success: false,
24
+ ignored: true,
25
+ message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
26
+ });
29
27
  }
30
28
  if (transaction.referenceId === '__IGNORE_WEBHOOK__' || transaction.status === 'waiting') {
31
29
  // Ignore confirmed transactions, because those hooks are generated through calling the confirm()
32
30
  // method in the payment adapter and could lead to double bookings.
33
31
  logger.info(`unhandled transaction state: ${transaction.status}`);
34
32
  reply.status(200);
35
- return reply.send(
36
- JSON.stringify({
37
- ignored: true,
38
- message: `Unhandled transaction state: ${transaction.status}`,
39
- }),
40
- );
33
+ return reply.send({
34
+ success: false,
35
+ ignored: true,
36
+ message: `Unhandled transaction state: ${transaction.status}`,
37
+ });
41
38
  }
42
39
 
43
40
  logger.info(`Processing event`, {
@@ -58,19 +55,14 @@ export const payrexxHandler: RouteHandlerMethod = async (
58
55
  userId,
59
56
  });
60
57
  reply.status(200);
61
- return reply.send(
62
- JSON.stringify({
63
- message: 'registration successful',
64
- paymentProviderId,
65
- userId,
66
- }),
67
- );
58
+ return reply.send({
59
+ success: true,
60
+ paymentProviderId,
61
+ userId,
62
+ });
68
63
  } else {
69
64
  const { referenceId: orderPaymentId, invoice } = transaction;
70
65
  logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
71
- await modules.orders.payments.logEvent(orderPaymentId, {
72
- transactionId: transaction.id,
73
- });
74
66
  const orderPayment = await modules.orders.payments.findOrderPayment({
75
67
  orderPaymentId,
76
68
  });
@@ -78,28 +70,36 @@ export const payrexxHandler: RouteHandlerMethod = async (
78
70
  throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
79
71
  }
80
72
 
73
+ await modules.orders.payments.logEvent(orderPaymentId, {
74
+ transactionId: transaction.id,
75
+ });
76
+
81
77
  const order = await services.orders.checkoutOrder(orderPayment.orderId, {
82
78
  paymentContext: {
83
79
  gatewayId: invoice.paymentRequestId,
84
80
  },
85
81
  });
82
+ if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
83
+
86
84
  logger.info(`checkout successful`, {
87
85
  orderPaymentId,
88
86
  orderId: order._id,
89
87
  });
90
88
  reply.status(200);
91
- return reply.send(
92
- JSON.stringify({
93
- message: 'checkout successful',
94
- orderId: order._id,
95
- }),
96
- );
89
+ return reply.send({
90
+ success: true,
91
+ orderId: order._id,
92
+ });
97
93
  }
98
94
  } catch (error) {
99
95
  logger.error(error, {
100
96
  transactionId: transaction.id,
101
97
  });
102
98
  reply.status(500);
103
- return reply.send(error.message);
99
+ return reply.send({
100
+ success: false,
101
+ message: error.message,
102
+ name: error.name,
103
+ });
104
104
  }
105
105
  };
@@ -9,7 +9,7 @@ import {
9
9
  PaymentError,
10
10
  } from '@unchainedshop/core';
11
11
 
12
- const logger = createLogger('unchained:core-payment:payrexx');
12
+ const logger = createLogger('unchained:payrexx');
13
13
 
14
14
  const Payrexx: IPaymentAdapter = {
15
15
  ...PaymentAdapter,
@@ -25,11 +25,7 @@ const Payrexx: IPaymentAdapter = {
25
25
  actions: (config, context) => {
26
26
  const { modules } = context;
27
27
 
28
- const getInstance = () => {
29
- return config.find((c) => c.key === 'instance')?.value;
30
- };
31
-
32
- const api = createPayrexxAPI(getInstance(), process.env.PAYREXX_SECRET);
28
+ const instance = config.find((c) => c.key === 'instance')?.value;
33
29
 
34
30
  const adapterActions = {
35
31
  ...PaymentAdapter.actions(config, context),
@@ -38,7 +34,7 @@ const Payrexx: IPaymentAdapter = {
38
34
  if (!process.env.PAYREXX_SECRET) {
39
35
  return PaymentError.INCOMPLETE_CONFIGURATION;
40
36
  }
41
- if (!getInstance()) {
37
+ if (!instance) {
42
38
  return PaymentError.INCOMPLETE_CONFIGURATION;
43
39
  }
44
40
  return null;
@@ -55,6 +51,11 @@ const Payrexx: IPaymentAdapter = {
55
51
 
56
52
  sign: async (transactionContext = {}) => {
57
53
  const { orderPayment, userId, order } = context;
54
+
55
+ if (!order) throw new Error('No order in context, can only sign with order context');
56
+
57
+ const api = createPayrexxAPI(instance!, process.env.PAYREXX_SECRET!);
58
+
58
59
  if (orderPayment) {
59
60
  // Order Checkout signing (One-time payment)
60
61
  const pricing = OrderPricingSheet({
@@ -70,7 +71,10 @@ const Payrexx: IPaymentAdapter = {
70
71
  }
71
72
 
72
73
  // Payment Credential Registration signing
73
- const user = await modules.users.findUserById(userId);
74
+
75
+ const user = userId && (await modules.users.findUserById(userId));
76
+ if (!user) throw new Error('User not found, can only sign registrations with user context');
77
+
74
78
  const emailAddress = modules.users.primaryEmail(user)?.address;
75
79
  const gateway = await api.createGateway(
76
80
  mapUserToGatewayObject({
@@ -107,11 +111,13 @@ const Payrexx: IPaymentAdapter = {
107
111
 
108
112
  async confirm() {
109
113
  const { orderPayment } = context;
110
- const { transactionId } = orderPayment;
111
114
 
112
- if (!transactionId) {
115
+ if (!orderPayment?.transactionId) {
113
116
  return false;
114
117
  }
118
+ const { transactionId } = orderPayment;
119
+
120
+ const api = createPayrexxAPI(instance!, process.env.PAYREXX_SECRET!);
115
121
 
116
122
  const gatewayObject = await api.getGateway(transactionId);
117
123
 
@@ -140,10 +146,12 @@ const Payrexx: IPaymentAdapter = {
140
146
 
141
147
  async cancel() {
142
148
  const { orderPayment } = context;
143
- const { transactionId } = orderPayment;
144
- if (!transactionId) {
149
+ if (!orderPayment?.transactionId) {
145
150
  return false;
146
151
  }
152
+ const { transactionId } = orderPayment;
153
+
154
+ const api = createPayrexxAPI(instance!, process.env.PAYREXX_SECRET!);
147
155
 
148
156
  const gatewayObject = await api.getGateway(transactionId);
149
157
 
@@ -170,10 +178,12 @@ const Payrexx: IPaymentAdapter = {
170
178
  throw new Error('You have to provide gatewayId or paymentCredentials');
171
179
  }
172
180
 
173
- const { order } = context;
174
- const orderPayment = await modules.orders.payments.findOrderPayment({
175
- orderPaymentId: order.paymentId,
176
- });
181
+ const { order, orderPayment } = context;
182
+
183
+ if (!order) throw new Error('No order in context, can only charge with order context');
184
+ if (!orderPayment) throw new Error('Order payment not found');
185
+
186
+ const api = createPayrexxAPI(instance!, process.env.PAYREXX_SECRET!);
177
187
 
178
188
  const gatewayObject = await api.getGateway(gatewayId);
179
189
 
@@ -3,7 +3,7 @@ import { createLogger } from '@unchainedshop/logger';
3
3
  import { WebhookData } from './types.js';
4
4
  import { getTransaction, getTransactionCompletion } from './api.js';
5
5
 
6
- const logger = createLogger('unchained:core-payment:postfinance-checkout:handler');
6
+ const logger = createLogger('unchained:postfinance-checkout:handler');
7
7
 
8
8
  export const postfinanceCheckoutHandler = async (req, res) => {
9
9
  const context = req.unchainedContext as Context;
@@ -26,19 +26,19 @@ export const postfinanceCheckoutHandler = async (req, res) => {
26
26
  transactionId: transactionCompletion.linkedTransaction,
27
27
  },
28
28
  });
29
+
30
+ if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
31
+
29
32
  logger.info(
30
- `Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
33
+ `Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData?.orderPaymentId} as paid`,
31
34
  );
32
- res.writeHead(200);
33
- res.end(`Order marked as paid: ${order.orderNumber}`);
35
+ res.status(200).send(`Order marked as paid: ${order.orderNumber}`);
34
36
  } catch (e) {
35
37
  logger.error(e);
36
- res.writeHead(500);
37
- res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
38
+ res.status(500).send({ name: e.name, code: e.code, message: e.message });
38
39
  }
39
40
  } else {
40
41
  logger.error(`Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
41
- res.writeHead(404);
42
- res.end();
42
+ res.status(404).end();
43
43
  }
44
44
  };
@@ -4,7 +4,7 @@ import { WebhookData } from './types.js';
4
4
  import { getTransaction, getTransactionCompletion } from './api.js';
5
5
  import { FastifyRequest, RouteHandlerMethod } from 'fastify';
6
6
 
7
- const logger = createLogger('unchained:core-payment:postfinance-checkout:handler');
7
+ const logger = createLogger('unchained:postfinance-checkout:handler');
8
8
 
9
9
  export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
10
10
  req: FastifyRequest & {
@@ -32,15 +32,18 @@ export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
32
32
  transactionId: transaction.id,
33
33
  },
34
34
  });
35
+
36
+ if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
37
+
35
38
  logger.info(
36
- `Transaction ${transaction.id} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
39
+ `Transaction ${transaction.id} marked order payment ID ${transaction.metaData?.orderPaymentId} as paid`,
37
40
  );
38
41
  reply.status(200);
39
- return reply.send(`Order marked as paid: ${order.orderNumber}`);
42
+ return reply.send({ success: true, orderNumber: order.orderNumber });
40
43
  } catch (e) {
41
44
  logger.error(e);
42
45
  reply.status(500);
43
- return reply.send({ name: e.name, code: e.code, message: e.message });
46
+ return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
44
47
  }
45
48
  } else {
46
49
  logger.error(`Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
@@ -40,7 +40,7 @@ const {
40
40
  PFCHECKOUT_FAILED_URL,
41
41
  } = process.env;
42
42
 
43
- const logger = createLogger('unchained:core-payment:postfinance-checkout');
43
+ const logger = createLogger('unchained:postfinance-checkout');
44
44
 
45
45
  const newError = ({ code, message }: { code: string; message: string }) => {
46
46
  const error = new Error(message);
@@ -104,6 +104,10 @@ const PostfinanceCheckout: IPaymentAdapter = {
104
104
  sign: async (transactionContext: any = {}) => {
105
105
  const { orderPayment, order } = context;
106
106
 
107
+ if (!order) throw new Error('No order in context, can only sign with order context');
108
+ if (!orderPayment)
109
+ throw new Error('No order payment in context, can only sign with order payment context');
110
+
107
111
  const { integrationMode = IntegrationModes.PaymentPage }: { integrationMode: IntegrationModes } =
108
112
  transactionContext;
109
113
  const completionMode = adapter.getCompletionMode();
@@ -146,7 +150,10 @@ const PostfinanceCheckout: IPaymentAdapter = {
146
150
  }
147
151
 
148
152
  const transactionId = await createTransaction(transaction);
149
- let location = null;
153
+
154
+ if (!transactionId) throw new Error('Could not create transaction');
155
+
156
+ let location: string | null = null;
150
157
  if (integrationMode === IntegrationModes.PaymentPage) {
151
158
  location = await getPaymentPageUrl(transactionId);
152
159
  } else if (integrationMode === IntegrationModes.Lightbox) {
@@ -185,7 +192,11 @@ const PostfinanceCheckout: IPaymentAdapter = {
185
192
  });
186
193
  }
187
194
 
188
- const isPaid = await orderIsPaid(context.order, transaction);
195
+ const { order, orderPayment } = context;
196
+ if (!orderPayment) throw new Error('No order payment in context, cannot charge payment');
197
+ if (!order) throw new Error('No order in context, can only sign with order context');
198
+
199
+ const isPaid = await orderIsPaid(order, transaction);
189
200
  if (!isPaid) {
190
201
  logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
191
202
  throw newError({
@@ -194,7 +205,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
194
205
  });
195
206
  }
196
207
 
197
- if (transaction.metaData.orderPaymentId !== context.orderPayment._id) {
208
+ if (transaction.metaData?.orderPaymentId !== orderPayment._id) {
198
209
  logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
199
210
  throw newError({
200
211
  code: `TRANSACTION_ALREADY_USED`,
@@ -216,10 +227,11 @@ const PostfinanceCheckout: IPaymentAdapter = {
216
227
 
217
228
  cancel: async () => {
218
229
  const { orderPayment, order } = context;
219
- const { transactionId } = orderPayment;
220
- if (!transactionId) {
230
+ if (!order) throw new Error('No order in context, can only cancel with order context');
231
+ if (!orderPayment?.transactionId) {
221
232
  return false;
222
233
  }
234
+ const { transactionId } = orderPayment;
223
235
  const transaction = await getTransaction(transactionId);
224
236
  const refund = transaction.state === TransactionState.FULFILL;
225
237
  const pricing = OrderPricingSheet({
@@ -237,10 +249,10 @@ const PostfinanceCheckout: IPaymentAdapter = {
237
249
 
238
250
  confirm: async () => {
239
251
  const { orderPayment } = context;
240
- const { transactionId } = orderPayment;
241
- if (!transactionId) {
252
+ if (!orderPayment?.transactionId) {
242
253
  return false;
243
254
  }
255
+ const { transactionId } = orderPayment;
244
256
  const transaction = await getTransaction(transactionId);
245
257
  if (transaction.state === TransactionState.AUTHORIZED) {
246
258
  return confirmDeferredTransaction(transactionId);
@@ -133,8 +133,8 @@ export const WordlineSaferpay: IPaymentAdapter = {
133
133
  saferpayTransactionId,
134
134
  );
135
135
 
136
- paymentPageInitInput.Notification.SuccessNotifyUrl = addTransactionId(
137
- paymentPageInitInput.Notification.SuccessNotifyUrl,
136
+ paymentPageInitInput.Notification!.SuccessNotifyUrl = addTransactionId(
137
+ paymentPageInitInput.Notification!.SuccessNotifyUrl,
138
138
  saferpayTransactionId,
139
139
  );
140
140
 
@@ -166,6 +166,10 @@ export const WordlineSaferpay: IPaymentAdapter = {
166
166
  mongodb.ObjectId.createFromHexString(transactionId),
167
167
  );
168
168
 
169
+ if (!saferpayTransaction?.token) {
170
+ throw new Error('No initialized transaction Token');
171
+ }
172
+
169
173
  const api = createSaferPayClient();
170
174
  const paymentPageAssert = await api.paymentPageAssert(orderPayment, {
171
175
  Token: saferpayTransaction.token,
@@ -205,6 +209,10 @@ export const WordlineSaferpay: IPaymentAdapter = {
205
209
  mongodb.ObjectId.createFromHexString(transactionId),
206
210
  );
207
211
 
212
+ if (!saferpayTransaction?.token) {
213
+ throw new Error('No initialized transaction Token');
214
+ }
215
+
208
216
  const api = createSaferPayClient();
209
217
  const paymentPageAssert = await api.paymentPageAssert(orderPayment, {
210
218
  Token: saferpayTransaction.token,
@@ -236,6 +244,10 @@ export const WordlineSaferpay: IPaymentAdapter = {
236
244
  mongodb.ObjectId.createFromHexString(transactionId),
237
245
  );
238
246
 
247
+ if (!saferpayTransaction?.token) {
248
+ throw new Error('No initialized transaction Token');
249
+ }
250
+
239
251
  const api = createSaferPayClient();
240
252
  const paymentPageAssert = await api.paymentPageAssert(orderPayment, {
241
253
  Token: saferpayTransaction.token,
@@ -3,7 +3,7 @@ import { createLogger } from '@unchainedshop/logger';
3
3
  import { buildSignature } from './buildSignature.js';
4
4
  import { SaferpayTransactionsModule } from './module.js';
5
5
 
6
- const logger = createLogger('unchained:core-payment:saferpay:handler');
6
+ const logger = createLogger('unchained:saferpay:handler');
7
7
 
8
8
  export const saferpayHandler = async (request, response) => {
9
9
  const resolvedContext = request.unchainedContext as Context & {
@@ -22,8 +22,7 @@ export const saferpayHandler = async (request, response) => {
22
22
 
23
23
  if ((request.method !== 'GET' && request.method !== 'HEAD') || !isValidRequest) {
24
24
  logger.warn(`unhandled http method ${request.method} or orderPaymentId missing in query`);
25
- response.writeHead(404);
26
- response.end();
25
+ response.status(404).end();
27
26
  return;
28
27
  }
29
28
 
@@ -47,24 +46,26 @@ export const saferpayHandler = async (request, response) => {
47
46
  transactionId,
48
47
  },
49
48
  });
49
+
50
+ if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
51
+
50
52
  logger.info(`checkout successful`, {
51
53
  orderPaymentId,
52
54
  orderId: order._id,
53
55
  });
54
- response.writeHead(200);
55
- response.end(
56
- JSON.stringify({
57
- message: 'checkout successful',
58
- orderPaymentId,
59
- orderId: order._id,
60
- }),
61
- );
56
+ response.status(200).send({
57
+ message: 'checkout successful',
58
+ orderPaymentId,
59
+ orderId: order._id,
60
+ });
62
61
  } catch (error) {
63
62
  logger.error(error, {
64
63
  orderPaymentId,
65
64
  transactionId,
66
65
  });
67
- response.writeHead(500);
68
- response.end(error.message);
66
+ response.status(500).send({
67
+ message: error.message,
68
+ name: error.name,
69
+ });
69
70
  }
70
71
  };
@@ -4,7 +4,7 @@ import { buildSignature } from './buildSignature.js';
4
4
  import { SaferpayTransactionsModule } from './module.js';
5
5
  import { FastifyRequest, RouteHandlerMethod } from 'fastify';
6
6
 
7
- const logger = createLogger('unchained:core-payment:saferpay:handler');
7
+ const logger = createLogger('unchained:saferpay:handler');
8
8
 
9
9
  export const saferpayHandler: RouteHandlerMethod = async (
10
10
  request: FastifyRequest & {
@@ -52,24 +52,29 @@ export const saferpayHandler: RouteHandlerMethod = async (
52
52
  transactionId,
53
53
  },
54
54
  });
55
+
56
+ if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
57
+
55
58
  logger.info(`checkout successful`, {
56
59
  orderPaymentId,
57
60
  orderId: order._id,
58
61
  });
59
62
  reply.status(200);
60
- return reply.send(
61
- JSON.stringify({
62
- message: 'checkout successful',
63
- orderPaymentId,
64
- orderId: order._id,
65
- }),
66
- );
63
+ return reply.send({
64
+ success: true,
65
+ orderPaymentId,
66
+ orderId: order._id,
67
+ });
67
68
  } catch (error) {
68
69
  logger.error(error, {
69
70
  orderPaymentId,
70
71
  transactionId,
71
72
  });
72
73
  reply.status(500);
73
- return reply.send(error.message);
74
+ return reply.send({
75
+ success: false,
76
+ message: error.message,
77
+ name: error.name,
78
+ });
74
79
  }
75
80
  };