@unchainedshop/plugins 4.0.0-rc.9 → 4.0.0

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 (307) 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.d.ts.map +1 -1
  13. package/lib/files/gridfs/adapter.js +11 -8
  14. package/lib/files/gridfs/adapter.js.map +1 -1
  15. package/lib/files/gridfs/gridfs-adapter.d.ts +3 -0
  16. package/lib/files/gridfs/gridfs-adapter.d.ts.map +1 -0
  17. package/lib/files/gridfs/gridfs-adapter.js +97 -0
  18. package/lib/files/gridfs/gridfs-adapter.js.map +1 -0
  19. package/lib/files/gridfs/gridfs-webhook.d.ts +11 -0
  20. package/lib/files/gridfs/gridfs-webhook.d.ts.map +1 -0
  21. package/lib/files/gridfs/gridfs-webhook.js +84 -0
  22. package/lib/files/gridfs/gridfs-webhook.js.map +1 -0
  23. package/lib/files/gridfs/handler-express.d.ts.map +1 -1
  24. package/lib/files/gridfs/handler-express.js +21 -25
  25. package/lib/files/gridfs/handler-express.js.map +1 -1
  26. package/lib/files/gridfs/handler-fastify.d.ts.map +1 -1
  27. package/lib/files/gridfs/handler-fastify.js +50 -13
  28. package/lib/files/gridfs/handler-fastify.js.map +1 -1
  29. package/lib/files/gridfs/module.d.ts +2 -2
  30. package/lib/files/minio/handler-express.d.ts.map +1 -1
  31. package/lib/files/minio/handler-express.js +4 -7
  32. package/lib/files/minio/handler-express.js.map +1 -1
  33. package/lib/files/minio/handler-fastify.js +2 -2
  34. package/lib/files/minio/handler-fastify.js.map +1 -1
  35. package/lib/files/minio/index.d.ts +1 -1
  36. package/lib/files/minio/index.d.ts.map +1 -1
  37. package/lib/files/minio/index.js +7 -7
  38. package/lib/files/minio/index.js.map +1 -1
  39. package/lib/files/minio/minio-adapter.d.ts +6 -0
  40. package/lib/files/minio/minio-adapter.d.ts.map +1 -0
  41. package/lib/files/minio/minio-adapter.js +181 -0
  42. package/lib/files/minio/minio-adapter.js.map +1 -0
  43. package/lib/files/minio/minio-webhook.d.ts +2 -0
  44. package/lib/files/minio/minio-webhook.d.ts.map +1 -0
  45. package/lib/files/minio/minio-webhook.js +33 -0
  46. package/lib/files/minio/minio-webhook.js.map +1 -0
  47. package/lib/filters/local-search.js +1 -1
  48. package/lib/filters/local-search.js.map +1 -1
  49. package/lib/filters/strict-equal.js +0 -18
  50. package/lib/filters/strict-equal.js.map +1 -1
  51. package/lib/payment/apple-iap/adapter.js +12 -10
  52. package/lib/payment/apple-iap/adapter.js.map +1 -1
  53. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +1 -1
  54. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts.map +1 -1
  55. package/lib/payment/apple-iap/handler-express.d.ts.map +1 -1
  56. package/lib/payment/apple-iap/handler-express.js +14 -10
  57. package/lib/payment/apple-iap/handler-express.js.map +1 -1
  58. package/lib/payment/apple-iap/handler-fastify.d.ts.map +1 -1
  59. package/lib/payment/apple-iap/handler-fastify.js +15 -8
  60. package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
  61. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
  62. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +1 -0
  63. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +17 -0
  64. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
  65. package/lib/payment/apple-iap/module.d.ts +4 -4
  66. package/lib/payment/apple-iap/module.d.ts.map +1 -1
  67. package/lib/payment/apple-iap/module.js +4 -2
  68. package/lib/payment/apple-iap/module.js.map +1 -1
  69. package/lib/payment/braintree.js +3 -1
  70. package/lib/payment/braintree.js.map +1 -1
  71. package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
  72. package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
  73. package/lib/payment/cryptopay/derive-btc-address.d.ts.map +1 -1
  74. package/lib/payment/cryptopay/derive-btc-address.js +2 -3
  75. package/lib/payment/cryptopay/derive-btc-address.js.map +1 -1
  76. package/lib/payment/cryptopay/derive-eth-address.d.ts.map +1 -1
  77. package/lib/payment/cryptopay/derive-eth-address.js +5 -3
  78. package/lib/payment/cryptopay/derive-eth-address.js.map +1 -1
  79. package/lib/payment/cryptopay/handle-webhook.js +2 -2
  80. package/lib/payment/cryptopay/handle-webhook.js.map +1 -1
  81. package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
  82. package/lib/payment/cryptopay/handler-express.js +4 -7
  83. package/lib/payment/cryptopay/handler-express.js.map +1 -1
  84. package/lib/payment/cryptopay/handler-fastify.js +1 -1
  85. package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
  86. package/lib/payment/cryptopay/middleware.d.ts +2 -0
  87. package/lib/payment/cryptopay/middleware.d.ts.map +1 -0
  88. package/lib/payment/cryptopay/middleware.js +75 -0
  89. package/lib/payment/cryptopay/middleware.js.map +1 -0
  90. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +25 -0
  91. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +1 -0
  92. package/lib/payment/cryptopay/module/configureCryptopayModule.js +75 -0
  93. package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +1 -0
  94. package/lib/payment/cryptopay/module.d.ts +2 -2
  95. package/lib/payment/cryptopay/module.d.ts.map +1 -1
  96. package/lib/payment/cryptopay/module.js +4 -4
  97. package/lib/payment/cryptopay/module.js.map +1 -1
  98. package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
  99. package/lib/payment/cryptopay/plugin.js +18 -4
  100. package/lib/payment/cryptopay/plugin.js.map +1 -1
  101. package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -1
  102. package/lib/payment/datatrans-v2/handler-express.js +13 -11
  103. package/lib/payment/datatrans-v2/handler-express.js.map +1 -1
  104. package/lib/payment/datatrans-v2/handler-fastify.d.ts.map +1 -1
  105. package/lib/payment/datatrans-v2/handler-fastify.js +11 -5
  106. package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -1
  107. package/lib/payment/datatrans-v2/index.js +63 -37
  108. package/lib/payment/datatrans-v2/index.js.map +1 -1
  109. package/lib/payment/datatrans-v2/middleware.d.ts +2 -0
  110. package/lib/payment/datatrans-v2/middleware.d.ts.map +1 -0
  111. package/lib/payment/datatrans-v2/middleware.js +68 -0
  112. package/lib/payment/datatrans-v2/middleware.js.map +1 -0
  113. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +1 -1
  114. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts.map +1 -1
  115. package/lib/payment/paypal-checkout.js +4 -2
  116. package/lib/payment/paypal-checkout.js.map +1 -1
  117. package/lib/payment/payrexx/api/index.d.ts +1 -1
  118. package/lib/payment/payrexx/api/index.d.ts.map +1 -1
  119. package/lib/payment/payrexx/api/makeFetcher.d.ts +1 -1
  120. package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
  121. package/lib/payment/payrexx/api/makeFetcher.js +1 -1
  122. package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
  123. package/lib/payment/payrexx/handler-express.d.ts.map +1 -1
  124. package/lib/payment/payrexx/handler-express.js +15 -15
  125. package/lib/payment/payrexx/handler-express.js.map +1 -1
  126. package/lib/payment/payrexx/handler-fastify.js +23 -15
  127. package/lib/payment/payrexx/handler-fastify.js.map +1 -1
  128. package/lib/payment/payrexx/index.js +21 -15
  129. package/lib/payment/payrexx/index.js.map +1 -1
  130. package/lib/payment/payrexx/middleware.d.ts +2 -0
  131. package/lib/payment/payrexx/middleware.d.ts.map +1 -0
  132. package/lib/payment/payrexx/middleware.js +86 -0
  133. package/lib/payment/payrexx/middleware.js.map +1 -0
  134. package/lib/payment/postfinance-checkout/api-client.d.ts.map +1 -1
  135. package/lib/payment/postfinance-checkout/api-client.js +7 -7
  136. package/lib/payment/postfinance-checkout/api-client.js.map +1 -1
  137. package/lib/payment/postfinance-checkout/handler-express.js +7 -8
  138. package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
  139. package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -1
  140. package/lib/payment/postfinance-checkout/handler-fastify.js +6 -4
  141. package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
  142. package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
  143. package/lib/payment/postfinance-checkout/index.js +20 -7
  144. package/lib/payment/postfinance-checkout/index.js.map +1 -1
  145. package/lib/payment/postfinance-checkout/middleware.d.ts +2 -0
  146. package/lib/payment/postfinance-checkout/middleware.d.ts.map +1 -0
  147. package/lib/payment/postfinance-checkout/middleware.js +38 -0
  148. package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
  149. package/lib/payment/saferpay/adapter.d.ts.map +1 -1
  150. package/lib/payment/saferpay/adapter.js +9 -0
  151. package/lib/payment/saferpay/adapter.js.map +1 -1
  152. package/lib/payment/saferpay/handler-express.d.ts.map +1 -1
  153. package/lib/payment/saferpay/handler-express.js +10 -8
  154. package/lib/payment/saferpay/handler-express.js.map +1 -1
  155. package/lib/payment/saferpay/handler-fastify.d.ts.map +1 -1
  156. package/lib/payment/saferpay/handler-fastify.js +11 -5
  157. package/lib/payment/saferpay/handler-fastify.js.map +1 -1
  158. package/lib/payment/saferpay/middleware.d.ts +2 -0
  159. package/lib/payment/saferpay/middleware.d.ts.map +1 -0
  160. package/lib/payment/saferpay/middleware.js +57 -0
  161. package/lib/payment/saferpay/middleware.js.map +1 -0
  162. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +10 -0
  163. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +1 -0
  164. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +24 -0
  165. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +1 -0
  166. package/lib/payment/saferpay/module.d.ts +2 -2
  167. package/lib/payment/stripe/handler-express.js +25 -17
  168. package/lib/payment/stripe/handler-express.js.map +1 -1
  169. package/lib/payment/stripe/handler-fastify.d.ts.map +1 -1
  170. package/lib/payment/stripe/handler-fastify.js +33 -12
  171. package/lib/payment/stripe/handler-fastify.js.map +1 -1
  172. package/lib/payment/stripe/index.js +21 -15
  173. package/lib/payment/stripe/index.js.map +1 -1
  174. package/lib/payment/stripe/middleware.d.ts +6 -0
  175. package/lib/payment/stripe/middleware.d.ts.map +1 -0
  176. package/lib/payment/stripe/middleware.js +114 -0
  177. package/lib/payment/stripe/middleware.js.map +1 -0
  178. package/lib/payment/stripe/stripe.d.ts +2 -2
  179. package/lib/payment/stripe/stripe.d.ts.map +1 -1
  180. package/lib/payment/stripe/stripe.js +14 -11
  181. package/lib/payment/stripe/stripe.js.map +1 -1
  182. package/lib/plugins-index.d.ts +48 -0
  183. package/lib/plugins-index.d.ts.map +1 -0
  184. package/lib/plugins-index.js +107 -0
  185. package/lib/plugins-index.js.map +1 -0
  186. package/lib/presets/all.d.ts +5 -5
  187. package/lib/presets/all.d.ts.map +1 -1
  188. package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
  189. package/lib/pricing/delivery-swiss-tax.js +13 -20
  190. package/lib/pricing/delivery-swiss-tax.js.map +1 -1
  191. package/lib/pricing/order-discount.d.ts.map +1 -1
  192. package/lib/pricing/order-discount.js +5 -3
  193. package/lib/pricing/order-discount.js.map +1 -1
  194. package/lib/pricing/order-round.d.ts.map +1 -1
  195. package/lib/pricing/order-round.js +4 -3
  196. package/lib/pricing/order-round.js.map +1 -1
  197. package/lib/pricing/product-catalog-price-options.d.ts +2 -0
  198. package/lib/pricing/product-catalog-price-options.d.ts.map +1 -0
  199. package/lib/pricing/product-catalog-price-options.js +52 -0
  200. package/lib/pricing/product-catalog-price-options.js.map +1 -0
  201. package/lib/pricing/product-catalog-price.d.ts.map +1 -1
  202. package/lib/pricing/product-catalog-price.js +26 -2
  203. package/lib/pricing/product-catalog-price.js.map +1 -1
  204. package/lib/pricing/product-price-rateconversion.js +3 -3
  205. package/lib/pricing/product-price-rateconversion.js.map +1 -1
  206. package/lib/pricing/product-swiss-tax.d.ts +1 -5
  207. package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
  208. package/lib/pricing/product-swiss-tax.js +26 -22
  209. package/lib/pricing/product-swiss-tax.js.map +1 -1
  210. package/lib/pricing/tax/ch.d.ts +7 -2
  211. package/lib/pricing/tax/ch.d.ts.map +1 -1
  212. package/lib/pricing/tax/ch.js +16 -1
  213. package/lib/pricing/tax/ch.js.map +1 -1
  214. package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts +7 -0
  215. package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts.map +1 -0
  216. package/lib/pricing/utils/isDeliveryAddressInCountry.js +13 -0
  217. package/lib/pricing/utils/isDeliveryAddressInCountry.js.map +1 -0
  218. package/lib/warehousing/eth-minter.js +23 -11
  219. package/lib/warehousing/eth-minter.js.map +1 -1
  220. package/lib/worker/bulk-import.d.ts +1 -1
  221. package/lib/worker/bulk-import.d.ts.map +1 -1
  222. package/lib/worker/bulk-import.js +11 -33
  223. package/lib/worker/bulk-import.js.map +1 -1
  224. package/lib/worker/email.d.ts.map +1 -1
  225. package/lib/worker/email.js +25 -7
  226. package/lib/worker/email.js.map +1 -1
  227. package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
  228. package/lib/worker/enrollment-order-generator.js +7 -49
  229. package/lib/worker/enrollment-order-generator.js.map +1 -1
  230. package/lib/worker/error-notifications.js +1 -1
  231. package/lib/worker/error-notifications.js.map +1 -1
  232. package/lib/worker/export-token.d.ts.map +1 -1
  233. package/lib/worker/export-token.js +0 -1
  234. package/lib/worker/export-token.js.map +1 -1
  235. package/lib/worker/message.d.ts +1 -1
  236. package/lib/worker/message.d.ts.map +1 -1
  237. package/lib/worker/message.js +4 -2
  238. package/lib/worker/message.js.map +1 -1
  239. package/lib/worker/sms.js +17 -17
  240. package/lib/worker/sms.js.map +1 -1
  241. package/lib/worker/twilio.js +4 -0
  242. package/lib/worker/twilio.js.map +1 -1
  243. package/package.json +22 -33
  244. package/src/delivery/send-message.ts +1 -1
  245. package/src/enrollments/licensed.ts +15 -2
  246. package/src/files/gridfs/adapter.ts +12 -7
  247. package/src/files/gridfs/handler-express.ts +23 -25
  248. package/src/files/gridfs/handler-fastify.ts +53 -14
  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 +16 -16
  252. package/src/filters/local-search.ts +1 -1
  253. package/src/filters/strict-equal.ts +0 -21
  254. package/src/payment/apple-iap/adapter.ts +12 -14
  255. package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +1 -1
  256. package/src/payment/apple-iap/handler-express.ts +17 -11
  257. package/src/payment/apple-iap/handler-fastify.ts +19 -9
  258. package/src/payment/apple-iap/module.ts +9 -4
  259. package/src/payment/braintree.ts +4 -1
  260. package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -1
  261. package/src/payment/cryptopay/derive-btc-address.ts +1 -3
  262. package/src/payment/cryptopay/derive-eth-address.ts +5 -3
  263. package/src/payment/cryptopay/handle-webhook.ts +6 -6
  264. package/src/payment/cryptopay/handler-express.ts +4 -7
  265. package/src/payment/cryptopay/handler-fastify.ts +1 -1
  266. package/src/payment/cryptopay/module.ts +8 -5
  267. package/src/payment/cryptopay/plugin.ts +21 -4
  268. package/src/payment/datatrans-v2/handler-express.ts +17 -12
  269. package/src/payment/datatrans-v2/handler-fastify.ts +15 -6
  270. package/src/payment/datatrans-v2/index.ts +82 -50
  271. package/src/payment/paypal-checkout.ts +4 -2
  272. package/src/payment/payrexx/api/index.ts +1 -1
  273. package/src/payment/payrexx/api/makeFetcher.ts +2 -2
  274. package/src/payment/payrexx/handler-express.ts +24 -32
  275. package/src/payment/payrexx/handler-fastify.ts +33 -33
  276. package/src/payment/payrexx/index.ts +26 -16
  277. package/src/payment/postfinance-checkout/api-client.ts +13 -8
  278. package/src/payment/postfinance-checkout/handler-express.ts +8 -8
  279. package/src/payment/postfinance-checkout/handler-fastify.ts +7 -4
  280. package/src/payment/postfinance-checkout/index.ts +20 -8
  281. package/src/payment/saferpay/adapter.ts +14 -2
  282. package/src/payment/saferpay/handler-express.ts +14 -13
  283. package/src/payment/saferpay/handler-fastify.ts +14 -9
  284. package/src/payment/stripe/handler-express.ts +33 -33
  285. package/src/payment/stripe/handler-fastify.ts +40 -27
  286. package/src/payment/stripe/index.ts +18 -16
  287. package/src/payment/stripe/stripe.ts +17 -12
  288. package/src/pricing/delivery-swiss-tax.ts +16 -31
  289. package/src/pricing/order-discount.ts +6 -4
  290. package/src/pricing/order-round.ts +5 -4
  291. package/src/pricing/product-catalog-price-options.ts +67 -0
  292. package/src/pricing/product-catalog-price.ts +25 -2
  293. package/src/pricing/product-price-rateconversion.ts +3 -3
  294. package/src/pricing/product-swiss-tax.ts +39 -40
  295. package/src/pricing/tax/ch.ts +33 -7
  296. package/src/pricing/utils/isDeliveryAddressInCountry.test.ts +106 -0
  297. package/src/pricing/utils/isDeliveryAddressInCountry.ts +26 -0
  298. package/src/warehousing/eth-minter.ts +30 -11
  299. package/src/worker/budgetsms.ts +1 -1
  300. package/src/worker/bulk-import.ts +12 -53
  301. package/src/worker/email.ts +30 -8
  302. package/src/worker/enrollment-order-generator.ts +14 -72
  303. package/src/worker/error-notifications.ts +2 -2
  304. package/src/worker/export-token.ts +0 -1
  305. package/src/worker/message.ts +5 -3
  306. package/src/worker/twilio.ts +10 -3
  307. package/src/pricing/product-swiss-tax.test.ts +0 -139
@@ -12,7 +12,7 @@ import deriveBtcAddress from './derive-btc-address.js';
12
12
  import deriveEthAddress from './derive-eth-address.js';
13
13
  import denoteAmount from './denote-amount.js';
14
14
 
15
- const logger = createLogger('unchained:core-payment:cryptopay');
15
+ const logger = createLogger('unchained:cryptopay');
16
16
 
17
17
  const { CRYPTOPAY_SECRET, CRYPTOPAY_BTC_XPUB, CRYPTOPAY_ETH_XPUB } = process.env;
18
18
 
@@ -44,6 +44,9 @@ const Cryptopay: IPaymentAdapter = {
44
44
 
45
45
  const setConversionRates = async (currencyCode: string, existingAddresses: any[]) => {
46
46
  const originCurrencyObj = await modules.currencies.findCurrency({ isoCode: currencyCode });
47
+
48
+ if (!originCurrencyObj?.isActive) throw new Error('Origin currency is not supported');
49
+
47
50
  const updatedAddresses = await Promise.all(
48
51
  existingAddresses.map(async (addressData) => {
49
52
  const targetCurrencyObj = await modules.currencies.findCurrency({
@@ -113,6 +116,8 @@ const Cryptopay: IPaymentAdapter = {
113
116
  if (!orderPayment)
114
117
  throw new Error('Payment Credential Registration is not yet supported for Cryptopay');
115
118
 
119
+ if (!order) throw new Error('Order context is required for signing with Cryptopay');
120
+
116
121
  const existingAddresses = await modules.cryptopay.getWalletAddressesByOrderPaymentId(
117
122
  orderPayment._id,
118
123
  );
@@ -166,6 +171,11 @@ const Cryptopay: IPaymentAdapter = {
166
171
  charge: async () => {
167
172
  const { order, orderPayment } = context;
168
173
 
174
+ if (!orderPayment)
175
+ throw new Error('Order Payment context is required for charging with Cryptopay');
176
+
177
+ if (!order) throw new Error('Order context is required for charging with Cryptopay');
178
+
169
179
  const foundWalletsWithBalances = await modules.cryptopay.getWalletAddressesByOrderPaymentId(
170
180
  orderPayment._id,
171
181
  );
@@ -180,18 +190,25 @@ const Cryptopay: IPaymentAdapter = {
180
190
  });
181
191
  const totalAmount = BigInt(pricing?.total({ useNetPrice: false }).amount);
182
192
 
183
- if (walletForOrderPayment.currencyCode !== order.currencyCode) {
193
+ if (walletForOrderPayment && walletForOrderPayment.currencyCode !== order.currencyCode) {
184
194
  const baseCurrency = await modules.currencies.findCurrency({
185
195
  isoCode: walletForOrderPayment.currencyCode,
186
196
  });
197
+
198
+ if (!baseCurrency) throw new Error('Base currency not found');
199
+
187
200
  const quoteCurrency = await modules.currencies.findCurrency({ isoCode: order.currencyCode });
188
201
 
189
- const { /* min, */ max } = await modules.products.prices.rates.getRateRange(
202
+ if (!quoteCurrency) throw new Error('Quote currency not found');
203
+
204
+ const rate = await modules.products.prices.rates.getRateRange(
190
205
  baseCurrency,
191
206
  quoteCurrency,
192
207
  order.confirmed || new Date(),
193
208
  );
194
209
 
210
+ if (!rate) throw new Error('No conversion rate found');
211
+
195
212
  const convertedAmount = denoteAmount(
196
213
  walletForOrderPayment.amount.toString(),
197
214
  walletForOrderPayment.decimals,
@@ -199,7 +216,7 @@ const Cryptopay: IPaymentAdapter = {
199
216
 
200
217
  // Add a Promille 🍻
201
218
  // const minAmount = parseFloat(convertedAmount.toString()) * min * 0.999;
202
- const maxAmount = parseFloat(convertedAmount.toString()) * max * 1.001;
219
+ const maxAmount = parseFloat(convertedAmount.toString()) * rate.max * 1.001;
203
220
 
204
221
  if (maxAmount && maxAmount >= totalAmount) {
205
222
  // Enough sent
@@ -9,12 +9,19 @@ const {
9
9
  DATATRANS_SECURITY = Security.DYNAMIC_SIGN,
10
10
  } = process.env;
11
11
 
12
- const logger = createLogger('unchained:core-payment:datatrans:handler');
12
+ const logger = createLogger('unchained:datatrans:handler');
13
13
 
14
14
  export const datatransHandler = async (req, res) => {
15
15
  const resolvedContext = req.unchainedContext as Context;
16
16
  const { modules, services } = resolvedContext;
17
17
  const signature = req.headers['datatrans-signature'];
18
+
19
+ if (!DATATRANS_SIGN_KEY && !DATATRANS_SIGN2_KEY) {
20
+ logger.warn('No sign key configured');
21
+ res.status(404).end();
22
+ return;
23
+ }
24
+
18
25
  if (req.method === 'POST' && signature) {
19
26
  const [rawTimestamp, rawHash] = signature.split(',');
20
27
  const [, hash] = rawHash.split('=');
@@ -22,13 +29,12 @@ export const datatransHandler = async (req, res) => {
22
29
 
23
30
  const comparableSignature = await generateSignature({
24
31
  security: DATATRANS_SECURITY as any,
25
- signKey: DATATRANS_SIGN2_KEY || DATATRANS_SIGN_KEY,
32
+ signKey: DATATRANS_SIGN2_KEY! || DATATRANS_SIGN_KEY!,
26
33
  })(timestamp, req.body);
27
34
 
28
35
  if (hash !== comparableSignature) {
29
36
  logger.error(`hash mismatch: ${signature} / ${comparableSignature}`, req.body);
30
- res.writeHead(403);
31
- res.end('Hash mismatch');
37
+ res.status(403).send('Hash mismatch');
32
38
  return;
33
39
  }
34
40
 
@@ -52,8 +58,7 @@ export const datatransHandler = async (req, res) => {
52
58
  logger.info(`registered payment credentials for ${userId}`, {
53
59
  userId,
54
60
  });
55
- res.writeHead(200);
56
- res.end(JSON.stringify(paymentCredentials));
61
+ res.status(200).send(paymentCredentials);
57
62
  return;
58
63
  }
59
64
  if (transaction.type === 'payment') {
@@ -66,21 +71,21 @@ export const datatransHandler = async (req, res) => {
66
71
  const order = await services.orders.checkoutOrder(orderPayment.orderId, {
67
72
  paymentContext: { userId, transactionId: transaction.transactionId },
68
73
  });
69
- res.writeHead(200);
74
+
75
+ if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
76
+
70
77
  logger.info(`confirmed checkout for order ${order.orderNumber}`, {
71
78
  orderId: order._id,
72
79
  });
73
- res.end(JSON.stringify(order));
80
+ res.status(200).send(order);
74
81
  return;
75
82
  }
76
83
  } catch (e) {
77
84
  logger.error(`rejected to checkout with message`, e);
78
- res.writeHead(500);
79
- res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
85
+ res.status(500).send({ name: e.name, code: e.code, message: e.message });
80
86
  return;
81
87
  }
82
88
  }
83
89
  }
84
- res.writeHead(404);
85
- res.end();
90
+ res.status(404).end();
86
91
  };
@@ -10,7 +10,7 @@ const {
10
10
  DATATRANS_SECURITY = Security.DYNAMIC_SIGN,
11
11
  } = process.env;
12
12
 
13
- const logger = createLogger('unchained:core-payment:datatrans:handler');
13
+ const logger = createLogger('unchained:datatrans:handler');
14
14
 
15
15
  export const datatransHandler: RouteHandlerMethod = async (
16
16
  req: FastifyRequest & {
@@ -21,6 +21,12 @@ export const datatransHandler: RouteHandlerMethod = async (
21
21
  const resolvedContext = req.unchainedContext as Context;
22
22
  const { modules, services } = resolvedContext;
23
23
  const signature = req.headers['datatrans-signature'] as string;
24
+
25
+ if (!DATATRANS_SIGN_KEY && !DATATRANS_SIGN2_KEY) {
26
+ logger.warn('No sign key configured');
27
+ return reply.send({ success: false, message: 'No sign key configured', name: 'NO_SIGN_KEY' });
28
+ }
29
+
24
30
  if (signature) {
25
31
  const [rawTimestamp, rawHash] = signature.split(',');
26
32
  const [, hash] = rawHash.split('=');
@@ -28,13 +34,13 @@ export const datatransHandler: RouteHandlerMethod = async (
28
34
 
29
35
  const comparableSignature = await generateSignature({
30
36
  security: DATATRANS_SECURITY as any,
31
- signKey: DATATRANS_SIGN2_KEY || DATATRANS_SIGN_KEY,
37
+ signKey: DATATRANS_SIGN2_KEY! || DATATRANS_SIGN_KEY!,
32
38
  })(timestamp, req.body as string);
33
39
 
34
40
  if (hash !== comparableSignature) {
35
- logger.error(`hash mismatch: ${signature} / ${comparableSignature}`, req.body as string);
41
+ logger.error(`hash mismatch: ${signature} / ${comparableSignature}`);
36
42
  reply.status(403);
37
- return reply.send('Hash mismatch');
43
+ return reply.send({ success: false, message: 'Invalid Signature', name: 'HASH_MISMATCH' });
38
44
  }
39
45
 
40
46
  const transaction: StatusResponseSuccess = JSON.parse(req.body as string) as StatusResponseSuccess;
@@ -70,6 +76,9 @@ export const datatransHandler: RouteHandlerMethod = async (
70
76
  const order = await services.orders.checkoutOrder(orderPayment.orderId, {
71
77
  paymentContext: { userId, transactionId: transaction.transactionId },
72
78
  });
79
+
80
+ if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
81
+
73
82
  reply.status(200);
74
83
  logger.info(`confirmed checkout for order ${order.orderNumber}`, {
75
84
  orderId: order._id,
@@ -77,9 +86,9 @@ export const datatransHandler: RouteHandlerMethod = async (
77
86
  return reply.send(order);
78
87
  }
79
88
  } catch (e) {
80
- logger.error(`rejected to checkout with message`, e);
89
+ logger.error(e);
81
90
  reply.status(500);
82
- return reply.send({ name: e.name, code: e.code, message: e.message });
91
+ return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
83
92
  }
84
93
  }
85
94
  }
@@ -19,8 +19,10 @@ import {
19
19
  PaymentPricingSheet,
20
20
  OrderPricingSheet,
21
21
  } from '@unchainedshop/core';
22
+ import { Order, OrderPayment } from '@unchainedshop/core-orders';
23
+ import { PaymentConfiguration } from '@unchainedshop/core-payment';
22
24
 
23
- const logger = createLogger('unchained:core-payment:datatrans');
25
+ const logger = createLogger('unchained:datatrans');
24
26
 
25
27
  // v2
26
28
  const {
@@ -43,6 +45,56 @@ const throwIfResponseError = (result) => {
43
45
  }
44
46
  };
45
47
 
48
+ const getMarketplaceSplits = async ({
49
+ order,
50
+ orderPayment,
51
+ config,
52
+ }: {
53
+ order: Order;
54
+ orderPayment: OrderPayment;
55
+ config: PaymentConfiguration;
56
+ }): Promise<
57
+ {
58
+ subMerchantId: string;
59
+ amount: number;
60
+ commission: number;
61
+ }[]
62
+ > => {
63
+ const pricingForOrderPayment = PaymentPricingSheet({
64
+ calculation: orderPayment.calculation,
65
+ currencyCode: order.currencyCode,
66
+ });
67
+ const pricing = OrderPricingSheet({
68
+ calculation: order.calculation,
69
+ currencyCode: order.currencyCode,
70
+ });
71
+
72
+ const { amount: total } = pricing.total({ useNetPrice: false });
73
+
74
+ return Promise.all(
75
+ config
76
+ .filter((item) => item.key === 'marketplaceSplit')
77
+ .map((item) => {
78
+ const [subMerchantId, staticDiscountId, sharePercentage] =
79
+ item.value || ''.split(';').map((f) => f.trim());
80
+
81
+ const { amount: discountSum } = pricingForOrderPayment.total({
82
+ category: PaymentPricingRowCategory.Discount,
83
+ discountId: staticDiscountId,
84
+ });
85
+ const shareFactor = sharePercentage ? parseInt(sharePercentage, 10) / 100 : 1;
86
+ const amount = Math.round(total * shareFactor);
87
+ const commission = Math.round(discountSum * -1 * shareFactor);
88
+
89
+ return {
90
+ subMerchantId,
91
+ amount,
92
+ commission,
93
+ };
94
+ }),
95
+ );
96
+ };
97
+
46
98
  const Datatrans: IPaymentAdapter = {
47
99
  ...PaymentAdapter,
48
100
 
@@ -67,8 +119,11 @@ const Datatrans: IPaymentAdapter = {
67
119
  };
68
120
 
69
121
  const api = () => {
70
- if (!DATATRANS_SECRET) throw new Error('Credentials not Set');
71
- return createDatatransAPI(DATATRANS_API_ENDPOINT, getMerchantId(), DATATRANS_SECRET);
122
+ const merchantId = getMerchantId();
123
+ if (!DATATRANS_SECRET) throw new Error('Credential DATATRANS_SECRET not Set');
124
+ if (!merchantId) throw new Error('Credential Merchant ID not configured');
125
+ if (!DATATRANS_API_ENDPOINT) throw new Error('Credential DATATRANS_API_ENDPOINT not Set');
126
+ return createDatatransAPI(DATATRANS_API_ENDPOINT, merchantId!, DATATRANS_SECRET);
72
127
  };
73
128
 
74
129
  const shouldSettleInUnchained = () => {
@@ -78,58 +133,21 @@ const Datatrans: IPaymentAdapter = {
78
133
  }, true);
79
134
  };
80
135
 
81
- const getMarketplaceSplits = async (): Promise<
82
- {
83
- subMerchantId: string;
84
- amount: number;
85
- commission: number;
86
- }[]
87
- > => {
136
+ const authorize = async ({ paymentCredentials, ...arbitraryFields }): Promise<string> => {
88
137
  const { order, orderPayment } = context;
89
138
 
90
- const pricingForOrderPayment = PaymentPricingSheet({
91
- calculation: orderPayment.calculation,
92
- currencyCode: order.currencyCode,
93
- });
94
- const pricing = OrderPricingSheet({
95
- calculation: order.calculation,
96
- currencyCode: order.currencyCode,
97
- });
98
-
99
- const { amount: total } = pricing.total({ useNetPrice: false });
100
-
101
- return Promise.all(
102
- config
103
- .filter((item) => item.key === 'marketplaceSplit')
104
- .map((item) => {
105
- const [subMerchantId, staticDiscountId, sharePercentage] = item.value
106
- .split(';')
107
- .map((f) => f.trim());
108
-
109
- const { amount: discountSum } = pricingForOrderPayment.total({
110
- category: PaymentPricingRowCategory.Discount,
111
- discountId: staticDiscountId,
112
- });
113
- const shareFactor = sharePercentage ? parseInt(sharePercentage, 10) / 100 : 1;
114
- const amount = Math.round(total * shareFactor);
115
- const commission = Math.round(discountSum * -1 * shareFactor);
116
-
117
- return {
118
- subMerchantId,
119
- amount,
120
- commission,
121
- };
122
- }),
123
- );
124
- };
139
+ if (!orderPayment) throw new Error('Order Payment missing in context');
140
+ if (!order) throw new Error('Order missing in context');
125
141
 
126
- const authorize = async ({ paymentCredentials, ...arbitraryFields }): Promise<string> => {
127
- const { order, orderPayment } = context;
128
142
  const refno = Buffer.from(orderPayment._id, 'hex').toString('base64');
129
143
  const userId = order?.userId || context?.userId;
130
144
  const refno2 = userId;
131
145
  const { currencyCode, amount } = roundedAmountFromOrder(order);
132
- const splits = await getMarketplaceSplits();
146
+ const splits = await getMarketplaceSplits({
147
+ orderPayment,
148
+ order,
149
+ config,
150
+ });
133
151
  const result = await api().authorize({
134
152
  ...arbitraryFields,
135
153
  amount,
@@ -158,6 +176,7 @@ const Datatrans: IPaymentAdapter = {
158
176
  ...arbitraryFields
159
177
  }): Promise<string> => {
160
178
  const { order } = context;
179
+ if (!order) throw new Error('Order missing in context');
161
180
  const { currencyCode, amount } = roundedAmountFromOrder(order);
162
181
  const result = await api().authorizeAuthenticated({
163
182
  ...arbitraryFields,
@@ -174,6 +193,7 @@ const Datatrans: IPaymentAdapter = {
174
193
 
175
194
  const isTransactionAmountValid = (transaction: StatusResponseSuccess): boolean => {
176
195
  const { order } = context;
196
+ if (!order) throw new Error('Order missing in context');
177
197
  const { currencyCode, amount } = roundedAmountFromOrder(order);
178
198
  if (
179
199
  transaction.currency !== currencyCode ||
@@ -207,9 +227,15 @@ const Datatrans: IPaymentAdapter = {
207
227
  };
208
228
 
209
229
  const settle = async ({ transactionId, refno, refno2, extensions }): Promise<boolean> => {
210
- const { order } = context;
230
+ const { order, orderPayment } = context;
231
+ if (!orderPayment) throw new Error('Order Payment missing in context');
232
+ if (!order) throw new Error('Order missing in context');
211
233
  const { currencyCode, amount } = roundedAmountFromOrder(order);
212
- const splits = await getMarketplaceSplits();
234
+ const splits = await getMarketplaceSplits({
235
+ orderPayment,
236
+ order,
237
+ config,
238
+ });
213
239
  const result = await api().settle({
214
240
  transactionId,
215
241
  amount,
@@ -320,6 +346,9 @@ const Datatrans: IPaymentAdapter = {
320
346
  async confirm() {
321
347
  if (!shouldSettleInUnchained()) return false;
322
348
  const { orderPayment, transactionContext } = context;
349
+
350
+ if (!orderPayment) throw new Error('Order Payment missing in context');
351
+
323
352
  const { transactionId } = orderPayment;
324
353
 
325
354
  const { extensions } = transactionContext || {};
@@ -350,6 +379,9 @@ const Datatrans: IPaymentAdapter = {
350
379
  async cancel() {
351
380
  if (!shouldSettleInUnchained()) return false;
352
381
  const { orderPayment } = context;
382
+
383
+ if (!orderPayment) throw new Error('Order Payment missing in context');
384
+
353
385
  const { transactionId } = orderPayment;
354
386
  if (!transactionId) {
355
387
  return false;
@@ -17,7 +17,7 @@ try {
17
17
  /* */
18
18
  }
19
19
 
20
- const logger = createLogger('unchained:core-payment:paypal-checkout');
20
+ const logger = createLogger('unchained:paypal-checkout');
21
21
 
22
22
  const { PAYPAL_CLIENT_ID, PAYPAL_SECRET, PAYPAL_ENVIRONMENT = 'sandbox' } = process.env;
23
23
 
@@ -72,12 +72,14 @@ const PaypalCheckout: IPaymentAdapter = {
72
72
  },
73
73
 
74
74
  sign: async () => {
75
- return PAYPAL_CLIENT_ID;
75
+ return PAYPAL_CLIENT_ID || null;
76
76
  },
77
77
 
78
78
  charge: async ({ orderID }) => {
79
79
  const { order } = context;
80
80
 
81
+ if (!order) throw new Error('Order missing in payment context');
82
+
81
83
  if (!orderID) {
82
84
  throw new Error('You have to provide orderID in paymentContext');
83
85
  }
@@ -51,7 +51,7 @@ const createPayrexxAPI = (instance: string, secret: string) => {
51
51
  throw new Error(await result.text());
52
52
  },
53
53
 
54
- async getGateway(id): Promise<GatewayObject> {
54
+ async getGateway(id): Promise<GatewayObject | null> {
55
55
  const result = await fetchPayrexx(`Gateway/${id}`, 'GET');
56
56
  if (!result.ok) throw new Error(await result.text());
57
57
  const { status, data } = await result.json();
@@ -6,8 +6,8 @@ const logger = createLogger('unchained:payrexx');
6
6
 
7
7
  export default (
8
8
  baseUrl = 'https://api.payrexx.com/v1.0/',
9
- instance: string = null,
10
- secret: string = null,
9
+ instance: string,
10
+ secret: string,
11
11
  ): ((path: string, method: 'GET' | 'DELETE' | 'PUT' | 'POST', data?: any) => Promise<Response>) => {
12
12
  if (MOCK_APIS) {
13
13
  return async (path): Promise<Response> => {
@@ -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
  };