@unchainedshop/plugins 1.1.7 → 1.2.1

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 (314) hide show
  1. package/jest.config.js +5 -0
  2. package/package.json +31 -25
  3. package/src/files/gridfs/gridfs-adapter.ts +1 -1
  4. package/src/files/gridfs/gridfs-webhook.ts +62 -0
  5. package/src/files/gridfs/{index.js → index.ts} +0 -0
  6. package/src/files/gridfs/{promisePipe.js → promisePipe.ts} +0 -0
  7. package/src/files/gridfs/{sign.js → sign.ts} +0 -0
  8. package/src/files/minio/minio-adapter.ts +1 -2
  9. package/src/files/minio/minio-webhook.js +33 -30
  10. package/src/payment/apple-iap/adapter.ts +113 -110
  11. package/src/payment/apple-iap/index.ts +2 -1
  12. package/src/payment/bity/adapter.ts +53 -51
  13. package/src/payment/bity/index.ts +2 -1
  14. package/src/payment/braintree.ts +2 -2
  15. package/src/payment/cryptopay.ts +69 -67
  16. package/src/payment/datatrans-v2/index.ts +3 -1
  17. package/src/payment/datatrans-v2/middleware.ts +129 -123
  18. package/src/payment/paypal-checkout.ts +1 -1
  19. package/src/payment/postfinance-checkout/index.ts +3 -1
  20. package/src/payment/postfinance-checkout/middleware.ts +42 -40
  21. package/src/payment/stripe.ts +82 -74
  22. package/src/payment/worldline-saferpay/worldline-saferpay-client/index.ts +3 -3
  23. package/src/pricing/product-discount.ts +1 -1
  24. package/src/pricing/product-price-ECB-interbank-exchange.ts +1 -1
  25. package/src/pricing/product-price-cryptopay.ts +20 -18
  26. package/src/worker/email.ts +1 -0
  27. package/tsconfig.json +26 -5
  28. package/lib/delivery/pick-mup.d.ts +0 -1
  29. package/lib/delivery/pick-mup.js +0 -98
  30. package/lib/delivery/pick-mup.js.map +0 -1
  31. package/lib/delivery/post.d.ts +0 -1
  32. package/lib/delivery/post.js +0 -23
  33. package/lib/delivery/post.js.map +0 -1
  34. package/lib/delivery/send-message.d.ts +0 -1
  35. package/lib/delivery/send-message.js +0 -41
  36. package/lib/delivery/send-message.js.map +0 -1
  37. package/lib/delivery/stores.d.ts +0 -1
  38. package/lib/delivery/stores.js +0 -39
  39. package/lib/delivery/stores.js.map +0 -1
  40. package/lib/enrollments/licensed.d.ts +0 -1
  41. package/lib/enrollments/licensed.js +0 -40
  42. package/lib/enrollments/licensed.js.map +0 -1
  43. package/lib/events/node-event-emitter.d.ts +0 -1
  44. package/lib/events/node-event-emitter.js +0 -16
  45. package/lib/events/node-event-emitter.js.map +0 -1
  46. package/lib/events/redis.d.ts +0 -1
  47. package/lib/events/redis.js +0 -24
  48. package/lib/events/redis.js.map +0 -1
  49. package/lib/files/gridfs/gridfs-adapter.d.ts +0 -2
  50. package/lib/files/gridfs/gridfs-adapter.js +0 -106
  51. package/lib/files/gridfs/gridfs-adapter.js.map +0 -1
  52. package/lib/files/gridfs/gridfs-webhook.d.ts +0 -1
  53. package/lib/files/gridfs/gridfs-webhook.js +0 -54
  54. package/lib/files/gridfs/gridfs-webhook.js.map +0 -1
  55. package/lib/files/gridfs/index.d.ts +0 -8
  56. package/lib/files/gridfs/index.js +0 -21
  57. package/lib/files/gridfs/index.js.map +0 -1
  58. package/lib/files/gridfs/promisePipe.d.ts +0 -2
  59. package/lib/files/gridfs/promisePipe.js +0 -21
  60. package/lib/files/gridfs/promisePipe.js.map +0 -1
  61. package/lib/files/gridfs/sign.d.ts +0 -2
  62. package/lib/files/gridfs/sign.js +0 -12
  63. package/lib/files/gridfs/sign.js.map +0 -1
  64. package/lib/files/minio/minio-adapter.d.ts +0 -4
  65. package/lib/files/minio/minio-adapter.js +0 -166
  66. package/lib/files/minio/minio-adapter.js.map +0 -1
  67. package/lib/files/minio/minio-webhook.d.ts +0 -1
  68. package/lib/files/minio/minio-webhook.js +0 -45
  69. package/lib/files/minio/minio-webhook.js.map +0 -1
  70. package/lib/filters/local-search.d.ts +0 -3
  71. package/lib/filters/local-search.js +0 -84
  72. package/lib/filters/local-search.js.map +0 -1
  73. package/lib/filters/strict-equal.d.ts +0 -1
  74. package/lib/filters/strict-equal.js +0 -25
  75. package/lib/filters/strict-equal.js.map +0 -1
  76. package/lib/payment/apple-iap/adapter.d.ts +0 -1
  77. package/lib/payment/apple-iap/adapter.js +0 -284
  78. package/lib/payment/apple-iap/adapter.js.map +0 -1
  79. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +0 -7
  80. package/lib/payment/apple-iap/db/AppleTransactionsCollection.js +0 -5
  81. package/lib/payment/apple-iap/db/AppleTransactionsCollection.js.map +0 -1
  82. package/lib/payment/apple-iap/index.d.ts +0 -2
  83. package/lib/payment/apple-iap/index.js +0 -3
  84. package/lib/payment/apple-iap/index.js.map +0 -1
  85. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +0 -9
  86. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +0 -18
  87. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +0 -1
  88. package/lib/payment/bity/adapter.d.ts +0 -1
  89. package/lib/payment/bity/adapter.js +0 -316
  90. package/lib/payment/bity/adapter.js.map +0 -1
  91. package/lib/payment/bity/db/BityCredentialsCollection.d.ts +0 -11
  92. package/lib/payment/bity/db/BityCredentialsCollection.js +0 -5
  93. package/lib/payment/bity/db/BityCredentialsCollection.js.map +0 -1
  94. package/lib/payment/bity/index.d.ts +0 -2
  95. package/lib/payment/bity/index.js +0 -3
  96. package/lib/payment/bity/index.js.map +0 -1
  97. package/lib/payment/bity/module/configureBityModule.d.ts +0 -11
  98. package/lib/payment/bity/module/configureBityModule.js +0 -33
  99. package/lib/payment/bity/module/configureBityModule.js.map +0 -1
  100. package/lib/payment/braintree.d.ts +0 -1
  101. package/lib/payment/braintree.js +0 -129
  102. package/lib/payment/braintree.js.map +0 -1
  103. package/lib/payment/cryptopay.d.ts +0 -1
  104. package/lib/payment/cryptopay.js +0 -159
  105. package/lib/payment/cryptopay.js.map +0 -1
  106. package/lib/payment/datatrans-v2/api/authorize.d.ts +0 -2
  107. package/lib/payment/datatrans-v2/api/authorize.js +0 -12
  108. package/lib/payment/datatrans-v2/api/authorize.js.map +0 -1
  109. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.d.ts +0 -2
  110. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js +0 -11
  111. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js.map +0 -1
  112. package/lib/payment/datatrans-v2/api/cancel.d.ts +0 -2
  113. package/lib/payment/datatrans-v2/api/cancel.js +0 -10
  114. package/lib/payment/datatrans-v2/api/cancel.js.map +0 -1
  115. package/lib/payment/datatrans-v2/api/index.d.ts +0 -19
  116. package/lib/payment/datatrans-v2/api/index.js +0 -24
  117. package/lib/payment/datatrans-v2/api/index.js.map +0 -1
  118. package/lib/payment/datatrans-v2/api/init.d.ts +0 -2
  119. package/lib/payment/datatrans-v2/api/init.js +0 -31
  120. package/lib/payment/datatrans-v2/api/init.js.map +0 -1
  121. package/lib/payment/datatrans-v2/api/makeFetcher.d.ts +0 -2
  122. package/lib/payment/datatrans-v2/api/makeFetcher.js +0 -41
  123. package/lib/payment/datatrans-v2/api/makeFetcher.js.map +0 -1
  124. package/lib/payment/datatrans-v2/api/secureFields.d.ts +0 -2
  125. package/lib/payment/datatrans-v2/api/secureFields.js +0 -14
  126. package/lib/payment/datatrans-v2/api/secureFields.js.map +0 -1
  127. package/lib/payment/datatrans-v2/api/settle.d.ts +0 -2
  128. package/lib/payment/datatrans-v2/api/settle.js +0 -10
  129. package/lib/payment/datatrans-v2/api/settle.js.map +0 -1
  130. package/lib/payment/datatrans-v2/api/status.d.ts +0 -2
  131. package/lib/payment/datatrans-v2/api/status.js +0 -7
  132. package/lib/payment/datatrans-v2/api/status.js.map +0 -1
  133. package/lib/payment/datatrans-v2/api/validate.d.ts +0 -2
  134. package/lib/payment/datatrans-v2/api/validate.js +0 -10
  135. package/lib/payment/datatrans-v2/api/validate.js.map +0 -1
  136. package/lib/payment/datatrans-v2/generateSignature.d.ts +0 -10
  137. package/lib/payment/datatrans-v2/generateSignature.js +0 -19
  138. package/lib/payment/datatrans-v2/generateSignature.js.map +0 -1
  139. package/lib/payment/datatrans-v2/getPaths.d.ts +0 -9
  140. package/lib/payment/datatrans-v2/getPaths.js +0 -9
  141. package/lib/payment/datatrans-v2/getPaths.js.map +0 -1
  142. package/lib/payment/datatrans-v2/index.d.ts +0 -1
  143. package/lib/payment/datatrans-v2/index.js +0 -384
  144. package/lib/payment/datatrans-v2/index.js.map +0 -1
  145. package/lib/payment/datatrans-v2/middleware.d.ts +0 -1
  146. package/lib/payment/datatrans-v2/middleware.js +0 -111
  147. package/lib/payment/datatrans-v2/middleware.js.map +0 -1
  148. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +0 -11
  149. package/lib/payment/datatrans-v2/parseRegistrationData.js +0 -26
  150. package/lib/payment/datatrans-v2/parseRegistrationData.js.map +0 -1
  151. package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +0 -7
  152. package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +0 -10
  153. package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +0 -1
  154. package/lib/payment/datatrans-v2/splitProperties.d.ts +0 -8
  155. package/lib/payment/datatrans-v2/splitProperties.js +0 -58
  156. package/lib/payment/datatrans-v2/splitProperties.js.map +0 -1
  157. package/lib/payment/invoice-prepaid.d.ts +0 -1
  158. package/lib/payment/invoice-prepaid.js +0 -30
  159. package/lib/payment/invoice-prepaid.js.map +0 -1
  160. package/lib/payment/invoice.d.ts +0 -1
  161. package/lib/payment/invoice.js +0 -27
  162. package/lib/payment/invoice.js.map +0 -1
  163. package/lib/payment/paypal-checkout.d.ts +0 -1
  164. package/lib/payment/paypal-checkout.js +0 -82
  165. package/lib/payment/paypal-checkout.js.map +0 -1
  166. package/lib/payment/postfinance-checkout/api.d.ts +0 -11
  167. package/lib/payment/postfinance-checkout/api.js +0 -109
  168. package/lib/payment/postfinance-checkout/api.js.map +0 -1
  169. package/lib/payment/postfinance-checkout/index.d.ts +0 -1
  170. package/lib/payment/postfinance-checkout/index.js +0 -186
  171. package/lib/payment/postfinance-checkout/index.js.map +0 -1
  172. package/lib/payment/postfinance-checkout/middleware.d.ts +0 -1
  173. package/lib/payment/postfinance-checkout/middleware.js +0 -42
  174. package/lib/payment/postfinance-checkout/middleware.js.map +0 -1
  175. package/lib/payment/postfinance-checkout/types.d.ts +0 -23
  176. package/lib/payment/postfinance-checkout/types.js +0 -12
  177. package/lib/payment/postfinance-checkout/types.js.map +0 -1
  178. package/lib/payment/postfinance-checkout/utils.d.ts +0 -4
  179. package/lib/payment/postfinance-checkout/utils.js +0 -20
  180. package/lib/payment/postfinance-checkout/utils.js.map +0 -1
  181. package/lib/payment/stripe.d.ts +0 -1
  182. package/lib/payment/stripe.js +0 -214
  183. package/lib/payment/stripe.js.map +0 -1
  184. package/lib/payment/worldline-saferpay/index.d.ts +0 -1
  185. package/lib/payment/worldline-saferpay/index.js +0 -112
  186. package/lib/payment/worldline-saferpay/index.js.map +0 -1
  187. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.d.ts +0 -14
  188. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js +0 -29
  189. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js.map +0 -1
  190. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.d.ts +0 -9
  191. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js +0 -28
  192. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js.map +0 -1
  193. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.d.ts +0 -4
  194. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js +0 -2
  195. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js.map +0 -1
  196. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.d.ts +0 -1
  197. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js +0 -2
  198. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js.map +0 -1
  199. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.d.ts +0 -73
  200. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js +0 -2
  201. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js.map +0 -1
  202. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.d.ts +0 -53
  203. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js +0 -2
  204. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js.map +0 -1
  205. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.d.ts +0 -13
  206. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js +0 -2
  207. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js.map +0 -1
  208. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.d.ts +0 -9
  209. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js +0 -2
  210. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js.map +0 -1
  211. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.d.ts +0 -5
  212. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js +0 -2
  213. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js.map +0 -1
  214. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.d.ts +0 -13
  215. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js +0 -2
  216. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js.map +0 -1
  217. package/lib/pricing/delivery-swiss-tax.d.ts +0 -15
  218. package/lib/pricing/delivery-swiss-tax.js +0 -98
  219. package/lib/pricing/delivery-swiss-tax.js.map +0 -1
  220. package/lib/pricing/discount-100-off.d.ts +0 -1
  221. package/lib/pricing/discount-100-off.js +0 -34
  222. package/lib/pricing/discount-100-off.js.map +0 -1
  223. package/lib/pricing/discount-half-price-manual.d.ts +0 -1
  224. package/lib/pricing/discount-half-price-manual.js +0 -34
  225. package/lib/pricing/discount-half-price-manual.js.map +0 -1
  226. package/lib/pricing/discount-half-price.d.ts +0 -1
  227. package/lib/pricing/discount-half-price.js +0 -37
  228. package/lib/pricing/discount-half-price.js.map +0 -1
  229. package/lib/pricing/free-delivery.d.ts +0 -2
  230. package/lib/pricing/free-delivery.js +0 -26
  231. package/lib/pricing/free-delivery.js.map +0 -1
  232. package/lib/pricing/free-payment.d.ts +0 -2
  233. package/lib/pricing/free-payment.js +0 -26
  234. package/lib/pricing/free-payment.js.map +0 -1
  235. package/lib/pricing/order-delivery.d.ts +0 -1
  236. package/lib/pricing/order-delivery.js +0 -33
  237. package/lib/pricing/order-delivery.js.map +0 -1
  238. package/lib/pricing/order-discount.d.ts +0 -1
  239. package/lib/pricing/order-discount.js +0 -110
  240. package/lib/pricing/order-discount.js.map +0 -1
  241. package/lib/pricing/order-items-discount.d.ts +0 -1
  242. package/lib/pricing/order-items-discount.js +0 -88
  243. package/lib/pricing/order-items-discount.js.map +0 -1
  244. package/lib/pricing/order-items.d.ts +0 -1
  245. package/lib/pricing/order-items.js +0 -44
  246. package/lib/pricing/order-items.js.map +0 -1
  247. package/lib/pricing/order-payment.d.ts +0 -1
  248. package/lib/pricing/order-payment.js +0 -33
  249. package/lib/pricing/order-payment.js.map +0 -1
  250. package/lib/pricing/product-catalog-price.d.ts +0 -1
  251. package/lib/pricing/product-catalog-price.js +0 -37
  252. package/lib/pricing/product-catalog-price.js.map +0 -1
  253. package/lib/pricing/product-discount.d.ts +0 -1
  254. package/lib/pricing/product-discount.js +0 -55
  255. package/lib/pricing/product-discount.js.map +0 -1
  256. package/lib/pricing/product-price-ECB-interbank-exchange.d.ts +0 -1
  257. package/lib/pricing/product-price-ECB-interbank-exchange.js +0 -90
  258. package/lib/pricing/product-price-ECB-interbank-exchange.js.map +0 -1
  259. package/lib/pricing/product-price-coinbase-exchange.d.ts +0 -1
  260. package/lib/pricing/product-price-coinbase-exchange.js +0 -60
  261. package/lib/pricing/product-price-coinbase-exchange.js.map +0 -1
  262. package/lib/pricing/product-price-cryptopay.d.ts +0 -1
  263. package/lib/pricing/product-price-cryptopay.js +0 -21
  264. package/lib/pricing/product-price-cryptopay.js.map +0 -1
  265. package/lib/pricing/product-price-rateconversion.d.ts +0 -1
  266. package/lib/pricing/product-price-rateconversion.js +0 -51
  267. package/lib/pricing/product-price-rateconversion.js.map +0 -1
  268. package/lib/pricing/product-price-round.d.ts +0 -11
  269. package/lib/pricing/product-price-round.js +0 -54
  270. package/lib/pricing/product-price-round.js.map +0 -1
  271. package/lib/pricing/product-swiss-tax.d.ts +0 -13
  272. package/lib/pricing/product-swiss-tax.js +0 -102
  273. package/lib/pricing/product-swiss-tax.js.map +0 -1
  274. package/lib/pricing/utils/cache.d.ts +0 -8
  275. package/lib/pricing/utils/cache.js +0 -28
  276. package/lib/pricing/utils/cache.js.map +0 -1
  277. package/lib/quotations/manual.d.ts +0 -1
  278. package/lib/quotations/manual.js +0 -21
  279. package/lib/quotations/manual.js.map +0 -1
  280. package/lib/warehousing/google-sheets.d.ts +0 -1
  281. package/lib/warehousing/google-sheets.js +0 -153
  282. package/lib/warehousing/google-sheets.js.map +0 -1
  283. package/lib/warehousing/store.d.ts +0 -1
  284. package/lib/warehousing/store.js +0 -33
  285. package/lib/warehousing/store.js.map +0 -1
  286. package/lib/worker/BulkImportWorker.d.ts +0 -2
  287. package/lib/worker/BulkImportWorker.js +0 -91
  288. package/lib/worker/BulkImportWorker.js.map +0 -1
  289. package/lib/worker/GenerateOrderWorker.d.ts +0 -1
  290. package/lib/worker/GenerateOrderWorker.js +0 -110
  291. package/lib/worker/GenerateOrderWorker.js.map +0 -1
  292. package/lib/worker/MessageWorker.js +0 -45
  293. package/lib/worker/MessageWorker.js.map +0 -1
  294. package/lib/worker/ZombieKillerWorker.d.ts +0 -7
  295. package/lib/worker/ZombieKillerWorker.js +0 -88
  296. package/lib/worker/ZombieKillerWorker.js.map +0 -1
  297. package/lib/worker/email.d.ts +0 -1
  298. package/lib/worker/email.js +0 -96
  299. package/lib/worker/email.js.map +0 -1
  300. package/lib/worker/external.d.ts +0 -2
  301. package/lib/worker/external.js +0 -13
  302. package/lib/worker/external.js.map +0 -1
  303. package/lib/worker/heartbeat.d.ts +0 -1
  304. package/lib/worker/heartbeat.js +0 -32
  305. package/lib/worker/heartbeat.js.map +0 -1
  306. package/lib/worker/http-request.d.ts +0 -8
  307. package/lib/worker/http-request.js +0 -61
  308. package/lib/worker/http-request.js.map +0 -1
  309. package/lib/worker/sms.d.ts +0 -1
  310. package/lib/worker/sms.js +0 -69
  311. package/lib/worker/sms.js.map +0 -1
  312. package/license +0 -274
  313. package/src/files/gridfs/gridfs-webhook.js +0 -60
  314. package/tsconfig.build.json +0 -26
@@ -91,7 +91,7 @@ const BraintreeDirect: IPaymentAdapter = {
91
91
  },
92
92
 
93
93
  sign: async () => {
94
- const braintree = require('braintree'); // eslint-disable-line
94
+ const braintree = (await import('braintree')).default; // eslint-disable-line
95
95
  const gateway = getGateway(braintree);
96
96
  const result = await gateway.clientToken.generate({});
97
97
  if (result.success) {
@@ -105,7 +105,7 @@ const BraintreeDirect: IPaymentAdapter = {
105
105
  const { order } = params.paymentContext;
106
106
  if (!paypalPaymentMethodNonce)
107
107
  throw new Error('You have to provide paypalPaymentMethodNonce in paymentContext');
108
- const braintree = require('braintree'); // eslint-disable-line
108
+ const braintree = (await import('braintree')).default; // eslint-disable-line
109
109
  const gateway = getGateway(braintree);
110
110
  const address = order.billingAddress || {};
111
111
  const pricing = modules.orders.pricingSheet(order);
@@ -14,7 +14,7 @@ const logger = createLogger('unchained:core-payment:cryptopay');
14
14
 
15
15
  const {
16
16
  CRYPTOPAY_SECRET,
17
- CRYPTOPAY_WEBHOOK_PATH = '/graphql/cryptopay',
17
+ CRYPTOPAY_WEBHOOK_PATH = '/payment/cryptopay',
18
18
  CRYPTOPAY_BTC_XPUB,
19
19
  CRYPTOPAY_ETH_XPUB,
20
20
  CRYPTOPAY_BTC_TESTNET = false,
@@ -30,79 +30,81 @@ enum CryptopayCurrencies { // eslint-disable-line
30
30
  const MAX_RATE_AGE = parseInt(CRYPTOPAY_MAX_RATE_AGE, 10);
31
31
  const MAX_ALLOWED_DIFF = parseFloat(CRYPTOPAY_MAX_CONV_DIFF); // Accept payments when the converted amount differs by adapterActions much (in percent)
32
32
 
33
- useMiddlewareWithCurrentContext(CRYPTOPAY_WEBHOOK_PATH, bodyParser.json());
34
-
35
- useMiddlewareWithCurrentContext(CRYPTOPAY_WEBHOOK_PATH, async (request, response) => {
36
- // Return a 200 response to acknowledge receipt of the event
37
- const resolvedContext = request.unchainedContext as Context;
38
- const { currency, contract, decimals, address, amount, secret } = request.body;
39
- if (secret !== CRYPTOPAY_SECRET) {
40
- logger.warn(`Cryptopay Plugin: Invalid Cryptopay Secret provided`);
41
- response.end(JSON.stringify({ success: false }));
42
- return;
43
- }
44
- const orderPayment = await resolvedContext.modules.orders.payments.findOrderPaymentByContextData({
45
- context: { currency, address },
46
- });
47
- if (orderPayment) {
48
- if (currency === CryptopayCurrencies.ETH && contract && contract !== '') {
49
- const ERC20CurrencyCount = await resolvedContext.modules.currencies.count({
50
- includeInactive: false,
51
- contractAddress: contract,
52
- });
53
- if (!ERC20CurrencyCount) {
54
- logger.warn(`Cryptopay Plugin: ERC20 token address ${contract} not whitelisted.`);
55
- response.end(JSON.stringify({ success: false }));
56
- return;
57
- }
33
+ export default (app) => {
34
+ useMiddlewareWithCurrentContext(app, CRYPTOPAY_WEBHOOK_PATH, bodyParser.json());
35
+
36
+ useMiddlewareWithCurrentContext(app, CRYPTOPAY_WEBHOOK_PATH, async (request, response) => {
37
+ // Return a 200 response to acknowledge receipt of the event
38
+ const resolvedContext = request.unchainedContext as Context;
39
+ const { currency, contract, decimals, address, amount, secret } = request.body;
40
+ if (secret !== CRYPTOPAY_SECRET) {
41
+ logger.warn(`Cryptopay Plugin: Invalid Cryptopay Secret provided`);
42
+ response.end(JSON.stringify({ success: false }));
43
+ return;
58
44
  }
59
- const order = await resolvedContext.modules.orders.findOrder({
60
- orderId: orderPayment.orderId,
45
+ const orderPayment = await resolvedContext.modules.orders.payments.findOrderPaymentByContextData({
46
+ context: { currency, address },
61
47
  });
62
- const pricing = OrderPricingSheet({
63
- calculation: order.calculation,
64
- currency: order.currency,
65
- });
66
- const totalAmount = pricing?.total({ useNetPrice: false }).amount;
67
- let convertedAmount: number;
68
- if (order.currency === currency) {
69
- convertedAmount = amount / 10 ** (decimals - 8); // All crypto native prices denoted with 8 decimals
70
- } else {
71
- // Need to convert
72
- const rate = await resolvedContext.modules.products.prices.rates.getRate(
73
- order.currency,
74
- contract && contract !== '' ? contract : currency, // Convert to the smart contract if given
75
- MAX_RATE_AGE,
76
- );
77
- if (rate) {
78
- // We assume that we are converting to a fiat currency here (with 2 decimals).
79
- // Paying an order with prices in crypto in another crypto is not supported.
80
- convertedAmount = Math.round((amount / 10 ** decimals) * rate * 100);
48
+ if (orderPayment) {
49
+ if (currency === CryptopayCurrencies.ETH && contract && contract !== '') {
50
+ const ERC20CurrencyCount = await resolvedContext.modules.currencies.count({
51
+ includeInactive: false,
52
+ contractAddress: contract,
53
+ });
54
+ if (!ERC20CurrencyCount) {
55
+ logger.warn(`Cryptopay Plugin: ERC20 token address ${contract} not whitelisted.`);
56
+ response.end(JSON.stringify({ success: false }));
57
+ return;
58
+ }
59
+ }
60
+ const order = await resolvedContext.modules.orders.findOrder({
61
+ orderId: orderPayment.orderId,
62
+ });
63
+ const pricing = OrderPricingSheet({
64
+ calculation: order.calculation,
65
+ currency: order.currency,
66
+ });
67
+ const totalAmount = pricing?.total({ useNetPrice: false }).amount;
68
+ let convertedAmount: number;
69
+ if (order.currency === currency) {
70
+ convertedAmount = amount / 10 ** (decimals - 8); // All crypto native prices denoted with 8 decimals
71
+ } else {
72
+ // Need to convert
73
+ const rate = await resolvedContext.modules.products.prices.rates.getRate(
74
+ order.currency,
75
+ contract && contract !== '' ? contract : currency, // Convert to the smart contract if given
76
+ MAX_RATE_AGE,
77
+ );
78
+ if (rate) {
79
+ // We assume that we are converting to a fiat currency here (with 2 decimals).
80
+ // Paying an order with prices in crypto in another crypto is not supported.
81
+ convertedAmount = Math.round((amount / 10 ** decimals) * rate * 100);
82
+ }
83
+ }
84
+ if (convertedAmount && convertedAmount >= totalAmount * (1 - MAX_ALLOWED_DIFF)) {
85
+ await resolvedContext.modules.orders.checkout(
86
+ order._id,
87
+ {
88
+ transactionContext: { address },
89
+ paymentContext: { address },
90
+ },
91
+ resolvedContext,
92
+ );
93
+ response.end(JSON.stringify({ success: true }));
94
+ } else {
95
+ logger.warn(
96
+ `Cryptopay Plugin: OrderPayment ${orderPayment._id} not marked as paid. Converted amount is ${convertedAmount}`,
97
+ );
98
+ response.end(JSON.stringify({ success: false }));
81
99
  }
82
- }
83
- if (convertedAmount && convertedAmount >= totalAmount * (1 - MAX_ALLOWED_DIFF)) {
84
- await resolvedContext.modules.orders.checkout(
85
- order._id,
86
- {
87
- transactionContext: { address },
88
- paymentContext: { address },
89
- },
90
- resolvedContext,
91
- );
92
- response.end(JSON.stringify({ success: true }));
93
100
  } else {
94
- logger.warn(
95
- `Cryptopay Plugin: OrderPayment ${orderPayment._id} not marked as paid. Converted amount is ${convertedAmount}`,
101
+ logger.info(
102
+ `Cryptopay Plugin: No orderPayment with address ${address} and currency ${currency} found`,
96
103
  );
97
104
  response.end(JSON.stringify({ success: false }));
98
105
  }
99
- } else {
100
- logger.info(
101
- `Cryptopay Plugin: No orderPayment with address ${address} and currency ${currency} found`,
102
- );
103
- response.end(JSON.stringify({ success: false }));
104
- }
105
- });
106
+ });
107
+ };
106
108
 
107
109
  const Cryptopay: IPaymentAdapter = {
108
110
  ...PaymentAdapter,
@@ -10,12 +10,14 @@ import type {
10
10
  StatusResponseSuccess,
11
11
  ValidateResponseSuccess,
12
12
  } from './api/types';
13
- import './middleware';
13
+ import setupDatatrans from './middleware';
14
14
  import parseRegistrationData from './parseRegistrationData';
15
15
  import roundedAmountFromOrder from './roundedAmountFromOrder';
16
16
 
17
17
  const logger = createLogger('unchained:core-payment:datatrans');
18
18
 
19
+ export default setupDatatrans;
20
+
19
21
  // v2
20
22
  const { DATATRANS_SECRET, DATATRANS_SIGN_KEY, DATATRANS_API_ENDPOINT, DATATRANS_MERCHANT_ID } =
21
23
  process.env;
@@ -17,131 +17,137 @@ const logger = createLogger('unchained:core-payment:datatrans');
17
17
 
18
18
  const { postUrl, cancelUrl, errorUrl, successUrl, returnUrl } = getPaths(true);
19
19
 
20
- useMiddlewareWithCurrentContext(
21
- postUrl,
22
- bodyParser.text({
23
- type: 'application/json',
24
- }),
25
- );
26
-
27
- useMiddlewareWithCurrentContext(cancelUrl, bodyParser.urlencoded({ extended: false }));
28
-
29
- useMiddlewareWithCurrentContext(errorUrl, bodyParser.urlencoded({ extended: false }));
30
-
31
- useMiddlewareWithCurrentContext(successUrl, bodyParser.urlencoded({ extended: false }));
32
-
33
- useMiddlewareWithCurrentContext(returnUrl, bodyParser.urlencoded({ extended: false }));
34
-
35
- useMiddlewareWithCurrentContext(postUrl, async (req, res) => {
36
- const resolvedContext = req.unchainedContext as Context;
37
- const { services, modules } = resolvedContext;
38
- const signature = req.headers['datatrans-signature'];
39
- if (req.method === 'POST' && signature) {
40
- const [rawTimestamp, rawHash] = signature.split(',');
41
- const [, hash] = rawHash.split('=');
42
- const [, timestamp] = rawTimestamp.split('=');
43
-
44
- const comparableSignature = generateSignature({
45
- security: DATATRANS_SECURITY,
46
- signKey: DATATRANS_SIGN2_KEY || DATATRANS_SIGN_KEY,
47
- })(timestamp, req.body);
48
-
49
- if (hash !== comparableSignature) {
50
- logger.error(`Datatrans Plugin: Hash mismatch: ${signature} / ${comparableSignature}`, req.body);
51
- res.writeHead(403);
52
- res.end('Hash mismatch');
53
- return;
54
- }
20
+ export default (app) => {
21
+ useMiddlewareWithCurrentContext(
22
+ app,
23
+ postUrl,
24
+ bodyParser.text({
25
+ type: 'application/json',
26
+ }),
27
+ );
28
+
29
+ useMiddlewareWithCurrentContext(app, cancelUrl, bodyParser.urlencoded({ extended: false }));
30
+
31
+ useMiddlewareWithCurrentContext(app, errorUrl, bodyParser.urlencoded({ extended: false }));
32
+
33
+ useMiddlewareWithCurrentContext(app, successUrl, bodyParser.urlencoded({ extended: false }));
34
+
35
+ useMiddlewareWithCurrentContext(app, returnUrl, bodyParser.urlencoded({ extended: false }));
36
+
37
+ useMiddlewareWithCurrentContext(app, postUrl, async (req, res) => {
38
+ const resolvedContext = req.unchainedContext as Context;
39
+ const { services, modules } = resolvedContext;
40
+ const signature = req.headers['datatrans-signature'];
41
+ if (req.method === 'POST' && signature) {
42
+ const [rawTimestamp, rawHash] = signature.split(',');
43
+ const [, hash] = rawHash.split('=');
44
+ const [, timestamp] = rawTimestamp.split('=');
45
+
46
+ const comparableSignature = generateSignature({
47
+ security: DATATRANS_SECURITY,
48
+ signKey: DATATRANS_SIGN2_KEY || DATATRANS_SIGN_KEY,
49
+ })(timestamp, req.body);
50
+
51
+ if (hash !== comparableSignature) {
52
+ logger.error(`Datatrans Plugin: Hash mismatch: ${signature} / ${comparableSignature}`, req.body);
53
+ res.writeHead(403);
54
+ res.end('Hash mismatch');
55
+ return;
56
+ }
55
57
 
56
- const transaction: StatusResponseSuccess = JSON.parse(req.body) as StatusResponseSuccess;
57
-
58
- if (transaction.status === 'authorized') {
59
- const userId = transaction.refno2;
60
- const referenceId = Buffer.from(transaction.refno, 'base64').toString('hex');
61
-
62
- try {
63
- if (transaction.type === 'card_check') {
64
- const paymentProviderId = referenceId;
65
- const paymentCredentials = await services.payment.registerPaymentCredentials(
66
- paymentProviderId,
67
- { transactionContext: { transactionId: transaction.transactionId } },
68
- { ...resolvedContext, userId },
69
- );
70
- logger.info(`Datatrans Webhook: Unchained registered payment credentials for ${userId}`, {
71
- userId,
72
- });
73
- res.writeHead(200);
74
- res.end(JSON.stringify(paymentCredentials));
58
+ const transaction: StatusResponseSuccess = JSON.parse(req.body) as StatusResponseSuccess;
59
+
60
+ if (transaction.status === 'authorized') {
61
+ const userId = transaction.refno2;
62
+ const referenceId = Buffer.from(transaction.refno, 'base64').toString('hex');
63
+
64
+ try {
65
+ if (transaction.type === 'card_check') {
66
+ const paymentProviderId = referenceId;
67
+ const paymentCredentials = await services.payment.registerPaymentCredentials(
68
+ paymentProviderId,
69
+ { transactionContext: { transactionId: transaction.transactionId } },
70
+ { ...resolvedContext, userId },
71
+ );
72
+ logger.info(`Datatrans Webhook: Unchained registered payment credentials for ${userId}`, {
73
+ userId,
74
+ });
75
+ res.writeHead(200);
76
+ res.end(JSON.stringify(paymentCredentials));
77
+ return;
78
+ }
79
+ if (transaction.type === 'payment') {
80
+ const orderPaymentId = referenceId;
81
+ const orderPayment = await modules.orders.payments.findOrderPayment({
82
+ orderPaymentId,
83
+ });
84
+ if (!orderPayment) throw new Error(`Order Payment with id ${orderPaymentId} not found`);
85
+
86
+ const order = await modules.orders.checkout(
87
+ orderPayment.orderId,
88
+ { paymentContext: { transactionId: transaction.transactionId } },
89
+ { ...resolvedContext, userId },
90
+ );
91
+ res.writeHead(200);
92
+ logger.info(
93
+ `Datatrans Webhook: Unchained confirmed checkout for order ${order.orderNumber}`,
94
+ {
95
+ orderId: order._id,
96
+ },
97
+ );
98
+ res.end(JSON.stringify(order));
99
+ return;
100
+ }
101
+ } catch (e) {
102
+ logger.error(`Datatrans Webhook: Unchained rejected to checkout with message`, e);
103
+ res.writeHead(500);
104
+ res.end(JSON.stringify(e));
75
105
  return;
76
106
  }
77
- if (transaction.type === 'payment') {
78
- const orderPaymentId = referenceId;
79
- const orderPayment = await modules.orders.payments.findOrderPayment({
80
- orderPaymentId,
81
- });
82
- if (!orderPayment) throw new Error(`Order Payment with id ${orderPaymentId} not found`);
83
-
84
- const order = await modules.orders.checkout(
85
- orderPayment.orderId,
86
- { paymentContext: { transactionId: transaction.transactionId } },
87
- resolvedContext,
88
- );
89
- res.writeHead(200);
90
- logger.info(`Datatrans Webhook: Unchained confirmed checkout for order ${order.orderNumber}`, {
91
- orderId: order._id,
92
- });
93
- res.end(JSON.stringify(order));
94
- return;
95
- }
96
- } catch (e) {
97
- logger.error(`Datatrans Webhook: Unchained rejected to checkout with message`, e);
98
- res.writeHead(500);
99
- res.end(JSON.stringify(e));
100
- return;
101
107
  }
102
108
  }
103
- }
104
- res.writeHead(404);
105
- res.end();
106
- });
107
-
108
- useMiddlewareWithCurrentContext(successUrl, async (req, res) => {
109
- if (req.method === 'GET') {
110
- const { datatransTrxId } = req.query;
111
- res.end(`Payment successful\nTransaction ID: ${datatransTrxId}`);
112
- return;
113
- }
114
- res.writeHead(404);
115
- res.end();
116
- });
117
-
118
- useMiddlewareWithCurrentContext(errorUrl, async (req, res) => {
119
- if (req.method === 'GET') {
120
- const { datatransTrxId } = req.query;
121
- res.end(`Payment error\nTransaction ID: ${datatransTrxId}`);
122
- return;
123
- }
124
- res.writeHead(404);
125
- res.end();
126
- });
127
-
128
- useMiddlewareWithCurrentContext(cancelUrl, async (req, res) => {
129
- if (req.method === 'GET') {
130
- const { datatransTrxId } = req.query;
131
- res.end(`Payment cancelled\nTransaction ID: ${datatransTrxId}`);
132
- return;
133
- }
134
- res.writeHead(404);
135
- res.end();
136
- });
137
-
138
- useMiddlewareWithCurrentContext(returnUrl, async (req, res) => {
139
- if (req.method === 'GET') {
140
- const { datatransTrxId } = req.query;
141
- res.end(
142
- `Secure Fields Payment authenticated\nTransaction ID: ${datatransTrxId}\nNeeds authorization`,
143
- );
144
- }
145
- res.writeHead(404);
146
- res.end();
147
- });
109
+ res.writeHead(404);
110
+ res.end();
111
+ });
112
+
113
+ useMiddlewareWithCurrentContext(app, successUrl, async (req, res) => {
114
+ if (req.method === 'GET') {
115
+ const { datatransTrxId } = req.query;
116
+ res.end(`Payment successful\nTransaction ID: ${datatransTrxId}`);
117
+ return;
118
+ }
119
+ res.writeHead(404);
120
+ res.end();
121
+ });
122
+
123
+ useMiddlewareWithCurrentContext(app, errorUrl, async (req, res) => {
124
+ if (req.method === 'GET') {
125
+ const { datatransTrxId } = req.query;
126
+ res.end(`Payment error\nTransaction ID: ${datatransTrxId}`);
127
+ return;
128
+ }
129
+ res.writeHead(404);
130
+ res.end();
131
+ });
132
+
133
+ useMiddlewareWithCurrentContext(app, cancelUrl, async (req, res) => {
134
+ if (req.method === 'GET') {
135
+ const { datatransTrxId } = req.query;
136
+ res.end(`Payment cancelled\nTransaction ID: ${datatransTrxId}`);
137
+ return;
138
+ }
139
+ res.writeHead(404);
140
+ res.end();
141
+ });
142
+
143
+ useMiddlewareWithCurrentContext(app, returnUrl, async (req, res) => {
144
+ if (req.method === 'GET') {
145
+ const { datatransTrxId } = req.query;
146
+ res.end(
147
+ `Secure Fields Payment authenticated\nTransaction ID: ${datatransTrxId}\nNeeds authorization`,
148
+ );
149
+ }
150
+ res.writeHead(404);
151
+ res.end();
152
+ });
153
+ };
@@ -2,7 +2,7 @@ import { IPaymentAdapter } from '@unchainedshop/types/payments';
2
2
  import { PaymentDirector, PaymentAdapter, PaymentError } from '@unchainedshop/core-payment';
3
3
  import { createLogger } from '@unchainedshop/logger';
4
4
 
5
- const checkoutNodeJssdk = require('@paypal/checkout-server-sdk'); // eslint-disable-line
5
+ import checkoutNodeJssdk from '@paypal/checkout-server-sdk'; // eslint-disable-line
6
6
 
7
7
  const logger = createLogger('unchained:core-payment');
8
8
 
@@ -17,9 +17,11 @@ import {
17
17
  voidTransaction,
18
18
  } from './api';
19
19
  import { orderIsPaid } from './utils';
20
- import './middleware';
20
+ import setupPostfinance from './middleware';
21
21
  import { CompletionModes, IntegrationModes, SignResponse } from './types';
22
22
 
23
+ export default setupPostfinance;
24
+
23
25
  const {
24
26
  PFCHECKOUT_SPACE_ID,
25
27
  PFCHECKOUT_USER_ID,
@@ -5,50 +5,52 @@ import { createLogger } from '@unchainedshop/logger';
5
5
  import { WebhookData } from './types';
6
6
  import { getTransaction, getTransactionCompletion } from './api';
7
7
 
8
- const { PFCHECKOUT_WEBHOOK_PATH = '/graphql/postfinance-checkout' } = process.env;
8
+ const { PFCHECKOUT_WEBHOOK_PATH = '/payment/postfinance-checkout' } = process.env;
9
9
 
10
10
  const logger = createLogger('unchained:core-payment:postfinance-checkout');
11
11
 
12
- useMiddlewareWithCurrentContext(PFCHECKOUT_WEBHOOK_PATH, bodyParser.json());
12
+ export default (app) => {
13
+ useMiddlewareWithCurrentContext(app, PFCHECKOUT_WEBHOOK_PATH, bodyParser.json());
13
14
 
14
- useMiddlewareWithCurrentContext(PFCHECKOUT_WEBHOOK_PATH, async (req, res) => {
15
- const context = req.unchainedContext as Context;
16
- const data = req.body as WebhookData;
17
- if (data.listenerEntityTechnicalName === 'TransactionCompletion') {
18
- try {
19
- const transactionCompletion = await getTransactionCompletion(data.entityId as unknown as string);
20
- const transaction = await getTransaction(
21
- transactionCompletion.linkedTransaction as unknown as string,
22
- );
23
- const { orderPaymentId } = transaction.metaData as { orderPaymentId: string };
24
- const orderPayment = await context.modules.orders.payments.findOrderPayment({
25
- orderPaymentId,
26
- });
27
- if (!orderPayment) throw new Error('Order Payment not found');
28
- const order = await context.modules.orders.checkout(
29
- orderPayment.orderId,
30
- {
31
- paymentContext: {
32
- transactionId: transactionCompletion.linkedTransaction,
15
+ useMiddlewareWithCurrentContext(app, PFCHECKOUT_WEBHOOK_PATH, async (req, res) => {
16
+ const context = req.unchainedContext as 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 context.modules.orders.payments.findOrderPayment({
26
+ orderPaymentId,
27
+ });
28
+ if (!orderPayment) throw new Error('Order Payment not found');
29
+ const order = await context.modules.orders.checkout(
30
+ orderPayment.orderId,
31
+ {
32
+ paymentContext: {
33
+ transactionId: transactionCompletion.linkedTransaction,
34
+ },
33
35
  },
34
- },
35
- context,
36
- );
37
- logger.info(
38
- `PostFinance Checkout Webhook: Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
36
+ context,
37
+ );
38
+ logger.info(
39
+ `PostFinance Checkout Webhook: Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
40
+ );
41
+ res.writeHead(200);
42
+ res.end(`Order marked as paid: ${order.orderNumber}`);
43
+ } catch (e) {
44
+ logger.error(`PostFinance Checkout Webhook: Unchained rejected to checkout with message`, e);
45
+ res.writeHead(500);
46
+ res.end(JSON.stringify(e));
47
+ }
48
+ } else {
49
+ logger.error(
50
+ `PostFinance Checkout Webhook: Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`,
39
51
  );
40
- res.writeHead(200);
41
- res.end(`Order marked as paid: ${order.orderNumber}`);
42
- } catch (e) {
43
- logger.error(`PostFinance Checkout Webhook: Unchained rejected to checkout with message`, e);
44
- res.writeHead(500);
45
- res.end(JSON.stringify(e));
52
+ res.writeHead(404);
53
+ res.end();
46
54
  }
47
- } else {
48
- logger.error(
49
- `PostFinance Checkout Webhook: Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`,
50
- );
51
- res.writeHead(404);
52
- res.end();
53
- }
54
- });
55
+ });
56
+ };