@unchainedshop/plugins 1.1.3 → 1.1.4

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 (319) 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/filters/local-search.d.ts +3 -0
  17. package/lib/filters/local-search.js +84 -0
  18. package/lib/filters/local-search.js.map +1 -0
  19. package/lib/filters/strict-equal.d.ts +1 -0
  20. package/lib/filters/strict-equal.js +25 -0
  21. package/lib/filters/strict-equal.js.map +1 -0
  22. package/lib/payment/apple-iap/adapter.d.ts +1 -0
  23. package/lib/payment/apple-iap/adapter.js +284 -0
  24. package/lib/payment/apple-iap/adapter.js.map +1 -0
  25. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +7 -0
  26. package/lib/payment/apple-iap/db/AppleTransactionsCollection.js +5 -0
  27. package/lib/payment/apple-iap/db/AppleTransactionsCollection.js.map +1 -0
  28. package/lib/payment/apple-iap/index.d.ts +2 -0
  29. package/lib/payment/apple-iap/index.js +3 -0
  30. package/lib/payment/apple-iap/index.js.map +1 -0
  31. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
  32. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +18 -0
  33. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
  34. package/lib/payment/bity/adapter.d.ts +1 -0
  35. package/lib/payment/bity/adapter.js +316 -0
  36. package/lib/payment/bity/adapter.js.map +1 -0
  37. package/lib/payment/bity/db/BityCredentialsCollection.d.ts +11 -0
  38. package/lib/payment/bity/db/BityCredentialsCollection.js +5 -0
  39. package/lib/payment/bity/db/BityCredentialsCollection.js.map +1 -0
  40. package/lib/payment/bity/index.d.ts +2 -0
  41. package/lib/payment/bity/index.js +3 -0
  42. package/lib/payment/bity/index.js.map +1 -0
  43. package/lib/payment/bity/module/configureBityModule.d.ts +11 -0
  44. package/lib/payment/bity/module/configureBityModule.js +33 -0
  45. package/lib/payment/bity/module/configureBityModule.js.map +1 -0
  46. package/lib/payment/braintree.d.ts +1 -0
  47. package/lib/payment/braintree.js +129 -0
  48. package/lib/payment/braintree.js.map +1 -0
  49. package/lib/payment/cryptopay.d.ts +1 -0
  50. package/lib/payment/cryptopay.js +159 -0
  51. package/lib/payment/cryptopay.js.map +1 -0
  52. package/lib/payment/datatrans-v2/api/authorize.d.ts +2 -0
  53. package/lib/payment/datatrans-v2/api/authorize.js +12 -0
  54. package/lib/payment/datatrans-v2/api/authorize.js.map +1 -0
  55. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.d.ts +2 -0
  56. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js +11 -0
  57. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js.map +1 -0
  58. package/lib/payment/datatrans-v2/api/cancel.d.ts +2 -0
  59. package/lib/payment/datatrans-v2/api/cancel.js +10 -0
  60. package/lib/payment/datatrans-v2/api/cancel.js.map +1 -0
  61. package/lib/payment/datatrans-v2/api/index.d.ts +19 -0
  62. package/lib/payment/datatrans-v2/api/index.js +24 -0
  63. package/lib/payment/datatrans-v2/api/index.js.map +1 -0
  64. package/lib/payment/datatrans-v2/api/init.d.ts +2 -0
  65. package/lib/payment/datatrans-v2/api/init.js +31 -0
  66. package/lib/payment/datatrans-v2/api/init.js.map +1 -0
  67. package/lib/payment/datatrans-v2/api/makeFetcher.d.ts +2 -0
  68. package/lib/payment/datatrans-v2/api/makeFetcher.js +41 -0
  69. package/lib/payment/datatrans-v2/api/makeFetcher.js.map +1 -0
  70. package/lib/payment/datatrans-v2/api/secureFields.d.ts +2 -0
  71. package/lib/payment/datatrans-v2/api/secureFields.js +14 -0
  72. package/lib/payment/datatrans-v2/api/secureFields.js.map +1 -0
  73. package/lib/payment/datatrans-v2/api/settle.d.ts +2 -0
  74. package/lib/payment/datatrans-v2/api/settle.js +10 -0
  75. package/lib/payment/datatrans-v2/api/settle.js.map +1 -0
  76. package/lib/payment/datatrans-v2/api/status.d.ts +2 -0
  77. package/lib/payment/datatrans-v2/api/status.js +7 -0
  78. package/lib/payment/datatrans-v2/api/status.js.map +1 -0
  79. package/lib/payment/datatrans-v2/api/validate.d.ts +2 -0
  80. package/lib/payment/datatrans-v2/api/validate.js +10 -0
  81. package/lib/payment/datatrans-v2/api/validate.js.map +1 -0
  82. package/lib/payment/datatrans-v2/generateSignature.d.ts +10 -0
  83. package/lib/payment/datatrans-v2/generateSignature.js +19 -0
  84. package/lib/payment/datatrans-v2/generateSignature.js.map +1 -0
  85. package/lib/payment/datatrans-v2/getPaths.d.ts +9 -0
  86. package/lib/payment/datatrans-v2/getPaths.js +9 -0
  87. package/lib/payment/datatrans-v2/getPaths.js.map +1 -0
  88. package/lib/payment/datatrans-v2/index.d.ts +1 -0
  89. package/lib/payment/datatrans-v2/index.js +384 -0
  90. package/lib/payment/datatrans-v2/index.js.map +1 -0
  91. package/lib/payment/datatrans-v2/middleware.d.ts +1 -0
  92. package/lib/payment/datatrans-v2/middleware.js +111 -0
  93. package/lib/payment/datatrans-v2/middleware.js.map +1 -0
  94. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +11 -0
  95. package/lib/payment/datatrans-v2/parseRegistrationData.js +26 -0
  96. package/lib/payment/datatrans-v2/parseRegistrationData.js.map +1 -0
  97. package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +7 -0
  98. package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +10 -0
  99. package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -0
  100. package/lib/payment/datatrans-v2/splitProperties.d.ts +8 -0
  101. package/lib/payment/datatrans-v2/splitProperties.js +58 -0
  102. package/lib/payment/datatrans-v2/splitProperties.js.map +1 -0
  103. package/lib/payment/invoice-prepaid.d.ts +1 -0
  104. package/lib/payment/invoice-prepaid.js +30 -0
  105. package/lib/payment/invoice-prepaid.js.map +1 -0
  106. package/lib/payment/invoice.d.ts +1 -0
  107. package/lib/payment/invoice.js +27 -0
  108. package/lib/payment/invoice.js.map +1 -0
  109. package/lib/payment/paypal-checkout.d.ts +1 -0
  110. package/lib/payment/paypal-checkout.js +82 -0
  111. package/lib/payment/paypal-checkout.js.map +1 -0
  112. package/lib/payment/postfinance-checkout/api.d.ts +11 -0
  113. package/lib/payment/postfinance-checkout/api.js +109 -0
  114. package/lib/payment/postfinance-checkout/api.js.map +1 -0
  115. package/lib/payment/postfinance-checkout/index.d.ts +1 -0
  116. package/lib/payment/postfinance-checkout/index.js +186 -0
  117. package/lib/payment/postfinance-checkout/index.js.map +1 -0
  118. package/lib/payment/postfinance-checkout/middleware.d.ts +1 -0
  119. package/lib/payment/postfinance-checkout/middleware.js +42 -0
  120. package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
  121. package/lib/payment/postfinance-checkout/types.d.ts +23 -0
  122. package/lib/payment/postfinance-checkout/types.js +12 -0
  123. package/lib/payment/postfinance-checkout/types.js.map +1 -0
  124. package/lib/payment/postfinance-checkout/utils.d.ts +4 -0
  125. package/lib/payment/postfinance-checkout/utils.js +20 -0
  126. package/lib/payment/postfinance-checkout/utils.js.map +1 -0
  127. package/lib/payment/stripe.d.ts +1 -0
  128. package/lib/payment/stripe.js +214 -0
  129. package/lib/payment/stripe.js.map +1 -0
  130. package/lib/payment/worldline-saferpay/index.d.ts +1 -0
  131. package/lib/payment/worldline-saferpay/index.js +112 -0
  132. package/lib/payment/worldline-saferpay/index.js.map +1 -0
  133. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.d.ts +14 -0
  134. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js +29 -0
  135. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js.map +1 -0
  136. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.d.ts +9 -0
  137. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js +28 -0
  138. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js.map +1 -0
  139. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.d.ts +4 -0
  140. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js +2 -0
  141. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js.map +1 -0
  142. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.d.ts +1 -0
  143. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js +2 -0
  144. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js.map +1 -0
  145. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.d.ts +73 -0
  146. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js +2 -0
  147. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js.map +1 -0
  148. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.d.ts +53 -0
  149. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js +2 -0
  150. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js.map +1 -0
  151. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.d.ts +13 -0
  152. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js +2 -0
  153. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js.map +1 -0
  154. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.d.ts +9 -0
  155. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js +2 -0
  156. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js.map +1 -0
  157. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.d.ts +5 -0
  158. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js +2 -0
  159. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js.map +1 -0
  160. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.d.ts +13 -0
  161. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js +2 -0
  162. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js.map +1 -0
  163. package/lib/pricing/delivery-swiss-tax.d.ts +15 -0
  164. package/lib/pricing/delivery-swiss-tax.js +98 -0
  165. package/lib/pricing/delivery-swiss-tax.js.map +1 -0
  166. package/lib/pricing/discount-100-off.d.ts +1 -0
  167. package/lib/pricing/discount-100-off.js +34 -0
  168. package/lib/pricing/discount-100-off.js.map +1 -0
  169. package/lib/pricing/discount-half-price-manual.d.ts +1 -0
  170. package/lib/pricing/discount-half-price-manual.js +34 -0
  171. package/lib/pricing/discount-half-price-manual.js.map +1 -0
  172. package/lib/pricing/discount-half-price.d.ts +1 -0
  173. package/lib/pricing/discount-half-price.js +37 -0
  174. package/lib/pricing/discount-half-price.js.map +1 -0
  175. package/lib/pricing/free-delivery.d.ts +2 -0
  176. package/lib/pricing/free-delivery.js +26 -0
  177. package/lib/pricing/free-delivery.js.map +1 -0
  178. package/lib/pricing/free-payment.d.ts +2 -0
  179. package/lib/pricing/free-payment.js +26 -0
  180. package/lib/pricing/free-payment.js.map +1 -0
  181. package/lib/pricing/order-delivery.d.ts +1 -0
  182. package/lib/pricing/order-delivery.js +33 -0
  183. package/lib/pricing/order-delivery.js.map +1 -0
  184. package/lib/pricing/order-discount.d.ts +1 -0
  185. package/lib/pricing/order-discount.js +110 -0
  186. package/lib/pricing/order-discount.js.map +1 -0
  187. package/lib/pricing/order-items-discount.d.ts +1 -0
  188. package/lib/pricing/order-items-discount.js +88 -0
  189. package/lib/pricing/order-items-discount.js.map +1 -0
  190. package/lib/pricing/order-items.d.ts +1 -0
  191. package/lib/pricing/order-items.js +44 -0
  192. package/lib/pricing/order-items.js.map +1 -0
  193. package/lib/pricing/order-payment.d.ts +1 -0
  194. package/lib/pricing/order-payment.js +33 -0
  195. package/lib/pricing/order-payment.js.map +1 -0
  196. package/lib/pricing/product-catalog-price.d.ts +1 -0
  197. package/lib/pricing/product-catalog-price.js +37 -0
  198. package/lib/pricing/product-catalog-price.js.map +1 -0
  199. package/lib/pricing/product-discount.d.ts +1 -0
  200. package/lib/pricing/product-discount.js +55 -0
  201. package/lib/pricing/product-discount.js.map +1 -0
  202. package/lib/pricing/product-price-ECB-interbank-exchange.d.ts +1 -0
  203. package/lib/pricing/product-price-ECB-interbank-exchange.js +90 -0
  204. package/lib/pricing/product-price-ECB-interbank-exchange.js.map +1 -0
  205. package/lib/pricing/product-price-coinbase-exchange.d.ts +1 -0
  206. package/lib/pricing/product-price-coinbase-exchange.js +60 -0
  207. package/lib/pricing/product-price-coinbase-exchange.js.map +1 -0
  208. package/lib/pricing/product-price-cryptopay.d.ts +1 -0
  209. package/lib/pricing/product-price-cryptopay.js +21 -0
  210. package/lib/pricing/product-price-cryptopay.js.map +1 -0
  211. package/lib/pricing/product-price-rateconversion.d.ts +1 -0
  212. package/lib/pricing/product-price-rateconversion.js +51 -0
  213. package/lib/pricing/product-price-rateconversion.js.map +1 -0
  214. package/lib/pricing/product-price-round.d.ts +11 -0
  215. package/lib/pricing/product-price-round.js +54 -0
  216. package/lib/pricing/product-price-round.js.map +1 -0
  217. package/lib/pricing/product-swiss-tax.d.ts +13 -0
  218. package/lib/pricing/product-swiss-tax.js +102 -0
  219. package/lib/pricing/product-swiss-tax.js.map +1 -0
  220. package/lib/pricing/utils/cache.d.ts +9 -0
  221. package/lib/pricing/utils/cache.js +28 -0
  222. package/lib/pricing/utils/cache.js.map +1 -0
  223. package/lib/quotations/manual.d.ts +1 -0
  224. package/lib/quotations/manual.js +21 -0
  225. package/lib/quotations/manual.js.map +1 -0
  226. package/lib/warehousing/google-sheets.d.ts +1 -0
  227. package/lib/warehousing/google-sheets.js +153 -0
  228. package/lib/warehousing/google-sheets.js.map +1 -0
  229. package/lib/warehousing/store.d.ts +1 -0
  230. package/lib/warehousing/store.js +33 -0
  231. package/lib/warehousing/store.js.map +1 -0
  232. package/lib/worker/BulkImportWorker.js +3 -3
  233. package/lib/worker/BulkImportWorker.js.map +1 -1
  234. package/lib/worker/GenerateOrderWorker.js +1 -1
  235. package/lib/worker/GenerateOrderWorker.js.map +1 -1
  236. package/lib/worker/email.js +55 -4
  237. package/lib/worker/email.js.map +1 -1
  238. package/package.json +18 -2
  239. package/src/delivery/pick-mup.ts +119 -0
  240. package/src/delivery/post.ts +30 -0
  241. package/src/delivery/send-message.ts +54 -0
  242. package/src/delivery/stores.ts +49 -0
  243. package/src/enrollments/licensed.ts +49 -0
  244. package/src/filters/local-search.ts +105 -0
  245. package/src/filters/strict-equal.ts +31 -0
  246. package/src/payment/apple-iap/adapter.ts +390 -0
  247. package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +13 -0
  248. package/src/payment/apple-iap/index.ts +3 -0
  249. package/src/payment/apple-iap/module/configureAppleTransactionsModule.ts +31 -0
  250. package/src/payment/bity/adapter.ts +417 -0
  251. package/src/payment/bity/db/BityCredentialsCollection.ts +17 -0
  252. package/src/payment/bity/index.ts +3 -0
  253. package/src/payment/bity/module/configureBityModule.ts +46 -0
  254. package/src/payment/braintree.ts +147 -0
  255. package/src/payment/cryptopay.ts +195 -0
  256. package/src/payment/datatrans-v2/api/authorize.ts +17 -0
  257. package/src/payment/datatrans-v2/api/authorizeAuthenticated.ts +20 -0
  258. package/src/payment/datatrans-v2/api/cancel.ts +13 -0
  259. package/src/payment/datatrans-v2/api/index.ts +24 -0
  260. package/src/payment/datatrans-v2/api/init.ts +40 -0
  261. package/src/payment/datatrans-v2/api/makeFetcher.ts +49 -0
  262. package/src/payment/datatrans-v2/api/secureFields.ts +19 -0
  263. package/src/payment/datatrans-v2/api/settle.ts +13 -0
  264. package/src/payment/datatrans-v2/api/status.ts +8 -0
  265. package/src/payment/datatrans-v2/api/types.d.ts +378 -0
  266. package/src/payment/datatrans-v2/api/validate.ts +13 -0
  267. package/src/payment/datatrans-v2/generateSignature.ts +24 -0
  268. package/src/payment/datatrans-v2/getPaths.ts +24 -0
  269. package/src/payment/datatrans-v2/index.ts +476 -0
  270. package/src/payment/datatrans-v2/middleware.ts +147 -0
  271. package/src/payment/datatrans-v2/parseRegistrationData.ts +32 -0
  272. package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +16 -0
  273. package/src/payment/datatrans-v2/splitProperties.ts +63 -0
  274. package/src/payment/invoice-prepaid.ts +40 -0
  275. package/src/payment/invoice.ts +36 -0
  276. package/src/payment/paypal-checkout.ts +107 -0
  277. package/src/payment/postfinance-checkout/api.ts +142 -0
  278. package/src/payment/postfinance-checkout/index.ts +241 -0
  279. package/src/payment/postfinance-checkout/middleware.ts +54 -0
  280. package/src/payment/postfinance-checkout/types.ts +27 -0
  281. package/src/payment/postfinance-checkout/utils.ts +35 -0
  282. package/src/payment/stripe.ts +278 -0
  283. package/src/payment/worldline-saferpay/index.ts +140 -0
  284. package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.ts +54 -0
  285. package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.ts +36 -0
  286. package/src/payment/worldline-saferpay/worldline-saferpay-client/index.ts +8 -0
  287. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.ts +26 -0
  288. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.ts +75 -0
  289. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.ts +55 -0
  290. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Request.ts +14 -0
  291. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Response.ts +9 -0
  292. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.ts +6 -0
  293. package/src/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.ts +15 -0
  294. package/src/pricing/delivery-swiss-tax.ts +115 -0
  295. package/src/pricing/discount-100-off.ts +44 -0
  296. package/src/pricing/discount-half-price-manual.ts +43 -0
  297. package/src/pricing/discount-half-price.ts +46 -0
  298. package/src/pricing/free-delivery.ts +31 -0
  299. package/src/pricing/free-payment.ts +32 -0
  300. package/src/pricing/order-delivery.ts +45 -0
  301. package/src/pricing/order-discount.ts +158 -0
  302. package/src/pricing/order-items-discount.ts +116 -0
  303. package/src/pricing/order-items.ts +61 -0
  304. package/src/pricing/order-payment.ts +46 -0
  305. package/src/pricing/product-catalog-price.ts +56 -0
  306. package/src/pricing/product-discount.ts +69 -0
  307. package/src/pricing/product-price-ECB-interbank-exchange.ts +108 -0
  308. package/src/pricing/product-price-coinbase-exchange.ts +82 -0
  309. package/src/pricing/product-price-cryptopay.ts +25 -0
  310. package/src/pricing/product-price-rateconversion.ts +73 -0
  311. package/src/pricing/product-price-round.ts +78 -0
  312. package/src/pricing/product-swiss-tax.ts +117 -0
  313. package/src/pricing/utils/cache.js +32 -0
  314. package/src/quotations/manual.ts +27 -0
  315. package/src/warehousing/google-sheets.ts +165 -0
  316. package/src/warehousing/store.ts +47 -0
  317. package/src/worker/BulkImportWorker.ts +3 -3
  318. package/src/worker/GenerateOrderWorker.ts +1 -1
  319. package/src/worker/email.ts +56 -4
@@ -0,0 +1,476 @@
1
+ import { IPaymentAdapter } from '@unchainedshop/types/payments';
2
+ import { PaymentAdapter, PaymentError, PaymentDirector } from '@unchainedshop/core-payment';
3
+ import { createLogger } from '@unchainedshop/logger';
4
+ import createDatatransAPI from './api';
5
+ import type {
6
+ AuthorizeAuthenticatedResponseSuccess,
7
+ AuthorizeResponseSuccess,
8
+ InitResponseSuccess,
9
+ ResponseError,
10
+ StatusResponseSuccess,
11
+ ValidateResponseSuccess,
12
+ } from './api/types';
13
+ import './middleware';
14
+ import parseRegistrationData from './parseRegistrationData';
15
+ import roundedAmountFromOrder from './roundedAmountFromOrder';
16
+
17
+ const logger = createLogger('unchained:core-payment:datatrans');
18
+
19
+ // v2
20
+ const { DATATRANS_SECRET, DATATRANS_SIGN_KEY, DATATRANS_API_ENDPOINT, DATATRANS_MERCHANT_ID } =
21
+ process.env;
22
+
23
+ const newDatatransError = ({ code, message }: { code: string; message: string }) => {
24
+ const error = new Error(message);
25
+ error.name = `DATATRANS_${code}`;
26
+ return error;
27
+ };
28
+
29
+ const throwIfResponseError = (result) => {
30
+ if ((result as ResponseError).error) {
31
+ const rawError = (result as ResponseError).error;
32
+ throw newDatatransError(rawError);
33
+ }
34
+ };
35
+
36
+ const Datatrans: IPaymentAdapter = {
37
+ ...PaymentAdapter,
38
+
39
+ key: 'shop.unchained.datatrans',
40
+ label: 'Datatrans (https://docs.datatrans.ch)',
41
+ version: '2.0.0',
42
+
43
+ initialConfiguration: [
44
+ {
45
+ key: 'merchantId',
46
+ value: null,
47
+ },
48
+ ],
49
+
50
+ typeSupported(type) {
51
+ return type === 'GENERIC';
52
+ },
53
+
54
+ actions: (params) => {
55
+ const { modules } = params.context;
56
+
57
+ const getMerchantId = (): string | undefined => {
58
+ return params.config.find((item) => item.key === 'merchantId')?.value || DATATRANS_MERCHANT_ID;
59
+ };
60
+
61
+ const api = () => {
62
+ if (!DATATRANS_SECRET) throw new Error('Credentials not Set');
63
+ return createDatatransAPI(
64
+ DATATRANS_API_ENDPOINT || 'https://api.sandbox.datatrans.com',
65
+ getMerchantId(),
66
+ DATATRANS_SECRET,
67
+ );
68
+ };
69
+
70
+ const shouldSettleInUnchained = () => {
71
+ return params.config.reduce((current, item) => {
72
+ if (item.key === 'settleInUnchained') return Boolean(item.value);
73
+ return current;
74
+ }, true);
75
+ };
76
+
77
+ const getMarketplaceSplits = async (): Promise<
78
+ {
79
+ subMerchantId: string;
80
+ amount: number;
81
+ commission: number;
82
+ }[]
83
+ > => {
84
+ const { order, orderPayment } = params.paymentContext;
85
+
86
+ const pricingForOrderPayment = modules.orders.payments.pricingSheet(
87
+ orderPayment,
88
+ order.currency,
89
+ params.context,
90
+ );
91
+ const pricing = modules.orders.pricingSheet(order);
92
+ const { amount: total } = pricing.total({ useNetPrice: false });
93
+
94
+ return Promise.all(
95
+ params.config
96
+ .filter((item) => item.key === 'marketplaceSplit')
97
+ .map((item) => {
98
+ const [subMerchantId, staticDiscountId, sharePercentage] = item.value
99
+ .split(';')
100
+ .map((f) => f.trim());
101
+
102
+ const discountSum = pricingForOrderPayment.discountSum(staticDiscountId) * -1;
103
+ const shareFactor = sharePercentage ? parseInt(sharePercentage, 10) / 100 : 1;
104
+ const amount = Math.round(total * shareFactor);
105
+ const commission = Math.round(discountSum * shareFactor);
106
+
107
+ return {
108
+ subMerchantId,
109
+ amount,
110
+ commission,
111
+ };
112
+ }),
113
+ );
114
+ };
115
+
116
+ const authorize = async ({ paymentCredentials, extensions }): Promise<string> => {
117
+ const { order, orderPayment } = params.paymentContext;
118
+ const userId = order?.userId || params.context.userId;
119
+ const refno = Buffer.from(orderPayment._id, 'hex').toString('base64');
120
+ const refno2 = userId;
121
+ const { currency, amount } = roundedAmountFromOrder(order, params.context);
122
+ const splits = await getMarketplaceSplits();
123
+ const result = await api().authorize({
124
+ ...extensions,
125
+ amount,
126
+ currency,
127
+ refno,
128
+ refno2,
129
+ autoSettle: false,
130
+ customer: {
131
+ id: userId,
132
+ },
133
+ marketplace: splits.length
134
+ ? {
135
+ splits,
136
+ }
137
+ : undefined,
138
+ [paymentCredentials.meta.objectKey]: JSON.parse(paymentCredentials.token),
139
+ });
140
+ throwIfResponseError(result);
141
+ return (result as AuthorizeResponseSuccess).transactionId;
142
+ };
143
+
144
+ const authorizeAuth = async ({ transactionId, refno, refno2, extensions }): Promise<string> => {
145
+ const { order } = params.paymentContext;
146
+ const { currency, amount } = roundedAmountFromOrder(order, params.context);
147
+ const result = await api().authorizeAuthenticated({
148
+ ...extensions,
149
+ transactionId,
150
+ amount,
151
+ currency,
152
+ refno,
153
+ refno2,
154
+ autoSettle: false,
155
+ });
156
+ throwIfResponseError(result);
157
+ return (result as AuthorizeAuthenticatedResponseSuccess).acquirerAuthorizationCode;
158
+ };
159
+
160
+ const isTransactionAmountValid = (transaction: StatusResponseSuccess): boolean => {
161
+ const { order } = params.paymentContext;
162
+ const { currency, amount } = roundedAmountFromOrder(order, params.context);
163
+ if (
164
+ transaction.currency !== currency ||
165
+ (transaction.detail.authorize as any)?.amount !== amount
166
+ ) {
167
+ logger.verbose(
168
+ `currency: ${transaction.currency} === ${currency} => ${
169
+ transaction.currency === currency
170
+ }, amount: ${(transaction.detail.authorize as any)?.amount} === ${amount} => ${
171
+ (transaction.detail.authorize as any)?.amount === amount
172
+ }`,
173
+ );
174
+ return false;
175
+ }
176
+ return true;
177
+ };
178
+
179
+ const checkIfTransactionAmountValid = (
180
+ transactionId: string,
181
+ transaction: StatusResponseSuccess,
182
+ ): void => {
183
+ if (!isTransactionAmountValid(transaction)) {
184
+ logger.error(
185
+ `Transaction declined / Transaction ID ${transactionId} because of amount/currency mismatch`,
186
+ );
187
+ throw newDatatransError({
188
+ code: `YOU_HAVE_TO_PAY_THE_FULL_AMOUNT_DUDE`,
189
+ message: 'Amount / Currency Mismatch with Cart',
190
+ });
191
+ }
192
+ };
193
+
194
+ const settle = async ({ transactionId, refno, refno2, extensions }): Promise<boolean> => {
195
+ const { order } = params.paymentContext;
196
+ const { currency, amount } = roundedAmountFromOrder(order, params.context);
197
+ const splits = await getMarketplaceSplits();
198
+ const result = await api().settle({
199
+ transactionId,
200
+ amount,
201
+ refno,
202
+ refno2,
203
+ currency,
204
+ marketplace: splits.length
205
+ ? {
206
+ splits,
207
+ }
208
+ : undefined,
209
+ extensions,
210
+ });
211
+ throwIfResponseError(result);
212
+ return result as boolean;
213
+ };
214
+
215
+ const cancel = async ({ transactionId, refno }): Promise<boolean> => {
216
+ const result = await api().cancel({
217
+ transactionId,
218
+ refno,
219
+ });
220
+ throwIfResponseError(result);
221
+ return result as boolean;
222
+ };
223
+
224
+ const adapterActions = {
225
+ ...PaymentAdapter.actions(params),
226
+
227
+ configurationError() {
228
+ if (!getMerchantId() || !DATATRANS_SECRET || !DATATRANS_SIGN_KEY) {
229
+ return PaymentError.INCOMPLETE_CONFIGURATION;
230
+ }
231
+ return null;
232
+ },
233
+
234
+ isActive() {
235
+ if (adapterActions.configurationError() === null) return true;
236
+ return false;
237
+ },
238
+
239
+ isPayLaterAllowed() {
240
+ return false;
241
+ },
242
+
243
+ async sign(transactionContext: any = {}) {
244
+ const { useSecureFields = false, ...additionalInitPayload } = transactionContext || {};
245
+ const { orderPayment, paymentProviderId, order } = params.paymentContext;
246
+
247
+ const userId = order?.userId || params.context?.userId;
248
+
249
+ const refno = Buffer.from(orderPayment ? orderPayment._id : paymentProviderId, 'hex').toString(
250
+ 'base64',
251
+ );
252
+ const refno2 = userId;
253
+ const price: { amount?: number; currency?: string } = order
254
+ ? roundedAmountFromOrder(order, params.context)
255
+ : {};
256
+
257
+ if (useSecureFields) {
258
+ const result = await api().secureFields({
259
+ ...additionalInitPayload,
260
+ currency: price.currency || 'CHF',
261
+ refno,
262
+ refno2,
263
+ customer: {
264
+ id: userId,
265
+ },
266
+ amount: price.amount,
267
+ });
268
+ throwIfResponseError(result);
269
+ return JSON.stringify(result as InitResponseSuccess);
270
+ }
271
+ const result = await api().init({
272
+ ...additionalInitPayload,
273
+ currency: price.currency || 'CHF',
274
+ refno,
275
+ refno2,
276
+ customer: {
277
+ id: userId,
278
+ },
279
+ amount: price.amount,
280
+ });
281
+ throwIfResponseError(result);
282
+ return JSON.stringify(result as InitResponseSuccess);
283
+ },
284
+
285
+ async validate(credentials) {
286
+ if (!credentials.meta) return false;
287
+ const { objectKey, currency } = credentials.meta;
288
+ const result = await api().validate({
289
+ refno: Buffer.from(`valid-${new Date().getTime()}`, 'hex').toString('base64'),
290
+ currency,
291
+ [objectKey]: JSON.parse(credentials.token),
292
+ });
293
+ return (result as ValidateResponseSuccess)?.transactionId;
294
+ },
295
+
296
+ async register(transactionResponse) {
297
+ const { transactionId } = transactionResponse;
298
+ const result = (await api().status({
299
+ transactionId,
300
+ })) as StatusResponseSuccess;
301
+ if (result.transactionId) {
302
+ return parseRegistrationData(result);
303
+ }
304
+ return null;
305
+ },
306
+
307
+ async confirm() {
308
+ if (!shouldSettleInUnchained()) return false;
309
+ const { orderPayment, transactionContext } = params.paymentContext;
310
+ const { transactionId } = orderPayment;
311
+ if (!transactionId) {
312
+ return false;
313
+ }
314
+ const transaction: StatusResponseSuccess = (await api().status({
315
+ transactionId,
316
+ })) as StatusResponseSuccess;
317
+ throwIfResponseError(transaction);
318
+ const { status } = transaction;
319
+
320
+ if (status === 'authorized') {
321
+ // either settle or cancel
322
+ // if further deferred settlement is active, don't settle in unchained and hand off
323
+ // settlement to other systems
324
+ await settle({
325
+ transactionId,
326
+ refno: transaction.refno,
327
+ refno2: transaction.refno2,
328
+ extensions: transactionContext,
329
+ });
330
+ }
331
+ return true;
332
+ },
333
+
334
+ async cancel() {
335
+ if (!shouldSettleInUnchained()) return false;
336
+ const { orderPayment } = params.paymentContext;
337
+ const { transactionId } = orderPayment;
338
+ if (!transactionId) {
339
+ return false;
340
+ }
341
+ const transaction: StatusResponseSuccess = (await api().status({
342
+ transactionId,
343
+ })) as StatusResponseSuccess;
344
+ throwIfResponseError(transaction);
345
+ const { status } = transaction;
346
+
347
+ if (status === 'authorized') {
348
+ // either settle or cancel
349
+ // if further deferred settlement is active, don't settle in unchained and hand off
350
+ // settlement to other systems
351
+ await cancel({
352
+ transactionId,
353
+ refno: transaction.refno,
354
+ });
355
+ }
356
+ return true;
357
+ },
358
+
359
+ async charge({
360
+ transactionId: rawTransactionId,
361
+ paymentCredentials,
362
+ authorizeAuthenticated,
363
+ ...extensions
364
+ }) {
365
+ if (!rawTransactionId && !paymentCredentials) {
366
+ logger.warn(
367
+ 'Not trying to charge because of missing payment authorization response, return false to provide later',
368
+ );
369
+ return false;
370
+ }
371
+
372
+ const transactionId =
373
+ rawTransactionId ||
374
+ (await authorize({
375
+ paymentCredentials,
376
+ extensions,
377
+ }));
378
+
379
+ const transaction: StatusResponseSuccess = (await api().status({
380
+ transactionId,
381
+ })) as StatusResponseSuccess;
382
+ throwIfResponseError(transaction);
383
+
384
+ if (!transaction) {
385
+ throw newDatatransError({
386
+ code: `TRANSACTION_NOT_FOUND`,
387
+ message: 'Amount / Currency Mismatch with Cart',
388
+ });
389
+ }
390
+ let { status } = transaction;
391
+
392
+ if (status === 'canceled' || status === 'failed') {
393
+ logger.error(
394
+ `Payment declined or canceled with Transaction ID ${transactionId} and status ${status}`,
395
+ );
396
+ throw newDatatransError({
397
+ code: `STATUS_${status.toUpperCase()}`,
398
+ message: 'Payment declined or canceled',
399
+ });
400
+ }
401
+
402
+ if (status === 'authenticated') {
403
+ if (authorizeAuthenticated) {
404
+ checkIfTransactionAmountValid(transactionId, transaction);
405
+ await authorizeAuth({
406
+ transactionId,
407
+ refno: transaction.refno,
408
+ refno2: transaction.refno2,
409
+ extensions: authorizeAuthenticated,
410
+ });
411
+ status = 'authorized';
412
+ } else {
413
+ logger.error(`Transaction declined / Transaction ID ${transactionId} not authorized yet`);
414
+ throw newDatatransError({
415
+ code: `STATUS_${status.toUpperCase()}`,
416
+ message: 'Payment authenticated but not authorized',
417
+ });
418
+ }
419
+ }
420
+
421
+ if (status === 'authorized' || status === 'settled') {
422
+ let settledTransaction = transaction;
423
+ let credentials;
424
+ // here we try to guard us against a potential
425
+ // network hicup or registration data parsing error
426
+ // at the dumbest possible moment
427
+ try {
428
+ checkIfTransactionAmountValid(transactionId, settledTransaction);
429
+ credentials = parseRegistrationData(settledTransaction);
430
+ const result = await api().status({
431
+ transactionId,
432
+ });
433
+ if ((result as ResponseError)?.error) {
434
+ settledTransaction = transaction;
435
+ } else {
436
+ settledTransaction = result as StatusResponseSuccess;
437
+ }
438
+ } catch (e) {
439
+ await cancel({ transactionId, refno: settledTransaction.refno });
440
+ logger.error(
441
+ `Transaction declined / Transaction ID ${transactionId} authorization cancelled`,
442
+ );
443
+ throw newDatatransError({
444
+ code: `STATUS_${status.toUpperCase()}`,
445
+ message: 'Payment cancelled server-side because of amount missmatch',
446
+ });
447
+ }
448
+ return {
449
+ transactionId,
450
+ settledTransaction,
451
+ extensions,
452
+ credentials,
453
+ };
454
+ }
455
+
456
+ if (
457
+ status === 'initialized' ||
458
+ status === 'challenge_required' ||
459
+ status === 'challenge_ongoing' ||
460
+ status === 'transmitted'
461
+ ) {
462
+ logger.error(`Transaction ID ${transactionId} in transit with status ${status}`);
463
+ throw newDatatransError({
464
+ code: `STATUS_${status.toUpperCase()}`,
465
+ message: 'Transaction status invalid for checkout',
466
+ });
467
+ }
468
+ return false;
469
+ },
470
+ };
471
+
472
+ return adapterActions;
473
+ },
474
+ };
475
+
476
+ PaymentDirector.registerAdapter(Datatrans);
@@ -0,0 +1,147 @@
1
+ import { useMiddlewareWithCurrentContext } from 'meteor/unchained:api';
2
+ import bodyParser from 'body-parser';
3
+ import { createLogger } from '@unchainedshop/logger';
4
+ import { Context } from '@unchainedshop/types/api';
5
+ import getPaths from './getPaths';
6
+ import generateSignature, { Security } from './generateSignature';
7
+
8
+ import type { StatusResponseSuccess } from './api/types';
9
+
10
+ const {
11
+ DATATRANS_SIGN_KEY,
12
+ DATATRANS_SIGN2_KEY,
13
+ DATATRANS_SECURITY = Security.DYNAMIC_SIGN,
14
+ } = process.env;
15
+
16
+ const logger = createLogger('unchained:core-payment:datatrans');
17
+
18
+ const { postUrl, cancelUrl, errorUrl, successUrl, returnUrl } = getPaths(true);
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
+ }
55
+
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));
75
+ return;
76
+ }
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
+ }
102
+ }
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
+ });
@@ -0,0 +1,32 @@
1
+ import splitProperties from './splitProperties';
2
+ import type { StatusResponseSuccess } from './api/types';
3
+
4
+ export default function parseRegistrationData(transaction: StatusResponseSuccess) {
5
+ const parsed = Object.entries(transaction).reduce((acc, [objectKey, payload]) => {
6
+ const { token, info, _id } = splitProperties({ objectKey, payload });
7
+ if (token) {
8
+ return {
9
+ _id,
10
+ token,
11
+ info,
12
+ objectKey,
13
+ };
14
+ }
15
+ return acc;
16
+ }, {}) as {
17
+ _id?: string;
18
+ token?: Record<string, unknown>;
19
+ info?: Record<string, unknown>;
20
+ objectKey?: string;
21
+ };
22
+ if (parsed.objectKey) {
23
+ return {
24
+ ...parsed,
25
+ paymentMethod: transaction.paymentMethod,
26
+ currency: transaction.currency,
27
+ language: transaction.language,
28
+ type: transaction.type,
29
+ };
30
+ }
31
+ return null;
32
+ }
@@ -0,0 +1,16 @@
1
+ import { Context } from '@unchainedshop/types/api';
2
+ import { Order } from '@unchainedshop/types/orders';
3
+
4
+ const roundedAmountFromOrder = (
5
+ order: Order,
6
+ context: Context,
7
+ ): { currency: string; amount: number } => {
8
+ const pricing = context.modules.orders.pricingSheet(order);
9
+ const { currency, amount } = pricing.total({ useNetPrice: false });
10
+ return {
11
+ currency,
12
+ amount: Math.round(amount),
13
+ };
14
+ };
15
+
16
+ export default roundedAmountFromOrder;