@unchainedshop/plugins 3.0.0-rc.13 → 3.0.0-rc.15

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 (268) hide show
  1. package/lib/files/gridfs/{gridfs-adapter.d.ts → adapter.d.ts} +2 -4
  2. package/lib/files/gridfs/adapter.d.ts.map +1 -0
  3. package/lib/files/gridfs/{gridfs-adapter.js → adapter.js} +1 -1
  4. package/lib/files/gridfs/adapter.js.map +1 -0
  5. package/lib/files/gridfs/handler-express.d.ts +10 -0
  6. package/lib/files/gridfs/handler-express.d.ts.map +1 -0
  7. package/lib/files/gridfs/{gridfs-webhook.js → handler-express.js} +3 -2
  8. package/lib/files/gridfs/handler-express.js.map +1 -0
  9. package/lib/files/gridfs/handler-fastify.d.ts +4 -0
  10. package/lib/files/gridfs/handler-fastify.d.ts.map +1 -0
  11. package/lib/files/gridfs/handler-fastify.js +91 -0
  12. package/lib/files/gridfs/handler-fastify.js.map +1 -0
  13. package/lib/files/gridfs/index.d.ts +4 -10
  14. package/lib/files/gridfs/index.d.ts.map +1 -1
  15. package/lib/files/gridfs/index.js +3 -27
  16. package/lib/files/gridfs/index.js.map +1 -1
  17. package/lib/files/gridfs/module.d.ts +26 -0
  18. package/lib/files/gridfs/module.d.ts.map +1 -0
  19. package/lib/files/gridfs/module.js +33 -0
  20. package/lib/files/gridfs/module.js.map +1 -0
  21. package/lib/files/minio/handler-express.d.ts +3 -0
  22. package/lib/files/minio/handler-express.d.ts.map +1 -0
  23. package/lib/files/minio/{minio-webhook.js → handler-express.js} +3 -2
  24. package/lib/files/minio/handler-express.js.map +1 -0
  25. package/lib/files/minio/handler-fastify.d.ts +4 -0
  26. package/lib/files/minio/handler-fastify.d.ts.map +1 -0
  27. package/lib/files/minio/handler-fastify.js +34 -0
  28. package/lib/files/minio/handler-fastify.js.map +1 -0
  29. package/lib/files/minio/{minio-adapter.d.ts → index.d.ts} +1 -1
  30. package/lib/files/minio/index.d.ts.map +1 -0
  31. package/lib/files/minio/{minio-adapter.js → index.js} +1 -1
  32. package/lib/files/minio/index.js.map +1 -0
  33. package/lib/payment/apple-iap/adapter.d.ts +1 -1
  34. package/lib/payment/apple-iap/adapter.d.ts.map +1 -1
  35. package/lib/payment/apple-iap/adapter.js +5 -155
  36. package/lib/payment/apple-iap/adapter.js.map +1 -1
  37. package/lib/payment/apple-iap/fix-periods.d.ts +8 -0
  38. package/lib/payment/apple-iap/fix-periods.d.ts.map +1 -0
  39. package/lib/payment/apple-iap/fix-periods.js +22 -0
  40. package/lib/payment/apple-iap/fix-periods.js.map +1 -0
  41. package/lib/payment/apple-iap/handler-express.d.ts +3 -0
  42. package/lib/payment/apple-iap/handler-express.d.ts.map +1 -0
  43. package/lib/payment/apple-iap/handler-express.js +110 -0
  44. package/lib/payment/apple-iap/handler-express.js.map +1 -0
  45. package/lib/payment/apple-iap/handler-fastify.d.ts +4 -0
  46. package/lib/payment/apple-iap/handler-fastify.d.ts.map +1 -0
  47. package/lib/payment/apple-iap/handler-fastify.js +104 -0
  48. package/lib/payment/apple-iap/handler-fastify.js.map +1 -0
  49. package/lib/payment/apple-iap/index.d.ts +3 -1
  50. package/lib/payment/apple-iap/index.d.ts.map +1 -1
  51. package/lib/payment/apple-iap/index.js +2 -1
  52. package/lib/payment/apple-iap/index.js.map +1 -1
  53. package/lib/payment/apple-iap/module.d.ts +22 -0
  54. package/lib/payment/apple-iap/module.d.ts.map +1 -0
  55. package/lib/payment/apple-iap/{module/configureAppleTransactionsModule.js → module.js} +7 -2
  56. package/lib/payment/apple-iap/module.js.map +1 -0
  57. package/lib/payment/apple-iap/verify-receipt.d.ts +5 -0
  58. package/lib/payment/apple-iap/verify-receipt.d.ts.map +1 -0
  59. package/lib/payment/apple-iap/verify-receipt.js +26 -0
  60. package/lib/payment/apple-iap/verify-receipt.js.map +1 -0
  61. package/lib/payment/cryptopay/handler-express.d.ts +3 -0
  62. package/lib/payment/cryptopay/handler-express.d.ts.map +1 -0
  63. package/lib/payment/cryptopay/{middleware.js → handler-express.js} +3 -2
  64. package/lib/payment/cryptopay/{middleware.js.map → handler-express.js.map} +1 -1
  65. package/lib/payment/cryptopay/handler-fastify.d.ts +4 -0
  66. package/lib/payment/cryptopay/handler-fastify.d.ts.map +1 -0
  67. package/lib/payment/cryptopay/handler-fastify.js +69 -0
  68. package/lib/payment/cryptopay/handler-fastify.js.map +1 -0
  69. package/lib/payment/cryptopay/index.d.ts +4 -4
  70. package/lib/payment/cryptopay/index.d.ts.map +1 -1
  71. package/lib/payment/cryptopay/index.js +3 -4
  72. package/lib/payment/cryptopay/index.js.map +1 -1
  73. package/lib/payment/cryptopay/module.d.ts +54 -0
  74. package/lib/payment/cryptopay/module.d.ts.map +1 -0
  75. package/lib/payment/cryptopay/{module/configureCryptopayModule.js → module.js} +8 -3
  76. package/lib/payment/cryptopay/module.js.map +1 -0
  77. package/lib/payment/cryptopay/plugin.js +1 -1
  78. package/lib/payment/cryptopay/plugin.js.map +1 -1
  79. package/lib/payment/datatrans-v2/{middleware.d.ts → handler-express.d.ts} +1 -1
  80. package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -0
  81. package/lib/payment/datatrans-v2/{middleware.js → handler-express.js} +2 -2
  82. package/lib/payment/datatrans-v2/handler-express.js.map +1 -0
  83. package/lib/payment/datatrans-v2/handler-fastify.d.ts +3 -0
  84. package/lib/payment/datatrans-v2/handler-fastify.d.ts.map +1 -0
  85. package/lib/payment/datatrans-v2/handler-fastify.js +66 -0
  86. package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -0
  87. package/lib/payment/datatrans-v2/index.d.ts +1 -1
  88. package/lib/payment/datatrans-v2/index.d.ts.map +1 -1
  89. package/lib/payment/datatrans-v2/index.js +0 -1
  90. package/lib/payment/datatrans-v2/index.js.map +1 -1
  91. package/lib/payment/payrexx/{middleware.d.ts → handler-express.d.ts} +1 -1
  92. package/lib/payment/payrexx/handler-express.d.ts.map +1 -0
  93. package/lib/payment/payrexx/{middleware.js → handler-express.js} +2 -2
  94. package/lib/payment/payrexx/handler-express.js.map +1 -0
  95. package/lib/payment/payrexx/handler-fastify.d.ts +3 -0
  96. package/lib/payment/payrexx/handler-fastify.d.ts.map +1 -0
  97. package/lib/payment/payrexx/handler-fastify.js +87 -0
  98. package/lib/payment/payrexx/handler-fastify.js.map +1 -0
  99. package/lib/payment/payrexx/index.d.ts +1 -1
  100. package/lib/payment/payrexx/index.d.ts.map +1 -1
  101. package/lib/payment/payrexx/index.js +0 -1
  102. package/lib/payment/payrexx/index.js.map +1 -1
  103. package/lib/payment/postfinance-checkout/{middleware.d.ts → handler-express.d.ts} +1 -1
  104. package/lib/payment/postfinance-checkout/handler-express.d.ts.map +1 -0
  105. package/lib/payment/postfinance-checkout/{middleware.js → handler-express.js} +1 -1
  106. package/lib/payment/postfinance-checkout/handler-express.js.map +1 -0
  107. package/lib/payment/postfinance-checkout/handler-fastify.d.ts +3 -0
  108. package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -0
  109. package/lib/payment/postfinance-checkout/handler-fastify.js +39 -0
  110. package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -0
  111. package/lib/payment/postfinance-checkout/index.d.ts +1 -1
  112. package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
  113. package/lib/payment/postfinance-checkout/index.js +0 -1
  114. package/lib/payment/postfinance-checkout/index.js.map +1 -1
  115. package/lib/payment/saferpay/adapter.d.ts +0 -1
  116. package/lib/payment/saferpay/adapter.d.ts.map +1 -1
  117. package/lib/payment/saferpay/adapter.js +0 -1
  118. package/lib/payment/saferpay/adapter.js.map +1 -1
  119. package/lib/payment/saferpay/{middleware.d.ts → handler-express.d.ts} +1 -1
  120. package/lib/payment/saferpay/handler-express.d.ts.map +1 -0
  121. package/lib/payment/saferpay/{middleware.js → handler-express.js} +2 -2
  122. package/lib/payment/saferpay/handler-express.js.map +1 -0
  123. package/lib/payment/saferpay/handler-fastify.d.ts +3 -0
  124. package/lib/payment/saferpay/handler-fastify.d.ts.map +1 -0
  125. package/lib/payment/saferpay/handler-fastify.js +56 -0
  126. package/lib/payment/saferpay/handler-fastify.js.map +1 -0
  127. package/lib/payment/saferpay/index.d.ts +3 -2
  128. package/lib/payment/saferpay/index.d.ts.map +1 -1
  129. package/lib/payment/saferpay/index.js +2 -2
  130. package/lib/payment/saferpay/index.js.map +1 -1
  131. package/lib/payment/saferpay/module.d.ts +24 -0
  132. package/lib/payment/saferpay/module.d.ts.map +1 -0
  133. package/lib/payment/saferpay/{module/configureSaferpayTransactionsModule.js → module.js} +8 -3
  134. package/lib/payment/saferpay/module.js.map +1 -0
  135. package/lib/payment/stripe/{middleware.d.ts → handler-express.d.ts} +1 -1
  136. package/lib/payment/stripe/handler-express.d.ts.map +1 -0
  137. package/lib/payment/stripe/{middleware.js → handler-express.js} +2 -2
  138. package/lib/payment/stripe/handler-express.js.map +1 -0
  139. package/lib/payment/stripe/handler-fastify.d.ts +7 -0
  140. package/lib/payment/stripe/handler-fastify.d.ts.map +1 -0
  141. package/lib/payment/stripe/handler-fastify.js +112 -0
  142. package/lib/payment/stripe/handler-fastify.js.map +1 -0
  143. package/lib/payment/stripe/index.d.ts +1 -1
  144. package/lib/payment/stripe/index.d.ts.map +1 -1
  145. package/lib/payment/stripe/index.js +0 -1
  146. package/lib/payment/stripe/index.js.map +1 -1
  147. package/lib/presets/all-express.d.ts +7 -0
  148. package/lib/presets/all-express.d.ts.map +1 -0
  149. package/lib/presets/all-express.js +27 -0
  150. package/lib/presets/all-express.js.map +1 -0
  151. package/lib/presets/all-fastify.d.ts +7 -0
  152. package/lib/presets/all-fastify.d.ts.map +1 -0
  153. package/lib/presets/all-fastify.js +64 -0
  154. package/lib/presets/all-fastify.js.map +1 -0
  155. package/lib/presets/all.d.ts +69 -0
  156. package/lib/presets/all.d.ts.map +1 -0
  157. package/lib/presets/all.js +30 -0
  158. package/lib/presets/all.js.map +1 -0
  159. package/lib/presets/base-express.js +2 -2
  160. package/lib/presets/base-express.js.map +1 -1
  161. package/lib/presets/base-fastify.d.ts +4 -0
  162. package/lib/presets/base-fastify.d.ts.map +1 -0
  163. package/lib/presets/base-fastify.js +18 -0
  164. package/lib/presets/base-fastify.js.map +1 -0
  165. package/lib/presets/{base-modules.d.ts → base.d.ts} +3 -7
  166. package/lib/presets/base.d.ts.map +1 -0
  167. package/lib/presets/{base-modules.js → base.js} +3 -9
  168. package/lib/presets/base.js.map +1 -0
  169. package/lib/presets/crypto-express.js +2 -2
  170. package/lib/presets/crypto-express.js.map +1 -1
  171. package/lib/presets/crypto-fastify.d.ts +4 -0
  172. package/lib/presets/crypto-fastify.d.ts.map +1 -0
  173. package/lib/presets/crypto-fastify.js +12 -0
  174. package/lib/presets/crypto-fastify.js.map +1 -0
  175. package/lib/presets/crypto.d.ts +8 -0
  176. package/lib/presets/crypto.d.ts.map +1 -0
  177. package/lib/presets/crypto.js +9 -0
  178. package/lib/presets/crypto.js.map +1 -0
  179. package/package.json +18 -14
  180. package/src/files/gridfs/{gridfs-adapter.ts → adapter.ts} +1 -3
  181. package/src/files/gridfs/{gridfs-webhook.ts → handler-express.ts} +5 -3
  182. package/src/files/gridfs/handler-fastify.ts +122 -0
  183. package/src/files/gridfs/index.ts +4 -29
  184. package/src/files/gridfs/module.ts +39 -0
  185. package/src/files/minio/{minio-webhook.ts → handler-express.ts} +3 -1
  186. package/src/files/minio/handler-fastify.ts +44 -0
  187. package/src/payment/apple-iap/adapter.ts +6 -193
  188. package/src/payment/apple-iap/fix-periods.ts +34 -0
  189. package/src/payment/apple-iap/handler-express.ts +134 -0
  190. package/src/payment/apple-iap/handler-fastify.ts +137 -0
  191. package/src/payment/apple-iap/index.ts +5 -1
  192. package/src/payment/apple-iap/{module/configureAppleTransactionsModule.ts → module.ts} +10 -2
  193. package/src/payment/apple-iap/verify-receipt.ts +27 -0
  194. package/src/payment/cryptopay/{middleware.ts → handler-express.ts} +5 -5
  195. package/src/payment/cryptopay/handler-fastify.ts +89 -0
  196. package/src/payment/cryptopay/index.ts +5 -4
  197. package/src/payment/cryptopay/{module/configureCryptopayModule.ts → module.ts} +11 -3
  198. package/src/payment/cryptopay/plugin.ts +3 -3
  199. package/src/payment/datatrans-v2/{middleware.ts → handler-express.ts} +1 -1
  200. package/src/payment/datatrans-v2/handler-fastify.ts +88 -0
  201. package/src/payment/datatrans-v2/index.ts +0 -2
  202. package/src/payment/payrexx/{middleware.ts → handler-express.ts} +1 -1
  203. package/src/payment/payrexx/handler-fastify.ts +105 -0
  204. package/src/payment/payrexx/index.ts +0 -2
  205. package/src/payment/postfinance-checkout/handler-fastify.ts +52 -0
  206. package/src/payment/postfinance-checkout/index.ts +0 -2
  207. package/src/payment/saferpay/adapter.ts +2 -4
  208. package/src/payment/saferpay/{middleware.ts → handler-express.ts} +3 -3
  209. package/src/payment/saferpay/handler-fastify.ts +75 -0
  210. package/src/payment/saferpay/index.ts +5 -2
  211. package/src/payment/saferpay/{module/configureSaferpayTransactionsModule.ts → module.ts} +11 -3
  212. package/src/payment/stripe/{middleware.ts → handler-express.ts} +1 -1
  213. package/src/payment/stripe/handler-fastify.ts +139 -0
  214. package/src/payment/stripe/index.ts +0 -2
  215. package/src/presets/all-express.ts +51 -0
  216. package/src/presets/all-fastify.ts +87 -0
  217. package/src/presets/all.ts +35 -0
  218. package/src/presets/base-express.ts +2 -2
  219. package/src/presets/base-fastify.ts +20 -0
  220. package/src/presets/{base-modules.ts → base.ts} +3 -17
  221. package/src/presets/crypto-express.ts +2 -2
  222. package/src/presets/crypto-fastify.ts +15 -0
  223. package/src/presets/crypto.ts +11 -0
  224. package/lib/files/gridfs/gridfs-adapter.d.ts.map +0 -1
  225. package/lib/files/gridfs/gridfs-adapter.js.map +0 -1
  226. package/lib/files/gridfs/gridfs-webhook.d.ts +0 -11
  227. package/lib/files/gridfs/gridfs-webhook.d.ts.map +0 -1
  228. package/lib/files/gridfs/gridfs-webhook.js.map +0 -1
  229. package/lib/files/minio/minio-adapter.d.ts.map +0 -1
  230. package/lib/files/minio/minio-adapter.js.map +0 -1
  231. package/lib/files/minio/minio-webhook.d.ts +0 -2
  232. package/lib/files/minio/minio-webhook.d.ts.map +0 -1
  233. package/lib/files/minio/minio-webhook.js.map +0 -1
  234. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +0 -9
  235. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +0 -1
  236. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +0 -1
  237. package/lib/payment/cryptopay/middleware.d.ts +0 -2
  238. package/lib/payment/cryptopay/middleware.d.ts.map +0 -1
  239. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +0 -25
  240. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +0 -1
  241. package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +0 -1
  242. package/lib/payment/datatrans-v2/middleware.d.ts.map +0 -1
  243. package/lib/payment/datatrans-v2/middleware.js.map +0 -1
  244. package/lib/payment/payrexx/middleware.d.ts.map +0 -1
  245. package/lib/payment/payrexx/middleware.js.map +0 -1
  246. package/lib/payment/postfinance-checkout/middleware.d.ts.map +0 -1
  247. package/lib/payment/postfinance-checkout/middleware.js.map +0 -1
  248. package/lib/payment/saferpay/middleware.d.ts.map +0 -1
  249. package/lib/payment/saferpay/middleware.js.map +0 -1
  250. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +0 -10
  251. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +0 -1
  252. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +0 -1
  253. package/lib/payment/stripe/middleware.d.ts.map +0 -1
  254. package/lib/payment/stripe/middleware.js.map +0 -1
  255. package/lib/plugins-index.d.ts +0 -18
  256. package/lib/plugins-index.d.ts.map +0 -1
  257. package/lib/plugins-index.js +0 -52
  258. package/lib/plugins-index.js.map +0 -1
  259. package/lib/presets/base-modules.d.ts.map +0 -1
  260. package/lib/presets/base-modules.js.map +0 -1
  261. package/lib/presets/crypto-modules.d.ts +0 -11
  262. package/lib/presets/crypto-modules.d.ts.map +0 -1
  263. package/lib/presets/crypto-modules.js +0 -14
  264. package/lib/presets/crypto-modules.js.map +0 -1
  265. package/src/plugins-index.ts +0 -90
  266. package/src/presets/crypto-modules.ts +0 -23
  267. /package/src/files/minio/{minio-adapter.ts → index.ts} +0 -0
  268. /package/src/payment/postfinance-checkout/{middleware.ts → handler-express.ts} +0 -0
@@ -0,0 +1,105 @@
1
+ import { Context } from '@unchainedshop/api';
2
+ import { createLogger } from '@unchainedshop/logger';
3
+ import { FastifyRequest, RouteHandlerMethod } from 'fastify';
4
+
5
+ const logger = createLogger('unchained:core-payment:payrexx:handler');
6
+
7
+ export const payrexxHandler: RouteHandlerMethod = async (
8
+ request: FastifyRequest & {
9
+ unchainedContext: Context;
10
+ },
11
+ reply,
12
+ ) => {
13
+ const resolvedContext = request.unchainedContext as Context;
14
+ const { modules, services } = resolvedContext;
15
+
16
+ const { transaction } = request.body as Record<string, any>;
17
+
18
+ if (!transaction) {
19
+ logger.info(`unhandled event type`, {
20
+ type: Object.keys(request.body).join(','),
21
+ });
22
+ 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
+ );
29
+ }
30
+ if (transaction.referenceId === '__IGNORE_WEBHOOK__' || transaction.status === 'waiting') {
31
+ // Ignore confirmed transactions, because those hooks are generated through calling the confirm()
32
+ // method in the payment adapter and could lead to double bookings.
33
+ logger.info(`unhandled transaction state: ${transaction.status}`);
34
+ reply.status(200);
35
+ return reply.send(
36
+ JSON.stringify({
37
+ ignored: true,
38
+ message: `Unhandled transaction state: ${transaction.status}`,
39
+ }),
40
+ );
41
+ }
42
+
43
+ logger.info(`Processing event`, {
44
+ transactionId: transaction.id,
45
+ });
46
+ try {
47
+ if (transaction.preAuthorizationId) {
48
+ // Pre-Authorization Flow, referenceId is a userId
49
+ const { referenceId: paymentProviderId, invoice } = transaction;
50
+ const userId = '';
51
+ logger.info(`register credentials for: ${userId}`);
52
+ await services.orders.registerPaymentCredentials(paymentProviderId, {
53
+ userId,
54
+ transactionContext: { gatewayId: invoice.paymentRequestId },
55
+ });
56
+ logger.info(`registration successful`, {
57
+ paymentProviderId,
58
+ userId,
59
+ });
60
+ reply.status(200);
61
+ return reply.send(
62
+ JSON.stringify({
63
+ message: 'registration successful',
64
+ paymentProviderId,
65
+ userId,
66
+ }),
67
+ );
68
+ } else {
69
+ const { referenceId: orderPaymentId, invoice } = transaction;
70
+ logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
71
+ await modules.orders.payments.logEvent(orderPaymentId, {
72
+ transactionId: transaction.id,
73
+ });
74
+ const orderPayment = await modules.orders.payments.findOrderPayment({
75
+ orderPaymentId,
76
+ });
77
+ if (!orderPayment) {
78
+ throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
79
+ }
80
+
81
+ const order = await services.orders.checkoutOrder(orderPayment.orderId, {
82
+ paymentContext: {
83
+ gatewayId: invoice.paymentRequestId,
84
+ },
85
+ });
86
+ logger.info(`checkout successful`, {
87
+ orderPaymentId,
88
+ orderId: order._id,
89
+ });
90
+ reply.status(200);
91
+ return reply.send(
92
+ JSON.stringify({
93
+ message: 'checkout successful',
94
+ orderId: order._id,
95
+ }),
96
+ );
97
+ }
98
+ } catch (error) {
99
+ logger.error(error, {
100
+ transactionId: transaction.id,
101
+ });
102
+ reply.status(500);
103
+ return reply.send(error.message);
104
+ }
105
+ };
@@ -9,8 +9,6 @@ import {
9
9
  PaymentError,
10
10
  } from '@unchainedshop/core';
11
11
 
12
- export * from './middleware.js';
13
-
14
12
  const logger = createLogger('unchained:core-payment:payrexx');
15
13
 
16
14
  const Payrexx: IPaymentAdapter = {
@@ -0,0 +1,52 @@
1
+ import { Context } from '@unchainedshop/api';
2
+ import { createLogger } from '@unchainedshop/logger';
3
+ import { WebhookData } from './types.js';
4
+ import { getTransaction, getTransactionCompletion } from './api.js';
5
+ import { FastifyRequest, RouteHandlerMethod } from 'fastify';
6
+
7
+ const logger = createLogger('unchained:core-payment:postfinance-checkout');
8
+
9
+ export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
10
+ req: FastifyRequest & {
11
+ unchainedContext: Context;
12
+ },
13
+ reply,
14
+ ) => {
15
+ const context = req.unchainedContext as Context;
16
+ const { services, modules } = context;
17
+ const data = req.body as WebhookData;
18
+ if (data.listenerEntityTechnicalName === 'TransactionCompletion') {
19
+ try {
20
+ const transactionCompletion = await getTransactionCompletion(data.entityId as unknown as string);
21
+ const transaction = await getTransaction(
22
+ transactionCompletion.linkedTransaction as unknown as string,
23
+ );
24
+ const { orderPaymentId } = transaction.metaData as { orderPaymentId: string };
25
+ const orderPayment = await modules.orders.payments.findOrderPayment({
26
+ orderPaymentId,
27
+ });
28
+ if (!orderPayment) throw new Error('Order Payment not found');
29
+
30
+ const order = await services.orders.checkoutOrder(orderPayment.orderId, {
31
+ paymentContext: {
32
+ transactionId: transactionCompletion.linkedTransaction,
33
+ },
34
+ });
35
+ logger.info(
36
+ `PostFinance Checkout Webhook: Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
37
+ );
38
+ reply.status(200);
39
+ return reply.send(`Order marked as paid: ${order.orderNumber}`);
40
+ } catch (e) {
41
+ logger.error(`PostFinance Checkout Webhook: Unchained rejected to checkout with message`, e);
42
+ reply.status(500);
43
+ return reply.send({ name: e.name, code: e.code, message: e.message });
44
+ }
45
+ } else {
46
+ logger.error(
47
+ `PostFinance Checkout Webhook: Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`,
48
+ );
49
+ reply.status(404);
50
+ return reply.send();
51
+ }
52
+ };
@@ -24,8 +24,6 @@ import {
24
24
  import { orderIsPaid } from './utils.js';
25
25
  import { CompletionModes, IntegrationModes, SignResponse } from './types.js';
26
26
 
27
- export * from './middleware.js';
28
-
29
27
  const { PostFinanceCheckout } = pf;
30
28
 
31
29
  const {
@@ -1,7 +1,7 @@
1
1
  import { mongodb } from '@unchainedshop/mongodb';
2
2
  import { PaymentPageInitializeInput, SaferpayClient } from './api/index.js';
3
3
  import { buildSignature } from './buildSignature.js';
4
- import { SaferpayTransactionsModule } from './module/configureSaferpayTransactionsModule.js';
4
+ import { SaferpayTransactionsModule } from './module.js';
5
5
  import {
6
6
  OrderPricingSheet,
7
7
  IPaymentAdapter,
@@ -10,8 +10,6 @@ import {
10
10
  PaymentError,
11
11
  } from '@unchainedshop/core';
12
12
 
13
- export * from './middleware.js';
14
-
15
13
  const {
16
14
  SAFERPAY_BASE_URL = 'https://test.saferpay.com/api',
17
15
  SAFERPAY_CUSTOMER_ID,
@@ -48,7 +46,7 @@ export const WordlineSaferpay: IPaymentAdapter = {
48
46
 
49
47
  actions: (config, context) => {
50
48
  const { modules } = context as typeof context & {
51
- modules: { saferpayTransactions: SaferpayTransactionsModule };
49
+ modules: SaferpayTransactionsModule;
52
50
  };
53
51
 
54
52
  const createSaferPayClient = () => {
@@ -1,13 +1,13 @@
1
1
  import { Context } from '@unchainedshop/api';
2
2
  import { createLogger } from '@unchainedshop/logger';
3
3
  import { buildSignature } from './buildSignature.js';
4
- import { SaferpayTransactionsModule } from './module/configureSaferpayTransactionsModule.js';
4
+ import { SaferpayTransactionsModule } from './module.js';
5
5
 
6
- const logger = createLogger('unchained:core-payment:saferpay:webhook');
6
+ const logger = createLogger('unchained:core-payment:saferpay:handler');
7
7
 
8
8
  export const saferpayHandler = async (request, response) => {
9
9
  const resolvedContext = request.unchainedContext as Context & {
10
- modules: { saferpayTransactions: SaferpayTransactionsModule };
10
+ modules: SaferpayTransactionsModule;
11
11
  };
12
12
  const { modules, services } = resolvedContext;
13
13
 
@@ -0,0 +1,75 @@
1
+ import { Context } from '@unchainedshop/api';
2
+ import { createLogger } from '@unchainedshop/logger';
3
+ import { buildSignature } from './buildSignature.js';
4
+ import { SaferpayTransactionsModule } from './module.js';
5
+ import { FastifyRequest, RouteHandlerMethod } from 'fastify';
6
+
7
+ const logger = createLogger('unchained:core-payment:saferpay:handler');
8
+
9
+ export const saferpayHandler: RouteHandlerMethod = async (
10
+ request: FastifyRequest & {
11
+ unchainedContext: Context;
12
+ },
13
+ reply,
14
+ ) => {
15
+ const resolvedContext = request.unchainedContext as Context & {
16
+ modules: SaferpayTransactionsModule;
17
+ };
18
+ const { modules, services } = resolvedContext;
19
+
20
+ const { orderPaymentId, signature, transactionId } = request.query as Record<string, string>;
21
+ const isValidRequest =
22
+ typeof orderPaymentId === 'string' &&
23
+ typeof signature === 'string' &&
24
+ typeof transactionId === 'string' &&
25
+ orderPaymentId &&
26
+ transactionId &&
27
+ signature;
28
+
29
+ if (!isValidRequest) {
30
+ logger.warn(`orderPaymentId missing in query`);
31
+ reply.status(404);
32
+ return reply.send();
33
+ }
34
+
35
+ try {
36
+ logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
37
+ const orderPayment = await modules.orders.payments.findOrderPayment({
38
+ orderPaymentId,
39
+ });
40
+ if (!orderPayment) {
41
+ throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
42
+ }
43
+
44
+ const correctSignature = await buildSignature(transactionId, orderPaymentId);
45
+
46
+ if (correctSignature !== signature) {
47
+ throw new Error('Invalid signature');
48
+ }
49
+
50
+ const order = await services.orders.checkoutOrder(orderPayment.orderId, {
51
+ paymentContext: {
52
+ transactionId,
53
+ },
54
+ });
55
+ logger.info(`checkout successful`, {
56
+ orderPaymentId,
57
+ orderId: order._id,
58
+ });
59
+ reply.status(200);
60
+ return reply.send(
61
+ JSON.stringify({
62
+ message: 'checkout successful',
63
+ orderPaymentId,
64
+ orderId: order._id,
65
+ }),
66
+ );
67
+ } catch (error) {
68
+ logger.error(error, {
69
+ orderPaymentId,
70
+ transactionId,
71
+ });
72
+ reply.status(500);
73
+ return reply.send(error.message);
74
+ }
75
+ };
@@ -1,3 +1,6 @@
1
1
  export * from './adapter.js';
2
- export * from './module/configureSaferpayTransactionsModule.js';
3
- export * from './middleware.js';
2
+
3
+ import saferpayTransactionsModule, { type SaferpayTransactionsModule } from './module.js';
4
+
5
+ export type { SaferpayTransactionsModule };
6
+ export default saferpayTransactionsModule;
@@ -1,7 +1,7 @@
1
1
  import { mongodb } from '@unchainedshop/mongodb';
2
- import { SaferpayTransactionsCollection } from '../db/SaferpayTransactionsCollection.js';
2
+ import { SaferpayTransactionsCollection } from './db/SaferpayTransactionsCollection.js';
3
3
 
4
- export const configureSaferpayTransactionsModule = async ({ db }: { db: mongodb.Db }) => {
4
+ const configureSaferpayTransactionsModule = async ({ db }: { db: mongodb.Db }) => {
5
5
  const SaferpayTransactions = await SaferpayTransactionsCollection(db);
6
6
 
7
7
  return {
@@ -30,4 +30,12 @@ export const configureSaferpayTransactionsModule = async ({ db }: { db: mongodb.
30
30
  };
31
31
  };
32
32
 
33
- export type SaferpayTransactionsModule = Awaited<ReturnType<typeof configureSaferpayTransactionsModule>>;
33
+ export default {
34
+ saferpayTransactions: {
35
+ configure: configureSaferpayTransactionsModule,
36
+ },
37
+ };
38
+
39
+ export type SaferpayTransactionsModule = {
40
+ saferpayTransactions: Awaited<ReturnType<typeof configureSaferpayTransactionsModule>>;
41
+ };
@@ -2,7 +2,7 @@ import { Context } from '@unchainedshop/api';
2
2
  import { createLogger } from '@unchainedshop/logger';
3
3
  import stripeClient from './stripe.js';
4
4
 
5
- const logger = createLogger('unchained:core-payment:stripe:webhook');
5
+ const logger = createLogger('unchained:core-payment:stripe:handler');
6
6
 
7
7
  export const WebhookEventTypes = {
8
8
  PAYMENT_INTENT_SUCCEEDED: 'payment_intent.succeeded',
@@ -0,0 +1,139 @@
1
+ import { Context } from '@unchainedshop/api';
2
+ import { createLogger } from '@unchainedshop/logger';
3
+ import stripeClient from './stripe.js';
4
+ import { FastifyRequest, RouteHandlerMethod } from 'fastify';
5
+
6
+ const logger = createLogger('unchained:core-payment:stripe:handler');
7
+
8
+ export const WebhookEventTypes = {
9
+ PAYMENT_INTENT_SUCCEEDED: 'payment_intent.succeeded',
10
+ SETUP_INTENT_SUCCEEDED: 'setup_intent.succeeded',
11
+ };
12
+
13
+ export const stripeHandler: RouteHandlerMethod = async (
14
+ req: FastifyRequest & {
15
+ unchainedContext: Context;
16
+ },
17
+ reply,
18
+ ) => {
19
+ const resolvedContext = req.unchainedContext as Context;
20
+ const { modules, services } = resolvedContext;
21
+
22
+ let event;
23
+
24
+ try {
25
+ const stripe = stripeClient();
26
+ const sig = req.headers['stripe-signature'];
27
+ event = stripe.webhooks.constructEvent(req.body as string, sig, process.env.STRIPE_ENDPOINT_SECRET);
28
+ } catch (err) {
29
+ logger.error(`Error constructing event: ${err.message}`);
30
+ reply.status(400);
31
+ return reply.send(err.message);
32
+ }
33
+
34
+ if (!Object.values(WebhookEventTypes).includes(event.type)) {
35
+ logger.info(`unhandled event type`, {
36
+ type: event.type,
37
+ });
38
+ reply.status(200);
39
+ return reply.send(
40
+ JSON.stringify({
41
+ ignored: true,
42
+ message: `Unhandled event type: ${event.type}. Supported types: ${Object.values(WebhookEventTypes).join(', ')}`,
43
+ }),
44
+ );
45
+ }
46
+
47
+ const environmentInMetadata = event.data?.object?.metadata?.environment || '';
48
+ const environmentInEnv = process.env.STRIPE_WEBHOOK_ENVIRONMENT || '';
49
+ if (environmentInMetadata !== environmentInEnv) {
50
+ logger.info(`unhandled event environment`, {
51
+ type: event.type,
52
+ environment: environmentInMetadata,
53
+ });
54
+ reply.status(200);
55
+ return reply.send(
56
+ JSON.stringify({
57
+ ignored: true,
58
+ message: `Unhandled event environment: ${environmentInMetadata}. Supported environment: ${environmentInEnv}`,
59
+ }),
60
+ );
61
+ }
62
+
63
+ logger.info(`Processing event`, {
64
+ type: event.type,
65
+ });
66
+ try {
67
+ if (event.type === WebhookEventTypes.PAYMENT_INTENT_SUCCEEDED) {
68
+ const paymentIntent = event.data.object;
69
+ const { orderPaymentId } = paymentIntent.metadata || {};
70
+
71
+ logger.info(`checkout with orderPaymentId: ${orderPaymentId}`, {
72
+ type: event.type,
73
+ });
74
+
75
+ await modules.orders.payments.logEvent(orderPaymentId, event);
76
+ const orderPayment = await modules.orders.payments.findOrderPayment({
77
+ orderPaymentId,
78
+ });
79
+
80
+ if (!orderPayment) {
81
+ throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
82
+ }
83
+
84
+ const order = await services.orders.checkoutOrder(orderPayment.orderId, {
85
+ paymentContext: {
86
+ paymentIntentId: paymentIntent.id,
87
+ },
88
+ });
89
+
90
+ logger.info(`checkout successful`, {
91
+ orderPaymentId,
92
+ orderId: order._id,
93
+ type: event.type,
94
+ });
95
+ reply.status(200);
96
+ return reply.send(
97
+ JSON.stringify({
98
+ message: 'checkout successful',
99
+ orderId: order._id,
100
+ }),
101
+ );
102
+ } else if (event.type === WebhookEventTypes.SETUP_INTENT_SUCCEEDED) {
103
+ const setupIntent = event.data.object;
104
+ const { paymentProviderId, userId } = setupIntent.metadata || {};
105
+
106
+ logger.info(`registered payment credential with paymentProviderId: ${paymentProviderId}`, {
107
+ type: event.type,
108
+ userId,
109
+ });
110
+
111
+ const paymentCredentials = await services.orders.registerPaymentCredentials(paymentProviderId, {
112
+ transactionContext: {
113
+ setupIntentId: setupIntent.id,
114
+ },
115
+ userId,
116
+ });
117
+
118
+ logger.info(`payment credentials registration successful`, {
119
+ userId,
120
+ paymentProviderId,
121
+ paymentCredentialsId: paymentCredentials?._id,
122
+ type: event.type,
123
+ });
124
+ reply.status(200);
125
+ return reply.send(
126
+ JSON.stringify({
127
+ message: 'payment credentials registration successful',
128
+ paymentCredentialsId: paymentCredentials?._id,
129
+ }),
130
+ );
131
+ }
132
+ } catch (error) {
133
+ logger.error(error, {
134
+ type: event.type,
135
+ });
136
+ reply.status(500);
137
+ return reply.send(error.message);
138
+ }
139
+ };
@@ -8,8 +8,6 @@ import {
8
8
  PaymentError,
9
9
  } from '@unchainedshop/core';
10
10
 
11
- export * from './middleware.js';
12
-
13
11
  const logger = createLogger('unchained:core-payment:stripe');
14
12
 
15
13
  const Stripe: IPaymentAdapter = {
@@ -0,0 +1,51 @@
1
+ import express from 'express';
2
+ import { UnchainedCore } from '@unchainedshop/core';
3
+
4
+ import connectCryptoToExpress from './crypto-express.js';
5
+ import connectBaseToExpress from './base-express.js';
6
+
7
+ import { datatransHandler } from '../payment/datatrans-v2/handler-express.js';
8
+ import { stripeHandler } from '../payment/stripe/handler-express.js';
9
+ import { postfinanceCheckoutHandler } from '../payment/postfinance-checkout/handler-express.js';
10
+ import { appleIAPHandler } from '../payment/apple-iap/handler-express.js';
11
+ import { payrexxHandler } from '../payment/payrexx/handler-express.js';
12
+ import { saferpayHandler } from '../payment/saferpay/handler-express.js';
13
+ import { configureGenerateOrderAutoscheduling } from '../worker/enrollment-order-generator.js';
14
+
15
+ const {
16
+ STRIPE_WEBHOOK_PATH = '/payment/stripe',
17
+ PAYREXX_WEBHOOK_PATH = '/payment/payrexx',
18
+ PFCHECKOUT_WEBHOOK_PATH = '/payment/postfinance-checkout',
19
+ DATATRANS_WEBHOOK_PATH = '/payment/datatrans/webhook',
20
+ APPLE_IAP_WEBHOOK_PATH = '/payment/apple-iap',
21
+ SAFERPAY_WEBHOOK_PATH = '/payment/saferpay/webhook',
22
+ } = process.env;
23
+
24
+ export default (app: express.Express, { unchainedAPI }: { unchainedAPI: UnchainedCore }) => {
25
+ connectBaseToExpress(app);
26
+ connectCryptoToExpress(app, unchainedAPI);
27
+
28
+ app.use(STRIPE_WEBHOOK_PATH, express.raw({ type: 'application/json' }), stripeHandler);
29
+ app.use(PFCHECKOUT_WEBHOOK_PATH, express.json(), postfinanceCheckoutHandler);
30
+
31
+ app.use(
32
+ DATATRANS_WEBHOOK_PATH,
33
+ express.text({
34
+ type: 'application/json',
35
+ }),
36
+ datatransHandler,
37
+ );
38
+
39
+ app.use(
40
+ APPLE_IAP_WEBHOOK_PATH,
41
+ express.json({
42
+ strict: false,
43
+ }),
44
+ appleIAPHandler,
45
+ );
46
+
47
+ app.use(PAYREXX_WEBHOOK_PATH, express.json({ type: 'application/json' }), payrexxHandler);
48
+ app.use(SAFERPAY_WEBHOOK_PATH, saferpayHandler);
49
+
50
+ configureGenerateOrderAutoscheduling();
51
+ };
@@ -0,0 +1,87 @@
1
+ import { UnchainedCore } from '@unchainedshop/core';
2
+ import { FastifyInstance } from 'fastify';
3
+
4
+ import connectCryptoToFastify from './crypto-fastify.js';
5
+ import connectBaseToFastify from './base-fastify.js';
6
+
7
+ import { stripeHandler } from '../payment/stripe/handler-fastify.js';
8
+ import { postfinanceCheckoutHandler } from '../payment/postfinance-checkout/handler-fastify.js';
9
+ import { datatransHandler } from '../payment/datatrans-v2/handler-fastify.js';
10
+ import { appleIAPHandler } from '../payment/apple-iap/handler-fastify.js';
11
+ import { payrexxHandler } from '../payment/payrexx/handler-fastify.js';
12
+ import { saferpayHandler } from '../payment/saferpay/handler-fastify.js';
13
+ import { configureGenerateOrderAutoscheduling } from '../worker/enrollment-order-generator.js';
14
+
15
+ const {
16
+ STRIPE_WEBHOOK_PATH = '/payment/stripe',
17
+ PAYREXX_WEBHOOK_PATH = '/payment/payrexx',
18
+ PFCHECKOUT_WEBHOOK_PATH = '/payment/postfinance-checkout',
19
+ DATATRANS_WEBHOOK_PATH = '/payment/datatrans/webhook',
20
+ APPLE_IAP_WEBHOOK_PATH = '/payment/apple-iap',
21
+ SAFERPAY_WEBHOOK_PATH = '/payment/saferpay/webhook',
22
+ } = process.env;
23
+
24
+ export default (fastify: FastifyInstance, { unchainedAPI }: { unchainedAPI: UnchainedCore }) => {
25
+ connectBaseToFastify(fastify);
26
+ connectCryptoToFastify(fastify, unchainedAPI);
27
+
28
+ fastify.register((s, opts, registered) => {
29
+ // Disable JSON parsing!
30
+ // fastify.addContentTypeParser(
31
+ // 'application/json',
32
+ // { parseAs: 'string', bodyLimit: 1024 * 1024 },
33
+ // function (req, body, done) {
34
+ // try {
35
+ // done(null, body);
36
+ // } catch (err) {
37
+ // err.statusCode = 400;
38
+ // done(err, undefined);
39
+ // }
40
+ // },
41
+ // );
42
+ s.addContentTypeParser(
43
+ 'application/json',
44
+ { parseAs: 'string', bodyLimit: 1024 * 1024 },
45
+ s.defaultTextParser,
46
+ );
47
+ s.route({
48
+ url: STRIPE_WEBHOOK_PATH,
49
+ method: 'POST',
50
+ handler: stripeHandler,
51
+ });
52
+ s.route({
53
+ url: DATATRANS_WEBHOOK_PATH,
54
+ method: 'POST',
55
+ handler: datatransHandler,
56
+ });
57
+ registered();
58
+ });
59
+
60
+ fastify.route({
61
+ url: PFCHECKOUT_WEBHOOK_PATH,
62
+ method: 'POST',
63
+ handler: postfinanceCheckoutHandler,
64
+ });
65
+
66
+ fastify.route({
67
+ url: APPLE_IAP_WEBHOOK_PATH,
68
+ method: 'POST',
69
+ handler: appleIAPHandler,
70
+ });
71
+
72
+ fastify.route({
73
+ url: PAYREXX_WEBHOOK_PATH,
74
+ method: 'POST',
75
+ handler: payrexxHandler,
76
+ });
77
+
78
+ fastify.route({
79
+ url: SAFERPAY_WEBHOOK_PATH,
80
+ method: 'GET',
81
+ handler: saferpayHandler,
82
+ });
83
+
84
+ // app.use(STRIPE_WEBHOOK_PATH, express.raw({ type: 'application/json' }), stripeHandler);
85
+
86
+ configureGenerateOrderAutoscheduling();
87
+ };
@@ -0,0 +1,35 @@
1
+ import baseModules from './base.js';
2
+ import './countries/ch.js';
3
+ import cryptoModules from './crypto.js';
4
+
5
+ // Delivery
6
+ import '../delivery/send-message.js';
7
+ import '../delivery/stores.js';
8
+
9
+ // Payment
10
+ import '../payment/invoice-prepaid.js';
11
+ import '../payment/paypal-checkout.js';
12
+ import appleTransactionsModules from '../payment/apple-iap/index.js';
13
+ import saferpayTransactionsModules from '../payment/saferpay/index.js';
14
+ import '../payment/stripe/index.js';
15
+ import '../payment/postfinance-checkout/index.js';
16
+ import '../payment/datatrans-v2/index.js';
17
+ import '../payment/payrexx/index.js';
18
+
19
+ // Filter & Search
20
+ import '../filters/strict-equal.js';
21
+ import '../filters/local-search.js';
22
+
23
+ // Workers
24
+ import '../worker/sms.js';
25
+ import '../worker/push-notification.js';
26
+ import '../worker/enrollment-order-generator.js';
27
+
28
+ const modules = {
29
+ ...baseModules,
30
+ ...cryptoModules,
31
+ ...appleTransactionsModules,
32
+ ...saferpayTransactionsModules,
33
+ };
34
+
35
+ export default modules;
@@ -1,7 +1,7 @@
1
- import { gridfsHandler } from '../files/gridfs/gridfs-webhook.js';
1
+ import handler from '../files/gridfs/handler-express.js';
2
2
 
3
3
  const { GRIDFS_PUT_SERVER_PATH = '/gridfs' } = process.env;
4
4
 
5
5
  export default (app) => {
6
- app.use(GRIDFS_PUT_SERVER_PATH, gridfsHandler);
6
+ app.use(GRIDFS_PUT_SERVER_PATH, handler);
7
7
  };