@unchainedshop/plugins 1.1.3 → 1.1.7

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 (332) hide show
  1. package/lib/delivery/pick-mup.d.ts +1 -0
  2. package/lib/delivery/pick-mup.js +98 -0
  3. package/lib/delivery/pick-mup.js.map +1 -0
  4. package/lib/delivery/post.d.ts +1 -0
  5. package/lib/delivery/post.js +23 -0
  6. package/lib/delivery/post.js.map +1 -0
  7. package/lib/delivery/send-message.d.ts +1 -0
  8. package/lib/delivery/send-message.js +41 -0
  9. package/lib/delivery/send-message.js.map +1 -0
  10. package/lib/delivery/stores.d.ts +1 -0
  11. package/lib/delivery/stores.js +39 -0
  12. package/lib/delivery/stores.js.map +1 -0
  13. package/lib/enrollments/licensed.d.ts +1 -0
  14. package/lib/enrollments/licensed.js +40 -0
  15. package/lib/enrollments/licensed.js.map +1 -0
  16. package/lib/files/gridfs/gridfs-adapter.js +1 -1
  17. package/lib/files/gridfs/gridfs-adapter.js.map +1 -1
  18. package/lib/files/gridfs/gridfs-webhook.js +2 -2
  19. package/lib/files/gridfs/gridfs-webhook.js.map +1 -1
  20. package/lib/files/minio/minio-webhook.js +1 -1
  21. package/lib/files/minio/minio-webhook.js.map +1 -1
  22. package/lib/filters/local-search.d.ts +3 -0
  23. package/lib/filters/local-search.js +84 -0
  24. package/lib/filters/local-search.js.map +1 -0
  25. package/lib/filters/strict-equal.d.ts +1 -0
  26. package/lib/filters/strict-equal.js +25 -0
  27. package/lib/filters/strict-equal.js.map +1 -0
  28. package/lib/payment/apple-iap/adapter.d.ts +1 -0
  29. package/lib/payment/apple-iap/adapter.js +284 -0
  30. package/lib/payment/apple-iap/adapter.js.map +1 -0
  31. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +7 -0
  32. package/lib/payment/apple-iap/db/AppleTransactionsCollection.js +5 -0
  33. package/lib/payment/apple-iap/db/AppleTransactionsCollection.js.map +1 -0
  34. package/lib/payment/apple-iap/index.d.ts +2 -0
  35. package/lib/payment/apple-iap/index.js +3 -0
  36. package/lib/payment/apple-iap/index.js.map +1 -0
  37. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
  38. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +18 -0
  39. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
  40. package/lib/payment/bity/adapter.d.ts +1 -0
  41. package/lib/payment/bity/adapter.js +316 -0
  42. package/lib/payment/bity/adapter.js.map +1 -0
  43. package/lib/payment/bity/db/BityCredentialsCollection.d.ts +11 -0
  44. package/lib/payment/bity/db/BityCredentialsCollection.js +5 -0
  45. package/lib/payment/bity/db/BityCredentialsCollection.js.map +1 -0
  46. package/lib/payment/bity/index.d.ts +2 -0
  47. package/lib/payment/bity/index.js +3 -0
  48. package/lib/payment/bity/index.js.map +1 -0
  49. package/lib/payment/bity/module/configureBityModule.d.ts +11 -0
  50. package/lib/payment/bity/module/configureBityModule.js +33 -0
  51. package/lib/payment/bity/module/configureBityModule.js.map +1 -0
  52. package/lib/payment/braintree.d.ts +1 -0
  53. package/lib/payment/braintree.js +129 -0
  54. package/lib/payment/braintree.js.map +1 -0
  55. package/lib/payment/cryptopay.d.ts +1 -0
  56. package/lib/payment/cryptopay.js +159 -0
  57. package/lib/payment/cryptopay.js.map +1 -0
  58. package/lib/payment/datatrans-v2/api/authorize.d.ts +2 -0
  59. package/lib/payment/datatrans-v2/api/authorize.js +12 -0
  60. package/lib/payment/datatrans-v2/api/authorize.js.map +1 -0
  61. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.d.ts +2 -0
  62. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js +11 -0
  63. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js.map +1 -0
  64. package/lib/payment/datatrans-v2/api/cancel.d.ts +2 -0
  65. package/lib/payment/datatrans-v2/api/cancel.js +10 -0
  66. package/lib/payment/datatrans-v2/api/cancel.js.map +1 -0
  67. package/lib/payment/datatrans-v2/api/index.d.ts +19 -0
  68. package/lib/payment/datatrans-v2/api/index.js +24 -0
  69. package/lib/payment/datatrans-v2/api/index.js.map +1 -0
  70. package/lib/payment/datatrans-v2/api/init.d.ts +2 -0
  71. package/lib/payment/datatrans-v2/api/init.js +31 -0
  72. package/lib/payment/datatrans-v2/api/init.js.map +1 -0
  73. package/lib/payment/datatrans-v2/api/makeFetcher.d.ts +2 -0
  74. package/lib/payment/datatrans-v2/api/makeFetcher.js +41 -0
  75. package/lib/payment/datatrans-v2/api/makeFetcher.js.map +1 -0
  76. package/lib/payment/datatrans-v2/api/secureFields.d.ts +2 -0
  77. package/lib/payment/datatrans-v2/api/secureFields.js +14 -0
  78. package/lib/payment/datatrans-v2/api/secureFields.js.map +1 -0
  79. package/lib/payment/datatrans-v2/api/settle.d.ts +2 -0
  80. package/lib/payment/datatrans-v2/api/settle.js +10 -0
  81. package/lib/payment/datatrans-v2/api/settle.js.map +1 -0
  82. package/lib/payment/datatrans-v2/api/status.d.ts +2 -0
  83. package/lib/payment/datatrans-v2/api/status.js +7 -0
  84. package/lib/payment/datatrans-v2/api/status.js.map +1 -0
  85. package/lib/payment/datatrans-v2/api/validate.d.ts +2 -0
  86. package/lib/payment/datatrans-v2/api/validate.js +10 -0
  87. package/lib/payment/datatrans-v2/api/validate.js.map +1 -0
  88. package/lib/payment/datatrans-v2/generateSignature.d.ts +10 -0
  89. package/lib/payment/datatrans-v2/generateSignature.js +19 -0
  90. package/lib/payment/datatrans-v2/generateSignature.js.map +1 -0
  91. package/lib/payment/datatrans-v2/getPaths.d.ts +9 -0
  92. package/lib/payment/datatrans-v2/getPaths.js +9 -0
  93. package/lib/payment/datatrans-v2/getPaths.js.map +1 -0
  94. package/lib/payment/datatrans-v2/index.d.ts +1 -0
  95. package/lib/payment/datatrans-v2/index.js +384 -0
  96. package/lib/payment/datatrans-v2/index.js.map +1 -0
  97. package/lib/payment/datatrans-v2/middleware.d.ts +1 -0
  98. package/lib/payment/datatrans-v2/middleware.js +111 -0
  99. package/lib/payment/datatrans-v2/middleware.js.map +1 -0
  100. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +11 -0
  101. package/lib/payment/datatrans-v2/parseRegistrationData.js +26 -0
  102. package/lib/payment/datatrans-v2/parseRegistrationData.js.map +1 -0
  103. package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +7 -0
  104. package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +10 -0
  105. package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -0
  106. package/lib/payment/datatrans-v2/splitProperties.d.ts +8 -0
  107. package/lib/payment/datatrans-v2/splitProperties.js +58 -0
  108. package/lib/payment/datatrans-v2/splitProperties.js.map +1 -0
  109. package/lib/payment/invoice-prepaid.d.ts +1 -0
  110. package/lib/payment/invoice-prepaid.js +30 -0
  111. package/lib/payment/invoice-prepaid.js.map +1 -0
  112. package/lib/payment/invoice.d.ts +1 -0
  113. package/lib/payment/invoice.js +27 -0
  114. package/lib/payment/invoice.js.map +1 -0
  115. package/lib/payment/paypal-checkout.d.ts +1 -0
  116. package/lib/payment/paypal-checkout.js +82 -0
  117. package/lib/payment/paypal-checkout.js.map +1 -0
  118. package/lib/payment/postfinance-checkout/api.d.ts +11 -0
  119. package/lib/payment/postfinance-checkout/api.js +109 -0
  120. package/lib/payment/postfinance-checkout/api.js.map +1 -0
  121. package/lib/payment/postfinance-checkout/index.d.ts +1 -0
  122. package/lib/payment/postfinance-checkout/index.js +186 -0
  123. package/lib/payment/postfinance-checkout/index.js.map +1 -0
  124. package/lib/payment/postfinance-checkout/middleware.d.ts +1 -0
  125. package/lib/payment/postfinance-checkout/middleware.js +42 -0
  126. package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
  127. package/lib/payment/postfinance-checkout/types.d.ts +23 -0
  128. package/lib/payment/postfinance-checkout/types.js +12 -0
  129. package/lib/payment/postfinance-checkout/types.js.map +1 -0
  130. package/lib/payment/postfinance-checkout/utils.d.ts +4 -0
  131. package/lib/payment/postfinance-checkout/utils.js +20 -0
  132. package/lib/payment/postfinance-checkout/utils.js.map +1 -0
  133. package/lib/payment/stripe.d.ts +1 -0
  134. package/lib/payment/stripe.js +214 -0
  135. package/lib/payment/stripe.js.map +1 -0
  136. package/lib/payment/worldline-saferpay/index.d.ts +1 -0
  137. package/lib/payment/worldline-saferpay/index.js +112 -0
  138. package/lib/payment/worldline-saferpay/index.js.map +1 -0
  139. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.d.ts +14 -0
  140. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js +29 -0
  141. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js.map +1 -0
  142. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.d.ts +9 -0
  143. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js +28 -0
  144. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js.map +1 -0
  145. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.d.ts +4 -0
  146. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js +2 -0
  147. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js.map +1 -0
  148. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.d.ts +1 -0
  149. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js +2 -0
  150. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js.map +1 -0
  151. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.d.ts +73 -0
  152. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js +2 -0
  153. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js.map +1 -0
  154. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.d.ts +53 -0
  155. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js +2 -0
  156. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js.map +1 -0
  157. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.d.ts +13 -0
  158. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js +2 -0
  159. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js.map +1 -0
  160. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.d.ts +9 -0
  161. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js +2 -0
  162. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js.map +1 -0
  163. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.d.ts +5 -0
  164. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js +2 -0
  165. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js.map +1 -0
  166. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.d.ts +13 -0
  167. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js +2 -0
  168. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js.map +1 -0
  169. package/lib/pricing/delivery-swiss-tax.d.ts +15 -0
  170. package/lib/pricing/delivery-swiss-tax.js +98 -0
  171. package/lib/pricing/delivery-swiss-tax.js.map +1 -0
  172. package/lib/pricing/discount-100-off.d.ts +1 -0
  173. package/lib/pricing/discount-100-off.js +34 -0
  174. package/lib/pricing/discount-100-off.js.map +1 -0
  175. package/lib/pricing/discount-half-price-manual.d.ts +1 -0
  176. package/lib/pricing/discount-half-price-manual.js +34 -0
  177. package/lib/pricing/discount-half-price-manual.js.map +1 -0
  178. package/lib/pricing/discount-half-price.d.ts +1 -0
  179. package/lib/pricing/discount-half-price.js +37 -0
  180. package/lib/pricing/discount-half-price.js.map +1 -0
  181. package/lib/pricing/free-delivery.d.ts +2 -0
  182. package/lib/pricing/free-delivery.js +26 -0
  183. package/lib/pricing/free-delivery.js.map +1 -0
  184. package/lib/pricing/free-payment.d.ts +2 -0
  185. package/lib/pricing/free-payment.js +26 -0
  186. package/lib/pricing/free-payment.js.map +1 -0
  187. package/lib/pricing/order-delivery.d.ts +1 -0
  188. package/lib/pricing/order-delivery.js +33 -0
  189. package/lib/pricing/order-delivery.js.map +1 -0
  190. package/lib/pricing/order-discount.d.ts +1 -0
  191. package/lib/pricing/order-discount.js +110 -0
  192. package/lib/pricing/order-discount.js.map +1 -0
  193. package/lib/pricing/order-items-discount.d.ts +1 -0
  194. package/lib/pricing/order-items-discount.js +88 -0
  195. package/lib/pricing/order-items-discount.js.map +1 -0
  196. package/lib/pricing/order-items.d.ts +1 -0
  197. package/lib/pricing/order-items.js +44 -0
  198. package/lib/pricing/order-items.js.map +1 -0
  199. package/lib/pricing/order-payment.d.ts +1 -0
  200. package/lib/pricing/order-payment.js +33 -0
  201. package/lib/pricing/order-payment.js.map +1 -0
  202. package/lib/pricing/product-catalog-price.d.ts +1 -0
  203. package/lib/pricing/product-catalog-price.js +37 -0
  204. package/lib/pricing/product-catalog-price.js.map +1 -0
  205. package/lib/pricing/product-discount.d.ts +1 -0
  206. package/lib/pricing/product-discount.js +55 -0
  207. package/lib/pricing/product-discount.js.map +1 -0
  208. package/lib/pricing/product-price-ECB-interbank-exchange.d.ts +1 -0
  209. package/lib/pricing/product-price-ECB-interbank-exchange.js +90 -0
  210. package/lib/pricing/product-price-ECB-interbank-exchange.js.map +1 -0
  211. package/lib/pricing/product-price-coinbase-exchange.d.ts +1 -0
  212. package/lib/pricing/product-price-coinbase-exchange.js +60 -0
  213. package/lib/pricing/product-price-coinbase-exchange.js.map +1 -0
  214. package/lib/pricing/product-price-cryptopay.d.ts +1 -0
  215. package/lib/pricing/product-price-cryptopay.js +21 -0
  216. package/lib/pricing/product-price-cryptopay.js.map +1 -0
  217. package/lib/pricing/product-price-rateconversion.d.ts +1 -0
  218. package/lib/pricing/product-price-rateconversion.js +51 -0
  219. package/lib/pricing/product-price-rateconversion.js.map +1 -0
  220. package/lib/pricing/product-price-round.d.ts +11 -0
  221. package/lib/pricing/product-price-round.js +54 -0
  222. package/lib/pricing/product-price-round.js.map +1 -0
  223. package/lib/pricing/product-swiss-tax.d.ts +13 -0
  224. package/lib/pricing/product-swiss-tax.js +102 -0
  225. package/lib/pricing/product-swiss-tax.js.map +1 -0
  226. package/lib/pricing/utils/cache.d.ts +8 -0
  227. package/lib/pricing/utils/cache.js +28 -0
  228. package/lib/pricing/utils/cache.js.map +1 -0
  229. package/lib/quotations/manual.d.ts +1 -0
  230. package/lib/quotations/manual.js +21 -0
  231. package/lib/quotations/manual.js.map +1 -0
  232. package/lib/warehousing/google-sheets.d.ts +1 -0
  233. package/lib/warehousing/google-sheets.js +153 -0
  234. package/lib/warehousing/google-sheets.js.map +1 -0
  235. package/lib/warehousing/store.d.ts +1 -0
  236. package/lib/warehousing/store.js +33 -0
  237. package/lib/warehousing/store.js.map +1 -0
  238. package/lib/worker/BulkImportWorker.js +3 -3
  239. package/lib/worker/BulkImportWorker.js.map +1 -1
  240. package/lib/worker/GenerateOrderWorker.js +1 -1
  241. package/lib/worker/GenerateOrderWorker.js.map +1 -1
  242. package/lib/worker/ZombieKillerWorker.js.map +1 -1
  243. package/lib/worker/email.js +55 -4
  244. package/lib/worker/email.js.map +1 -1
  245. package/license +274 -0
  246. package/package.json +29 -12
  247. package/src/delivery/pick-mup.ts +119 -0
  248. package/src/delivery/post.ts +30 -0
  249. package/src/delivery/send-message.ts +54 -0
  250. package/src/delivery/stores.ts +49 -0
  251. package/src/enrollments/licensed.ts +49 -0
  252. package/src/files/gridfs/gridfs-adapter.ts +1 -1
  253. package/src/files/gridfs/gridfs-webhook.js +2 -2
  254. package/src/files/minio/minio-webhook.js +1 -1
  255. package/src/filters/local-search.ts +105 -0
  256. package/src/filters/strict-equal.ts +31 -0
  257. package/src/payment/apple-iap/adapter.ts +390 -0
  258. package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +13 -0
  259. package/src/payment/apple-iap/index.ts +3 -0
  260. package/src/payment/apple-iap/module/configureAppleTransactionsModule.ts +31 -0
  261. package/src/payment/bity/adapter.ts +417 -0
  262. package/src/payment/bity/db/BityCredentialsCollection.ts +17 -0
  263. package/src/payment/bity/index.ts +3 -0
  264. package/src/payment/bity/module/configureBityModule.ts +46 -0
  265. package/src/payment/braintree.ts +147 -0
  266. package/src/payment/cryptopay.ts +195 -0
  267. package/src/payment/datatrans-v2/api/authorize.ts +17 -0
  268. package/src/payment/datatrans-v2/api/authorizeAuthenticated.ts +20 -0
  269. package/src/payment/datatrans-v2/api/cancel.ts +13 -0
  270. package/src/payment/datatrans-v2/api/index.ts +24 -0
  271. package/src/payment/datatrans-v2/api/init.ts +40 -0
  272. package/src/payment/datatrans-v2/api/makeFetcher.ts +49 -0
  273. package/src/payment/datatrans-v2/api/secureFields.ts +19 -0
  274. package/src/payment/datatrans-v2/api/settle.ts +13 -0
  275. package/src/payment/datatrans-v2/api/status.ts +8 -0
  276. package/src/payment/datatrans-v2/api/types.d.ts +378 -0
  277. package/src/payment/datatrans-v2/api/validate.ts +13 -0
  278. package/src/payment/datatrans-v2/generateSignature.ts +24 -0
  279. package/src/payment/datatrans-v2/getPaths.ts +24 -0
  280. package/src/payment/datatrans-v2/index.ts +476 -0
  281. package/src/payment/datatrans-v2/middleware.ts +147 -0
  282. package/src/payment/datatrans-v2/parseRegistrationData.ts +32 -0
  283. package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +16 -0
  284. package/src/payment/datatrans-v2/splitProperties.ts +63 -0
  285. package/src/payment/invoice-prepaid.ts +40 -0
  286. package/src/payment/invoice.ts +36 -0
  287. package/src/payment/paypal-checkout.ts +107 -0
  288. package/src/payment/postfinance-checkout/api.ts +142 -0
  289. package/src/payment/postfinance-checkout/index.ts +241 -0
  290. package/src/payment/postfinance-checkout/middleware.ts +54 -0
  291. package/src/payment/postfinance-checkout/types.ts +27 -0
  292. package/src/payment/postfinance-checkout/utils.ts +35 -0
  293. package/src/payment/stripe.ts +278 -0
  294. package/src/payment/worldline-saferpay/index.ts +140 -0
  295. package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.ts +54 -0
  296. package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.ts +36 -0
  297. package/src/payment/worldline-saferpay/worldline-saferpay-client/index.ts +8 -0
  298. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.ts +26 -0
  299. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.ts +75 -0
  300. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.ts +55 -0
  301. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Request.ts +14 -0
  302. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Response.ts +9 -0
  303. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.ts +6 -0
  304. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.ts +15 -0
  305. package/src/pricing/delivery-swiss-tax.ts +115 -0
  306. package/src/pricing/discount-100-off.ts +44 -0
  307. package/src/pricing/discount-half-price-manual.ts +43 -0
  308. package/src/pricing/discount-half-price.ts +46 -0
  309. package/src/pricing/free-delivery.ts +31 -0
  310. package/src/pricing/free-payment.ts +32 -0
  311. package/src/pricing/order-delivery.ts +45 -0
  312. package/src/pricing/order-discount.ts +158 -0
  313. package/src/pricing/order-items-discount.ts +116 -0
  314. package/src/pricing/order-items.ts +61 -0
  315. package/src/pricing/order-payment.ts +46 -0
  316. package/src/pricing/product-catalog-price.ts +56 -0
  317. package/src/pricing/product-discount.ts +69 -0
  318. package/src/pricing/product-price-ECB-interbank-exchange.ts +108 -0
  319. package/src/pricing/product-price-coinbase-exchange.ts +82 -0
  320. package/src/pricing/product-price-cryptopay.ts +25 -0
  321. package/src/pricing/product-price-rateconversion.ts +73 -0
  322. package/src/pricing/product-price-round.ts +78 -0
  323. package/src/pricing/product-swiss-tax.ts +117 -0
  324. package/src/pricing/utils/cache.js +32 -0
  325. package/src/quotations/manual.ts +27 -0
  326. package/src/warehousing/google-sheets.ts +165 -0
  327. package/src/warehousing/store.ts +47 -0
  328. package/src/worker/BulkImportWorker.ts +3 -3
  329. package/src/worker/GenerateOrderWorker.ts +1 -1
  330. package/src/worker/ZombieKillerWorker.ts +5 -5
  331. package/src/worker/email.ts +56 -4
  332. package/lib/worker/MessageWorker.d.ts +0 -10
@@ -0,0 +1,63 @@
1
+ // This method splits the return data of alias registration to the important properties needed for validation and the additional data
2
+ import crypto from 'crypto';
3
+
4
+ export default function splitProperties({ objectKey, payload }: { objectKey?: string; payload: any }): {
5
+ token?: string;
6
+ info: any;
7
+ _id?: string;
8
+ } {
9
+ if (!payload || !objectKey) return { info: {} };
10
+
11
+ if (objectKey === 'card') {
12
+ const { expiryMonth, alias, expiryYear, ...info } = payload;
13
+ if (!alias) return { info };
14
+ const is3DActive = !!payload['3D']?.xid;
15
+ if (is3DActive) {
16
+ delete info['3D'];
17
+ }
18
+ const token = JSON.stringify({
19
+ alias,
20
+ expiryMonth,
21
+ expiryYear,
22
+ '3D': is3DActive ? payload['3D'] : undefined,
23
+ });
24
+ const _id = crypto.createHash('sha256').update(token).digest('hex');
25
+
26
+ return {
27
+ token,
28
+ info,
29
+ _id,
30
+ };
31
+ }
32
+
33
+ if (objectKey === 'PAY') {
34
+ const { signature, protocolVersion, signedMessage, ...info } = payload;
35
+ if (!signedMessage) return { info };
36
+ return {
37
+ token: JSON.stringify({
38
+ signature,
39
+ protocolVersion,
40
+ signedMessage,
41
+ }),
42
+ info,
43
+ };
44
+ }
45
+
46
+ if (objectKey === 'APL') {
47
+ const { data, header, signature, version, ...info } = payload;
48
+ if (!data) return { info };
49
+ delete info['3D'];
50
+ return {
51
+ token: JSON.stringify({
52
+ data,
53
+ header,
54
+ signature,
55
+ version,
56
+ }),
57
+ info,
58
+ };
59
+ }
60
+
61
+ const { alias, ...info } = payload;
62
+ return { token: alias ? JSON.stringify({ alias }) : undefined, info };
63
+ }
@@ -0,0 +1,40 @@
1
+ import { IPaymentAdapter } from '@unchainedshop/types/payments';
2
+ import { PaymentDirector, PaymentAdapter, PaymentProviderType } from '@unchainedshop/core-payment';
3
+
4
+ const InvoicePrepaid: IPaymentAdapter = {
5
+ ...PaymentAdapter,
6
+
7
+ key: 'shop.unchained.invoice-prepaid',
8
+ label: 'Invoice Prepaid (manually)',
9
+ version: '1.0',
10
+
11
+ initialConfiguration: [],
12
+
13
+ typeSupported: (type) => {
14
+ return type === PaymentProviderType.INVOICE;
15
+ },
16
+
17
+ actions: (params) => {
18
+ return {
19
+ ...PaymentAdapter.actions(params),
20
+
21
+ configurationError: () => {
22
+ return null;
23
+ },
24
+
25
+ isActive: () => {
26
+ return true;
27
+ },
28
+
29
+ isPayLaterAllowed: () => {
30
+ return false;
31
+ },
32
+
33
+ charge: async () => {
34
+ return false;
35
+ },
36
+ };
37
+ },
38
+ };
39
+
40
+ PaymentDirector.registerAdapter(InvoicePrepaid);
@@ -0,0 +1,36 @@
1
+ import { IPaymentAdapter } from '@unchainedshop/types/payments';
2
+ import { PaymentDirector, PaymentAdapter, PaymentProviderType } from '@unchainedshop/core-payment';
3
+
4
+ const Invoice: IPaymentAdapter = {
5
+ ...PaymentAdapter,
6
+
7
+ key: 'shop.unchained.invoice',
8
+ label: 'Invoice (manually)',
9
+ version: '1.0',
10
+
11
+ initialConfiguration: [],
12
+
13
+ typeSupported: (type) => {
14
+ return type === PaymentProviderType.INVOICE;
15
+ },
16
+
17
+ actions: (params) => {
18
+ return {
19
+ ...PaymentAdapter.actions(params),
20
+
21
+ configurationError: () => {
22
+ return null;
23
+ },
24
+
25
+ isActive: () => {
26
+ return true;
27
+ },
28
+
29
+ isPayLaterAllowed: () => {
30
+ return true;
31
+ },
32
+ };
33
+ },
34
+ };
35
+
36
+ PaymentDirector.registerAdapter(Invoice);
@@ -0,0 +1,107 @@
1
+ import { IPaymentAdapter } from '@unchainedshop/types/payments';
2
+ import { PaymentDirector, PaymentAdapter, PaymentError } from '@unchainedshop/core-payment';
3
+ import { createLogger } from '@unchainedshop/logger';
4
+
5
+ const checkoutNodeJssdk = require('@paypal/checkout-server-sdk'); // eslint-disable-line
6
+
7
+ const logger = createLogger('unchained:core-payment');
8
+
9
+ const { PAYPAL_CLIENT_ID, PAYPAL_SECRET, PAYPAL_ENVIRONMENT = 'sandbox' } = process.env;
10
+
11
+ /**
12
+ *
13
+ * Set up and return PayPal JavaScript SDK environment with PayPal access credentials.
14
+ * This sample uses SandboxEnvironment. In production, use ProductionEnvironment.
15
+ *
16
+ */
17
+ const environment = () => {
18
+ const clientId = PAYPAL_CLIENT_ID;
19
+ const clientSecret = PAYPAL_SECRET;
20
+
21
+ return PAYPAL_ENVIRONMENT !== 'live'
22
+ ? new checkoutNodeJssdk.core.SandboxEnvironment(clientId, clientSecret)
23
+ : new checkoutNodeJssdk.core.LiveEnvironment(clientId, clientSecret);
24
+ };
25
+
26
+ const PaypalCheckout: IPaymentAdapter = {
27
+ ...PaymentAdapter,
28
+
29
+ key: 'com.paypal.checkout',
30
+ label: 'Paypal (Checkout / Native)',
31
+ version: '1.0',
32
+
33
+ initialConfiguration: [],
34
+
35
+ typeSupported: (type) => {
36
+ return type === 'GENERIC';
37
+ },
38
+
39
+ actions: (params) => {
40
+ const adapter = {
41
+ ...PaymentAdapter.actions(params),
42
+
43
+ configurationError: () => {
44
+ const publicCredentialsValid = PAYPAL_CLIENT_ID && PAYPAL_SECRET;
45
+
46
+ if (!publicCredentialsValid) {
47
+ return PaymentError.WRONG_CREDENTIALS;
48
+ }
49
+ return null;
50
+ },
51
+
52
+ isActive: () => {
53
+ if (adapter.configurationError() === null) return true;
54
+ return false;
55
+ },
56
+
57
+ isPayLaterAllowed: () => {
58
+ return false;
59
+ },
60
+
61
+ sign: async () => {
62
+ return PAYPAL_CLIENT_ID;
63
+ },
64
+
65
+ charge: async ({ orderID }) => {
66
+ const { modules } = params.context;
67
+ const { order } = params.paymentContext;
68
+
69
+ if (!orderID) {
70
+ logger.warn('Paypal Native Plugin: PRICE MATCH');
71
+ throw new Error('You have to provide orderID in paymentContext');
72
+ }
73
+
74
+ try {
75
+ const request = new checkoutNodeJssdk.orders.OrdersGetRequest(orderID);
76
+ const client = new checkoutNodeJssdk.core.PayPalHttpClient(environment());
77
+ const paypalOrder = await client.execute(request);
78
+
79
+ const pricing = modules.orders.pricingSheet(order);
80
+ const ourTotal = (pricing.total({ useNetPrice: false }).amount / 100).toFixed(2);
81
+ const paypalTotal = paypalOrder.result.purchase_units[0].amount.value;
82
+
83
+ if (ourTotal === paypalTotal) {
84
+ logger.info('Paypal Native Plugin: PRICE MATCH');
85
+ return order;
86
+ }
87
+
88
+ logger.warn(
89
+ 'Paypal Native Plugin: Missmatch PAYPAL ORDER',
90
+ JSON.stringify(paypalOrder.result, null, 2),
91
+ );
92
+
93
+ logger.debug('Paypal Native Plugin: OUR ORDER', order);
94
+ logger.debug('Paypal Native Plugin: OUR PRICE', pricing);
95
+
96
+ throw new Error(`Payment mismatch`);
97
+ } catch (e) {
98
+ logger.warn('Paypal Native Plugin: Failed', e);
99
+ throw new Error(e);
100
+ }
101
+ },
102
+ };
103
+ return adapter;
104
+ },
105
+ };
106
+
107
+ PaymentDirector.registerAdapter(PaypalCheckout);
@@ -0,0 +1,142 @@
1
+ import { PostFinanceCheckout } from 'postfinancecheckout';
2
+ import { RefundCreate } from 'postfinancecheckout/src/models/RefundCreate';
3
+ import { RefundType } from 'postfinancecheckout/src/models/RefundType';
4
+
5
+ const { PFCHECKOUT_SPACE_ID, PFCHECKOUT_USER_ID, PFCHECKOUT_SECRET } = process.env;
6
+ const SPACE_ID = parseInt(PFCHECKOUT_SPACE_ID as string, 10);
7
+ const USER_ID = parseInt(PFCHECKOUT_USER_ID as string, 10);
8
+
9
+ const getConfig = () => {
10
+ return {
11
+ space_id: SPACE_ID,
12
+ user_id: USER_ID,
13
+ api_secret: PFCHECKOUT_SECRET,
14
+ };
15
+ };
16
+
17
+ const getTransactionService = () => {
18
+ return new PostFinanceCheckout.api.TransactionService(getConfig());
19
+ };
20
+
21
+ const getTransactionCompletionService = () => {
22
+ return new PostFinanceCheckout.api.TransactionCompletionService(getConfig());
23
+ };
24
+
25
+ const getTransactionVoidService = () => {
26
+ return new PostFinanceCheckout.api.TransactionVoidService(getConfig());
27
+ };
28
+
29
+ const getRefundService = () => {
30
+ return new PostFinanceCheckout.api.RefundService(getConfig());
31
+ };
32
+
33
+ const getTransactionPaymentPageService = () => {
34
+ return new PostFinanceCheckout.api.TransactionPaymentPageService(getConfig());
35
+ };
36
+
37
+ const getTransactionIframeService = () => {
38
+ return new PostFinanceCheckout.api.TransactionIframeService(getConfig());
39
+ };
40
+
41
+ const getTransactionLightboxService = () => {
42
+ return new PostFinanceCheckout.api.TransactionLightboxService(getConfig());
43
+ };
44
+
45
+ const getTokenService = () => {
46
+ return new PostFinanceCheckout.api.TokenService(getConfig());
47
+ };
48
+
49
+ export const getTransaction = async (
50
+ transactionId: string,
51
+ ): Promise<PostFinanceCheckout.model.Transaction> => {
52
+ const transactionService = getTransactionService();
53
+ const transaction = await transactionService.read(SPACE_ID, parseInt(transactionId, 10));
54
+ return transaction.body;
55
+ };
56
+
57
+ export const getTransactionCompletion = async (
58
+ entityId: string,
59
+ ): Promise<PostFinanceCheckout.model.TransactionCompletion> => {
60
+ const transactionCompletionService = getTransactionCompletionService();
61
+ const transactionCompletion = await transactionCompletionService.read(
62
+ SPACE_ID,
63
+ parseInt(entityId, 10),
64
+ );
65
+ return transactionCompletion.body;
66
+ };
67
+
68
+ export const getToken = async (
69
+ spaceId: number,
70
+ tokenId: number,
71
+ ): Promise<PostFinanceCheckout.model.Token> => {
72
+ const tokenService = getTokenService();
73
+ const token = await tokenService.read(spaceId || SPACE_ID, tokenId);
74
+ return token.body;
75
+ };
76
+
77
+ export const createTransaction = async (
78
+ transaction: PostFinanceCheckout.model.TransactionCreate,
79
+ ): Promise<number | null> => {
80
+ const transactionService = getTransactionService();
81
+ const transactionCreateRes = await transactionService.create(SPACE_ID, transaction);
82
+ const transactionCreate = transactionCreateRes.body;
83
+ return transactionCreate.id || null;
84
+ };
85
+
86
+ export const voidTransaction = async (transactionId: string): Promise<boolean> => {
87
+ const transactionVoidService = getTransactionVoidService();
88
+ try {
89
+ await transactionVoidService.voidOnline(SPACE_ID, parseInt(transactionId, 10));
90
+ return true;
91
+ } catch (e) {
92
+ return false;
93
+ }
94
+ };
95
+
96
+ export const refundTransaction = async (
97
+ transactionId: string,
98
+ orderId: string,
99
+ amount: number,
100
+ ): Promise<boolean> => {
101
+ const refundService = getRefundService();
102
+ const refund: RefundCreate = {
103
+ transaction: parseInt(transactionId, 10),
104
+ externalId: orderId,
105
+ amount,
106
+ type: RefundType.MERCHANT_INITIATED_ONLINE,
107
+ };
108
+ try {
109
+ await refundService.refund(SPACE_ID, refund);
110
+ return true;
111
+ } catch (e) {
112
+ return false;
113
+ }
114
+ };
115
+
116
+ export const confirmDeferredTransaction = async (transactionId: string): Promise<boolean> => {
117
+ const transactionCompletionService = getTransactionCompletionService();
118
+ try {
119
+ await transactionCompletionService.completeOnline(SPACE_ID, parseInt(transactionId, 10));
120
+ return true;
121
+ } catch (e) {
122
+ return false;
123
+ }
124
+ };
125
+
126
+ export const getPaymentPageUrl = async (transactionId: number): Promise<string> => {
127
+ const transactionPaymentPageService = getTransactionPaymentPageService();
128
+ const paymentPageUrl = await transactionPaymentPageService.paymentPageUrl(SPACE_ID, transactionId);
129
+ return paymentPageUrl.body;
130
+ };
131
+
132
+ export const getLightboxJavascriptUrl = async (transactionId: number): Promise<string> => {
133
+ const transactionLightboxService = getTransactionLightboxService();
134
+ const javascriptUrl = await transactionLightboxService.javascriptUrl(SPACE_ID, transactionId);
135
+ return javascriptUrl.body;
136
+ };
137
+
138
+ export const getIframeJavascriptUrl = async (transactionId: number): Promise<string> => {
139
+ const transactionIframeService = getTransactionIframeService();
140
+ const javascriptUrl = await transactionIframeService.javascriptUrl(SPACE_ID, transactionId);
141
+ return javascriptUrl.body;
142
+ };
@@ -0,0 +1,241 @@
1
+ import { IPaymentActions, IPaymentAdapter } from '@unchainedshop/types/payments';
2
+ import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment';
3
+ import { TransactionCompletionBehavior } from 'postfinancecheckout/src/models/TransactionCompletionBehavior';
4
+ import { PostFinanceCheckout } from 'postfinancecheckout';
5
+ import { createLogger } from '@unchainedshop/logger';
6
+ import { CreationEntityState } from 'postfinancecheckout/src/models/CreationEntityState';
7
+ import { TransactionState } from 'postfinancecheckout/src/models/TransactionState';
8
+ import {
9
+ confirmDeferredTransaction,
10
+ createTransaction,
11
+ getIframeJavascriptUrl,
12
+ getLightboxJavascriptUrl,
13
+ getPaymentPageUrl,
14
+ getToken,
15
+ getTransaction,
16
+ refundTransaction,
17
+ voidTransaction,
18
+ } from './api';
19
+ import { orderIsPaid } from './utils';
20
+ import './middleware';
21
+ import { CompletionModes, IntegrationModes, SignResponse } from './types';
22
+
23
+ const {
24
+ PFCHECKOUT_SPACE_ID,
25
+ PFCHECKOUT_USER_ID,
26
+ PFCHECKOUT_SECRET,
27
+ PFCHECKOUT_SUCCESS_URL,
28
+ PFCHECKOUT_FAILED_URL,
29
+ } = process.env;
30
+
31
+ const logger = createLogger('unchained:core-payment:postfinance');
32
+
33
+ const newError = ({ code, message }: { code: string; message: string }) => {
34
+ const error = new Error(message);
35
+ error.name = `POSTFINANCE_${code}`;
36
+ return error;
37
+ };
38
+
39
+ const PostfinanceCheckout: IPaymentAdapter = {
40
+ ...PaymentAdapter,
41
+
42
+ key: 'shop.unchained.payment.postfinance-checkout',
43
+ label: 'Postfinance Checkout',
44
+ version: '1.0',
45
+
46
+ typeSupported(type) {
47
+ return type === 'GENERIC';
48
+ },
49
+
50
+ actions: (params) => {
51
+ const { modules } = params.context;
52
+
53
+ const adapter: IPaymentActions & {
54
+ getCompletionMode: () => CompletionModes;
55
+ } = {
56
+ ...PaymentAdapter.actions(params),
57
+
58
+ getCompletionMode() {
59
+ return (
60
+ (params.config.find((item) => item.key === 'completionMode')?.value as CompletionModes) ||
61
+ CompletionModes.Deferred
62
+ );
63
+ },
64
+
65
+ // eslint-disable-next-line
66
+ configurationError() {
67
+ // eslint-disable-line
68
+ if (
69
+ !PFCHECKOUT_SPACE_ID ||
70
+ !PFCHECKOUT_USER_ID ||
71
+ !PFCHECKOUT_SECRET ||
72
+ !PFCHECKOUT_SUCCESS_URL ||
73
+ !PFCHECKOUT_FAILED_URL
74
+ ) {
75
+ return PaymentError.INCOMPLETE_CONFIGURATION;
76
+ }
77
+ return null;
78
+ },
79
+
80
+ isActive() {
81
+ if (adapter.configurationError() === null) return true;
82
+ return false;
83
+ },
84
+
85
+ isPayLaterAllowed() {
86
+ return false;
87
+ },
88
+
89
+ async validate(credentials) {
90
+ if (!credentials.meta) return false;
91
+ const { linkedSpaceId } = credentials.meta;
92
+ const tokenData = await getToken(linkedSpaceId, credentials.token);
93
+ return tokenData.state === CreationEntityState.ACTIVE;
94
+ },
95
+
96
+ sign: async (transactionContext: any = {}) => {
97
+ const { integrationMode = IntegrationModes.PaymentPage }: { integrationMode: IntegrationModes } =
98
+ transactionContext;
99
+ const completionMode = adapter.getCompletionMode();
100
+ const { orderPayment } = params.paymentContext;
101
+ const order = await modules.orders.findOrder({
102
+ orderId: orderPayment.orderId,
103
+ });
104
+ const pricing = modules.orders.pricingSheet(order);
105
+ const totalAmount = pricing?.total({ useNetPrice: false }).amount;
106
+ const transaction = new PostFinanceCheckout.model.TransactionCreate();
107
+ transaction.currency = order.currency;
108
+ transaction.metaData = {
109
+ orderPaymentId: orderPayment._id,
110
+ };
111
+ transaction.successUrl = `${transactionContext?.successUrl || PFCHECKOUT_SUCCESS_URL}?order_id=${
112
+ orderPayment.orderId
113
+ }`;
114
+ transaction.failedUrl = `${transactionContext?.failedUrl || PFCHECKOUT_FAILED_URL}?order_id=${
115
+ orderPayment.orderId
116
+ }`;
117
+ transaction.customerId = params.context.user._id;
118
+ transaction.tokenizationMode =
119
+ PostFinanceCheckout.model.TokenizationMode.ALLOW_ONE_CLICK_PAYMENT;
120
+ if (completionMode === CompletionModes.Immediate) {
121
+ transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_IMMEDIATELY;
122
+ } else if (completionMode === CompletionModes.Deferred) {
123
+ transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_DEFERRED;
124
+ }
125
+ if (totalAmount) {
126
+ const lineItemSum = new PostFinanceCheckout.model.LineItemCreate();
127
+ lineItemSum.name = `Bestellung ${orderPayment.orderId}`;
128
+ lineItemSum.type = PostFinanceCheckout.model.LineItemType.FEE;
129
+ lineItemSum.quantity = 1;
130
+ lineItemSum.uniqueId = orderPayment.orderId;
131
+ lineItemSum.amountIncludingTax = totalAmount / 100;
132
+ transaction.lineItems = [lineItemSum];
133
+ }
134
+ const transactionId = await createTransaction(transaction);
135
+ let location = null;
136
+ if (integrationMode === IntegrationModes.PaymentPage) {
137
+ location = await getPaymentPageUrl(transactionId);
138
+ } else if (integrationMode === IntegrationModes.Lightbox) {
139
+ location = await getLightboxJavascriptUrl(transactionId);
140
+ } else if (integrationMode === IntegrationModes.iFrame) {
141
+ location = await getIframeJavascriptUrl(transactionId);
142
+ }
143
+ const res: SignResponse = {
144
+ transactionId,
145
+ location,
146
+ };
147
+
148
+ return JSON.stringify(res);
149
+ },
150
+
151
+ charge: async ({
152
+ transactionId,
153
+ paymentCredentials,
154
+ }: {
155
+ transactionId: string;
156
+ paymentCredentials: any;
157
+ }) => {
158
+ if (paymentCredentials && !transactionId) {
159
+ // Directly charge the customer based on existing token!
160
+ throw new Error('Not implemented yet');
161
+ }
162
+ if (!transactionId) return false; // checkout without payment
163
+
164
+ const transaction = await getTransaction(transactionId);
165
+
166
+ if (!transaction) {
167
+ logger.error(`Transaction #${transactionId}: Transaction not found`);
168
+ throw newError({
169
+ code: `TRANSACTION_NOT_FOUND`,
170
+ message: 'Payment declined',
171
+ });
172
+ }
173
+
174
+ const isPaid = await orderIsPaid(params.paymentContext.order, transaction, modules.orders);
175
+ if (!isPaid) {
176
+ logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
177
+ throw newError({
178
+ code: `STATE_${transaction.state?.toUpperCase()}`,
179
+ message: 'Invalid state / Amount incorrect',
180
+ });
181
+ }
182
+
183
+ if (transaction.metaData.orderPaymentId !== params.paymentContext.orderPayment._id) {
184
+ logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
185
+ throw newError({
186
+ code: `TRANSACTION_ALREADY_USED`,
187
+ message: 'Transaction already used in previous checkout',
188
+ });
189
+ }
190
+
191
+ const { token: { id, ...tokenMeta } = {} } = transaction;
192
+
193
+ return {
194
+ transaction,
195
+ transactionId,
196
+ credentials: id && {
197
+ ...tokenMeta,
198
+ token: id,
199
+ },
200
+ };
201
+ },
202
+
203
+ cancel: async () => {
204
+ const { orderPayment } = params.paymentContext;
205
+ const { transactionId } = orderPayment;
206
+ if (!transactionId) {
207
+ return false;
208
+ }
209
+ const transaction = await getTransaction(transactionId);
210
+ const refund = transaction.state === TransactionState.FULFILL;
211
+ const order = await modules.orders.findOrder({
212
+ orderId: orderPayment.orderId,
213
+ });
214
+ const pricing = modules.orders.pricingSheet(order);
215
+ const totalAmount = pricing?.total({ useNetPrice: false }).amount;
216
+ // For immediate settlements, try refunding. For deferred settlements, void the transaction.
217
+ return (
218
+ (refund && refundTransaction(transactionId, order._id, totalAmount / 100)) ||
219
+ voidTransaction(transactionId)
220
+ );
221
+ },
222
+
223
+ confirm: async () => {
224
+ const { orderPayment } = params.paymentContext;
225
+ const { transactionId } = orderPayment;
226
+ if (!transactionId) {
227
+ return false;
228
+ }
229
+ const transaction = await getTransaction(transactionId);
230
+ if (transaction.state === TransactionState.AUTHORIZED) {
231
+ return confirmDeferredTransaction(transactionId);
232
+ }
233
+ return false;
234
+ },
235
+ };
236
+
237
+ return adapter;
238
+ },
239
+ };
240
+
241
+ PaymentDirector.registerAdapter(PostfinanceCheckout);
@@ -0,0 +1,54 @@
1
+ import bodyParser from 'body-parser';
2
+ import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
3
+ import { Context } from '@unchainedshop/types/api';
4
+ import { createLogger } from '@unchainedshop/logger';
5
+ import { WebhookData } from './types';
6
+ import { getTransaction, getTransactionCompletion } from './api';
7
+
8
+ const { PFCHECKOUT_WEBHOOK_PATH = '/graphql/postfinance-checkout' } = process.env;
9
+
10
+ const logger = createLogger('unchained:core-payment:postfinance-checkout');
11
+
12
+ useMiddlewareWithCurrentContext(PFCHECKOUT_WEBHOOK_PATH, bodyParser.json());
13
+
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,
33
+ },
34
+ },
35
+ context,
36
+ );
37
+ logger.info(
38
+ `PostFinance Checkout Webhook: Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
39
+ );
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));
46
+ }
47
+ } else {
48
+ logger.error(
49
+ `PostFinance Checkout Webhook: Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`,
50
+ );
51
+ res.writeHead(404);
52
+ res.end();
53
+ }
54
+ });