@unchainedshop/plugins 4.6.2 → 4.7.2

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 (184) hide show
  1. package/README.md +0 -2
  2. package/lib/events/node-event-emitter.d.ts +3 -1
  3. package/lib/events/node-event-emitter.js +3 -3
  4. package/lib/files/gridfs/adapter.d.ts +2 -2
  5. package/lib/files/gridfs/adapter.js +2 -5
  6. package/lib/files/gridfs/index.d.ts +5 -4
  7. package/lib/files/gridfs/index.js +30 -3
  8. package/lib/files/minio/index.d.ts +4 -5
  9. package/lib/files/minio/index.js +18 -157
  10. package/lib/payment/apple-iap/adapter.d.ts +2 -1
  11. package/lib/payment/apple-iap/adapter.js +2 -3
  12. package/lib/payment/apple-iap/index.d.ts +6 -4
  13. package/lib/payment/apple-iap/index.js +28 -3
  14. package/lib/payment/cryptopay/index.d.ts +5 -4
  15. package/lib/payment/cryptopay/index.js +31 -3
  16. package/lib/payment/datatrans-v2/index.d.ts +4 -1
  17. package/lib/payment/datatrans-v2/index.js +17 -400
  18. package/lib/payment/payrexx/index.d.ts +4 -1
  19. package/lib/payment/payrexx/index.js +19 -158
  20. package/lib/payment/postfinance-checkout/index.d.ts +5 -0
  21. package/lib/payment/postfinance-checkout/index.js +25 -186
  22. package/lib/payment/saferpay/adapter.js +1 -2
  23. package/lib/payment/saferpay/index.d.ts +5 -4
  24. package/lib/payment/saferpay/index.js +29 -3
  25. package/lib/payment/stripe/index.d.ts +4 -1
  26. package/lib/payment/stripe/index.js +22 -116
  27. package/lib/payment/stripe/stripe.js +2 -5
  28. package/lib/presets/all.d.ts +1 -70
  29. package/lib/presets/all.js +41 -27
  30. package/lib/presets/base.d.ts +1 -25
  31. package/lib/presets/base.js +56 -25
  32. package/lib/presets/countries/ch.d.ts +1 -2
  33. package/lib/presets/countries/ch.js +7 -2
  34. package/lib/presets/crypto.d.ts +3 -7
  35. package/lib/presets/crypto.js +18 -7
  36. package/package.json +15 -10
  37. package/lib/delivery/post.d.ts +0 -1
  38. package/lib/delivery/post.js +0 -23
  39. package/lib/delivery/send-message.d.ts +0 -1
  40. package/lib/delivery/send-message.js +0 -40
  41. package/lib/delivery/stores.d.ts +0 -1
  42. package/lib/delivery/stores.js +0 -43
  43. package/lib/enrollments/licensed.d.ts +0 -4
  44. package/lib/enrollments/licensed.js +0 -52
  45. package/lib/files/gridfs/handler-express.d.ts +0 -9
  46. package/lib/files/gridfs/handler-express.js +0 -110
  47. package/lib/files/gridfs/handler-fastify.d.ts +0 -3
  48. package/lib/files/gridfs/handler-fastify.js +0 -138
  49. package/lib/files/minio/handler-express.d.ts +0 -2
  50. package/lib/files/minio/handler-express.js +0 -36
  51. package/lib/files/minio/handler-fastify.d.ts +0 -3
  52. package/lib/files/minio/handler-fastify.js +0 -40
  53. package/lib/filters/local-search.d.ts +0 -3
  54. package/lib/filters/local-search.js +0 -66
  55. package/lib/filters/strict-equal.d.ts +0 -1
  56. package/lib/filters/strict-equal.js +0 -24
  57. package/lib/payment/apple-iap/handler-express.d.ts +0 -2
  58. package/lib/payment/apple-iap/handler-express.js +0 -103
  59. package/lib/payment/apple-iap/handler-fastify.d.ts +0 -3
  60. package/lib/payment/apple-iap/handler-fastify.js +0 -102
  61. package/lib/payment/braintree.d.ts +0 -1
  62. package/lib/payment/braintree.js +0 -138
  63. package/lib/payment/cryptopay/handler-express.d.ts +0 -2
  64. package/lib/payment/cryptopay/handler-express.js +0 -19
  65. package/lib/payment/cryptopay/handler-fastify.d.ts +0 -3
  66. package/lib/payment/cryptopay/handler-fastify.js +0 -17
  67. package/lib/payment/cryptopay/plugin.d.ts +0 -3
  68. package/lib/payment/cryptopay/plugin.js +0 -159
  69. package/lib/payment/datatrans-v2/handler-express.d.ts +0 -1
  70. package/lib/payment/datatrans-v2/handler-express.js +0 -71
  71. package/lib/payment/datatrans-v2/handler-fastify.d.ts +0 -2
  72. package/lib/payment/datatrans-v2/handler-fastify.js +0 -71
  73. package/lib/payment/invoice-prepaid.d.ts +0 -1
  74. package/lib/payment/invoice-prepaid.js +0 -30
  75. package/lib/payment/invoice.d.ts +0 -1
  76. package/lib/payment/invoice.js +0 -27
  77. package/lib/payment/paypal-checkout.d.ts +0 -1
  78. package/lib/payment/paypal-checkout.js +0 -87
  79. package/lib/payment/payrexx/handler-express.d.ts +0 -1
  80. package/lib/payment/payrexx/handler-express.js +0 -85
  81. package/lib/payment/payrexx/handler-fastify.d.ts +0 -2
  82. package/lib/payment/payrexx/handler-fastify.js +0 -91
  83. package/lib/payment/postfinance-checkout/handler-express.d.ts +0 -1
  84. package/lib/payment/postfinance-checkout/handler-express.js +0 -37
  85. package/lib/payment/postfinance-checkout/handler-fastify.d.ts +0 -2
  86. package/lib/payment/postfinance-checkout/handler-fastify.js +0 -40
  87. package/lib/payment/saferpay/handler-express.d.ts +0 -1
  88. package/lib/payment/saferpay/handler-express.js +0 -59
  89. package/lib/payment/saferpay/handler-fastify.d.ts +0 -2
  90. package/lib/payment/saferpay/handler-fastify.js +0 -62
  91. package/lib/payment/stripe/handler-express.d.ts +0 -5
  92. package/lib/payment/stripe/handler-express.js +0 -121
  93. package/lib/payment/stripe/handler-fastify.d.ts +0 -6
  94. package/lib/payment/stripe/handler-fastify.js +0 -131
  95. package/lib/presets/all-express.d.ts +0 -6
  96. package/lib/presets/all-express.js +0 -26
  97. package/lib/presets/all-fastify.d.ts +0 -6
  98. package/lib/presets/all-fastify.js +0 -49
  99. package/lib/presets/base-express.d.ts +0 -2
  100. package/lib/presets/base-express.js +0 -5
  101. package/lib/presets/base-fastify.d.ts +0 -3
  102. package/lib/presets/base-fastify.js +0 -16
  103. package/lib/presets/crypto-express.d.ts +0 -3
  104. package/lib/presets/crypto-express.js +0 -8
  105. package/lib/presets/crypto-fastify.d.ts +0 -3
  106. package/lib/presets/crypto-fastify.js +0 -11
  107. package/lib/pricing/delivery-swiss-tax.d.ts +0 -2
  108. package/lib/pricing/delivery-swiss-tax.js +0 -62
  109. package/lib/pricing/discount-100-off.d.ts +0 -2
  110. package/lib/pricing/discount-100-off.js +0 -30
  111. package/lib/pricing/discount-half-price-manual.d.ts +0 -2
  112. package/lib/pricing/discount-half-price-manual.js +0 -30
  113. package/lib/pricing/discount-half-price.d.ts +0 -2
  114. package/lib/pricing/discount-half-price.js +0 -33
  115. package/lib/pricing/free-delivery.d.ts +0 -2
  116. package/lib/pricing/free-delivery.js +0 -27
  117. package/lib/pricing/free-payment.d.ts +0 -2
  118. package/lib/pricing/free-payment.js +0 -27
  119. package/lib/pricing/order-delivery.d.ts +0 -2
  120. package/lib/pricing/order-delivery.js +0 -33
  121. package/lib/pricing/order-discount.d.ts +0 -2
  122. package/lib/pricing/order-discount.js +0 -74
  123. package/lib/pricing/order-items-discount.d.ts +0 -2
  124. package/lib/pricing/order-items-discount.js +0 -50
  125. package/lib/pricing/order-items.d.ts +0 -2
  126. package/lib/pricing/order-items.js +0 -43
  127. package/lib/pricing/order-payment.d.ts +0 -2
  128. package/lib/pricing/order-payment.js +0 -33
  129. package/lib/pricing/order-round.d.ts +0 -10
  130. package/lib/pricing/order-round.js +0 -135
  131. package/lib/pricing/product-catalog-price-options.d.ts +0 -2
  132. package/lib/pricing/product-catalog-price-options.js +0 -51
  133. package/lib/pricing/product-catalog-price.d.ts +0 -2
  134. package/lib/pricing/product-catalog-price.js +0 -60
  135. package/lib/pricing/product-discount.d.ts +0 -2
  136. package/lib/pricing/product-discount.js +0 -69
  137. package/lib/pricing/product-price-rateconversion.d.ts +0 -2
  138. package/lib/pricing/product-price-rateconversion.js +0 -53
  139. package/lib/pricing/product-round.d.ts +0 -10
  140. package/lib/pricing/product-round.js +0 -44
  141. package/lib/pricing/product-swiss-tax.d.ts +0 -2
  142. package/lib/pricing/product-swiss-tax.js +0 -76
  143. package/lib/quotations/manual.d.ts +0 -1
  144. package/lib/quotations/manual.js +0 -20
  145. package/lib/warehousing/eth-minter.d.ts +0 -1
  146. package/lib/warehousing/eth-minter.js +0 -120
  147. package/lib/warehousing/store.d.ts +0 -1
  148. package/lib/warehousing/store.js +0 -34
  149. package/lib/worker/budgetsms.d.ts +0 -9
  150. package/lib/worker/budgetsms.js +0 -169
  151. package/lib/worker/bulk-export.d.ts +0 -2
  152. package/lib/worker/bulk-export.js +0 -64
  153. package/lib/worker/bulk-import.d.ts +0 -2
  154. package/lib/worker/bulk-import.js +0 -65
  155. package/lib/worker/bulkgate.d.ts +0 -1
  156. package/lib/worker/bulkgate.js +0 -91
  157. package/lib/worker/email.d.ts +0 -1
  158. package/lib/worker/email.js +0 -136
  159. package/lib/worker/enrollment-order-generator.d.ts +0 -1
  160. package/lib/worker/enrollment-order-generator.js +0 -77
  161. package/lib/worker/error-notifications.d.ts +0 -9
  162. package/lib/worker/error-notifications.js +0 -61
  163. package/lib/worker/export-token.d.ts +0 -4
  164. package/lib/worker/export-token.js +0 -26
  165. package/lib/worker/external.d.ts +0 -2
  166. package/lib/worker/external.js +0 -13
  167. package/lib/worker/heartbeat.d.ts +0 -1
  168. package/lib/worker/heartbeat.js +0 -26
  169. package/lib/worker/http-request.d.ts +0 -8
  170. package/lib/worker/http-request.js +0 -56
  171. package/lib/worker/message.d.ts +0 -10
  172. package/lib/worker/message.js +0 -42
  173. package/lib/worker/push-notification.d.ts +0 -1
  174. package/lib/worker/push-notification.js +0 -87
  175. package/lib/worker/twilio.d.ts +0 -1
  176. package/lib/worker/twilio.js +0 -59
  177. package/lib/worker/update-coinbase-rates.d.ts +0 -1
  178. package/lib/worker/update-coinbase-rates.js +0 -59
  179. package/lib/worker/update-ecb-rates.d.ts +0 -1
  180. package/lib/worker/update-ecb-rates.js +0 -92
  181. package/lib/worker/update-token-ownership.d.ts +0 -3
  182. package/lib/worker/update-token-ownership.js +0 -57
  183. package/lib/worker/zombie-killer.d.ts +0 -13
  184. package/lib/worker/zombie-killer.js +0 -91
@@ -1,159 +0,0 @@
1
- import { PaymentAdapter, PaymentDirector, PaymentError, OrderPricingSheet, } from '@unchainedshop/core';
2
- import { createLogger } from '@unchainedshop/logger';
3
- import {} from "./module.js";
4
- import deriveBtcAddress from "./derive-btc-address.js";
5
- import deriveEthAddress from "./derive-eth-address.js";
6
- import denoteAmount from "./denote-amount.js";
7
- const logger = createLogger('unchained:cryptopay');
8
- const { CRYPTOPAY_SECRET, CRYPTOPAY_BTC_XPUB, CRYPTOPAY_ETH_XPUB } = process.env;
9
- const CryptopayCurrencies = {
10
- BTC: 'BTC',
11
- ETH: 'ETH',
12
- };
13
- const Cryptopay = {
14
- ...PaymentAdapter,
15
- key: 'shop.unchained.payment.cryptopay',
16
- label: 'Cryptopay',
17
- version: '1.0.0',
18
- typeSupported(type) {
19
- return type === 'GENERIC';
20
- },
21
- actions: (config, context) => {
22
- const { modules } = context;
23
- const setConversionRates = async (currencyCode, existingAddresses) => {
24
- const originCurrencyObj = await modules.currencies.findCurrency({ isoCode: currencyCode });
25
- if (!originCurrencyObj?.isActive)
26
- throw new Error('Origin currency is not supported');
27
- const updatedAddresses = await Promise.all(existingAddresses.map(async (addressData) => {
28
- const targetCurrencyObj = await modules.currencies.findCurrency({
29
- isoCode: addressData.currencyCode,
30
- });
31
- if (!targetCurrencyObj?.isActive)
32
- return null;
33
- const rateData = await modules.products.prices.rates.getRate(originCurrencyObj, targetCurrencyObj);
34
- return {
35
- ...addressData,
36
- currencyConversionRate: rateData?.rate,
37
- currencyConversionExpiryDate: rateData?.expiresAt,
38
- };
39
- }));
40
- return updatedAddresses.filter(Boolean);
41
- };
42
- const updateTransactionsWithOrderPaymentId = async (orderPaymentId, cryptoAddresses) => {
43
- for (const cryptoAddress of cryptoAddresses) {
44
- const { address, currencyCode } = cryptoAddress;
45
- await modules.cryptopay.mapOrderPaymentToWalletAddress({
46
- address,
47
- currencyCode,
48
- orderPaymentId,
49
- });
50
- }
51
- };
52
- const adapterActions = {
53
- ...PaymentAdapter.actions(config, context),
54
- configurationError() {
55
- if (!CRYPTOPAY_SECRET) {
56
- return PaymentError.INCOMPLETE_CONFIGURATION;
57
- }
58
- if (!CRYPTOPAY_BTC_XPUB && !CRYPTOPAY_ETH_XPUB) {
59
- return PaymentError.INCOMPLETE_CONFIGURATION;
60
- }
61
- return null;
62
- },
63
- isActive() {
64
- if (adapterActions.configurationError() !== null)
65
- return false;
66
- if (!context.order)
67
- return true;
68
- return true;
69
- },
70
- isPayLaterAllowed() {
71
- return false;
72
- },
73
- sign: async () => {
74
- const { orderPayment, order } = context;
75
- if (!orderPayment)
76
- throw new Error('Payment Credential Registration is not yet supported for Cryptopay');
77
- if (!order)
78
- throw new Error('Order context is required for signing with Cryptopay');
79
- const existingAddresses = await modules.cryptopay.getWalletAddressesByOrderPaymentId(orderPayment._id);
80
- if (existingAddresses.length) {
81
- const existingAddressesWithNewExpiration = await setConversionRates(order.currencyCode, existingAddresses.map(({ _id, currencyCode }) => ({
82
- address: _id,
83
- currencyCode,
84
- })));
85
- return JSON.stringify(existingAddressesWithNewExpiration);
86
- }
87
- const cryptoAddresses = [];
88
- if (CRYPTOPAY_BTC_XPUB) {
89
- const btcDerivationNumber = await modules.cryptopay.getNextDerivationNumber(CryptopayCurrencies.BTC);
90
- const address = deriveBtcAddress(CRYPTOPAY_BTC_XPUB, btcDerivationNumber);
91
- cryptoAddresses.push({
92
- currencyCode: CryptopayCurrencies.BTC,
93
- address,
94
- });
95
- }
96
- if (CRYPTOPAY_ETH_XPUB) {
97
- const ethDerivationNumber = await modules.cryptopay.getNextDerivationNumber(CryptopayCurrencies.ETH);
98
- const address = deriveEthAddress(CRYPTOPAY_ETH_XPUB, ethDerivationNumber);
99
- cryptoAddresses.push({
100
- currencyCode: CryptopayCurrencies.ETH,
101
- address,
102
- });
103
- }
104
- const cryptoAddressesWithExpiration = await setConversionRates(order.currencyCode, cryptoAddresses);
105
- await updateTransactionsWithOrderPaymentId(orderPayment._id, cryptoAddresses);
106
- return JSON.stringify(cryptoAddressesWithExpiration);
107
- },
108
- charge: async () => {
109
- const { order, orderPayment } = context;
110
- if (!orderPayment)
111
- throw new Error('Order Payment context is required for charging with Cryptopay');
112
- if (!order)
113
- throw new Error('Order context is required for charging with Cryptopay');
114
- const foundWalletsWithBalances = await modules.cryptopay.getWalletAddressesByOrderPaymentId(orderPayment._id);
115
- const walletForOrderPayment = foundWalletsWithBalances.find((wallet) => BigInt(wallet.amount.toString()) > 0n);
116
- const pricing = OrderPricingSheet({
117
- calculation: order.calculation,
118
- currencyCode: order.currencyCode,
119
- });
120
- const totalAmount = BigInt(pricing?.total({ useNetPrice: false }).amount);
121
- if (walletForOrderPayment && walletForOrderPayment.currencyCode !== order.currencyCode) {
122
- const baseCurrency = await modules.currencies.findCurrency({
123
- isoCode: walletForOrderPayment.currencyCode,
124
- });
125
- if (!baseCurrency)
126
- throw new Error('Base currency not found');
127
- const quoteCurrency = await modules.currencies.findCurrency({ isoCode: order.currencyCode });
128
- if (!quoteCurrency)
129
- throw new Error('Quote currency not found');
130
- const rate = await modules.products.prices.rates.getRateRange(baseCurrency, quoteCurrency, order.confirmed || new Date());
131
- if (!rate)
132
- throw new Error('No conversion rate found');
133
- const convertedAmount = denoteAmount(walletForOrderPayment.amount.toString(), walletForOrderPayment.decimals);
134
- const maxAmount = parseFloat(convertedAmount.toString()) * rate.max * 1.001;
135
- if (maxAmount && maxAmount >= totalAmount) {
136
- return {
137
- transactionId: walletForOrderPayment._id,
138
- };
139
- }
140
- logger.info(`Cryptopay Plugin: Wallet ${walletForOrderPayment._id} balance too low (yet): ${maxAmount} < ${totalAmount}`);
141
- }
142
- if (walletForOrderPayment) {
143
- const convertedAmount = denoteAmount(walletForOrderPayment.amount.toString(), walletForOrderPayment.decimals);
144
- if (convertedAmount && convertedAmount >= totalAmount) {
145
- return {
146
- transactionId: walletForOrderPayment._id,
147
- };
148
- }
149
- logger.info(`Cryptopay Plugin: Wallet ${walletForOrderPayment._id} balance too low (yet): ${convertedAmount} < ${totalAmount}`);
150
- }
151
- logger.info(`Cryptopay Plugin: No confirmed payments found for currency ${order.currencyCode} and addresses ${JSON.stringify(foundWalletsWithBalances)}`);
152
- return false;
153
- },
154
- };
155
- return adapterActions;
156
- },
157
- };
158
- PaymentDirector.registerAdapter(Cryptopay);
159
- export default Cryptopay;
@@ -1 +0,0 @@
1
- export declare const datatransHandler: (req: any, res: any) => Promise<void>;
@@ -1,71 +0,0 @@
1
- import { createLogger } from '@unchainedshop/logger';
2
- import generateSignature, { Security } from "./generateSignature.js";
3
- const { DATATRANS_SIGN_KEY, DATATRANS_SIGN2_KEY, DATATRANS_SECURITY = Security.DYNAMIC_SIGN, } = process.env;
4
- const logger = createLogger('unchained:datatrans:handler');
5
- export const datatransHandler = async (req, res) => {
6
- const resolvedContext = req.unchainedContext;
7
- const { modules, services } = resolvedContext;
8
- const signature = req.headers['datatrans-signature'];
9
- if (!DATATRANS_SIGN_KEY && !DATATRANS_SIGN2_KEY) {
10
- logger.warn('No sign key configured');
11
- res.status(404).end();
12
- return;
13
- }
14
- if (req.method === 'POST' && signature) {
15
- const [rawTimestamp, rawHash] = signature.split(',');
16
- const [, hash] = rawHash.split('=');
17
- const [, timestamp] = rawTimestamp.split('=');
18
- const comparableSignature = await generateSignature({
19
- security: DATATRANS_SECURITY,
20
- signKey: DATATRANS_SIGN2_KEY || DATATRANS_SIGN_KEY,
21
- })(timestamp, req.body);
22
- if (hash !== comparableSignature) {
23
- logger.error(`hash mismatch: ${signature} / ${comparableSignature}`);
24
- res.status(403).send('Hash mismatch');
25
- return;
26
- }
27
- const transaction = JSON.parse(req.body);
28
- logger.info(`received request`, {
29
- type: transaction.type,
30
- });
31
- if (transaction.status === 'authorized') {
32
- const userId = transaction.refno2;
33
- const referenceId = Buffer.from(transaction.refno, 'base64').toString('hex');
34
- try {
35
- if (transaction.type === 'card_check') {
36
- const paymentProviderId = referenceId;
37
- const paymentCredentials = await services.orders.registerPaymentCredentials(paymentProviderId, { userId, transactionContext: { transactionId: transaction.transactionId } });
38
- logger.info(`registered payment credentials for ${userId}`, {
39
- userId,
40
- });
41
- res.status(200).send(paymentCredentials);
42
- return;
43
- }
44
- if (transaction.type === 'payment') {
45
- const orderPaymentId = referenceId;
46
- const orderPayment = await modules.orders.payments.findOrderPayment({
47
- orderPaymentId,
48
- });
49
- if (!orderPayment)
50
- throw new Error(`Order Payment with id ${orderPaymentId} not found`);
51
- const order = await services.orders.checkoutOrder(orderPayment.orderId, {
52
- paymentContext: { userId, transactionId: transaction.transactionId },
53
- });
54
- if (!order)
55
- throw new Error(`Order with id ${orderPayment.orderId} not found`);
56
- logger.info(`confirmed checkout for order ${order.orderNumber}`, {
57
- orderId: order._id,
58
- });
59
- res.status(200).send(order);
60
- return;
61
- }
62
- }
63
- catch (e) {
64
- logger.error(`rejected to checkout: ${e.name} - ${e.message}`);
65
- res.status(500).send({ name: e.name, code: e.code, message: e.message });
66
- return;
67
- }
68
- }
69
- }
70
- res.status(404).end();
71
- };
@@ -1,2 +0,0 @@
1
- import type { RouteHandlerMethod } from 'fastify';
2
- export declare const datatransHandler: RouteHandlerMethod;
@@ -1,71 +0,0 @@
1
- import { createLogger } from '@unchainedshop/logger';
2
- import generateSignature, { Security } from "./generateSignature.js";
3
- const { DATATRANS_SIGN_KEY, DATATRANS_SIGN2_KEY, DATATRANS_SECURITY = Security.DYNAMIC_SIGN, } = process.env;
4
- const logger = createLogger('unchained:datatrans:handler');
5
- export const datatransHandler = async (req, reply) => {
6
- const resolvedContext = req.unchainedContext;
7
- const { modules, services } = resolvedContext;
8
- const signature = req.headers['datatrans-signature'];
9
- if (!DATATRANS_SIGN_KEY && !DATATRANS_SIGN2_KEY) {
10
- logger.warn('No sign key configured');
11
- return reply.send({ success: false, message: 'No sign key configured', name: 'NO_SIGN_KEY' });
12
- }
13
- if (signature) {
14
- const [rawTimestamp, rawHash] = signature.split(',');
15
- const [, hash] = rawHash.split('=');
16
- const [, timestamp] = rawTimestamp.split('=');
17
- const comparableSignature = await generateSignature({
18
- security: DATATRANS_SECURITY,
19
- signKey: DATATRANS_SIGN2_KEY || DATATRANS_SIGN_KEY,
20
- })(timestamp, req.body);
21
- if (hash !== comparableSignature) {
22
- logger.error(`hash mismatch: ${signature} / ${comparableSignature}`);
23
- reply.status(403);
24
- return reply.send({ success: false, message: 'Invalid Signature', name: 'HASH_MISMATCH' });
25
- }
26
- const transaction = JSON.parse(req.body);
27
- logger.info(`received request`, {
28
- type: transaction.type,
29
- });
30
- if (transaction.status === 'authorized') {
31
- const userId = transaction.refno2;
32
- const referenceId = Buffer.from(transaction.refno, 'base64').toString('hex');
33
- try {
34
- if (transaction.type === 'card_check') {
35
- const paymentProviderId = referenceId;
36
- const paymentCredentials = await services.orders.registerPaymentCredentials(paymentProviderId, { userId, transactionContext: { transactionId: transaction.transactionId } });
37
- logger.info(`registered payment credentials for ${userId}`, {
38
- userId,
39
- });
40
- reply.status(200);
41
- return reply.send(paymentCredentials);
42
- }
43
- if (transaction.type === 'payment') {
44
- const orderPaymentId = referenceId;
45
- const orderPayment = await modules.orders.payments.findOrderPayment({
46
- orderPaymentId,
47
- });
48
- if (!orderPayment)
49
- throw new Error(`Order Payment with id ${orderPaymentId} not found`);
50
- const order = await services.orders.checkoutOrder(orderPayment.orderId, {
51
- paymentContext: { userId, transactionId: transaction.transactionId },
52
- });
53
- if (!order)
54
- throw new Error(`Order with id ${orderPayment.orderId} not found`);
55
- reply.status(200);
56
- logger.info(`confirmed checkout for order ${order.orderNumber}`, {
57
- orderId: order._id,
58
- });
59
- return reply.send(order);
60
- }
61
- }
62
- catch (e) {
63
- logger.error(e);
64
- reply.status(500);
65
- return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
66
- }
67
- }
68
- }
69
- reply.status(404);
70
- return reply.send();
71
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,30 +0,0 @@
1
- import { PaymentAdapter, PaymentDirector } from '@unchainedshop/core';
2
- import { PaymentProviderType } from '@unchainedshop/core-payment';
3
- const InvoicePrepaid = {
4
- ...PaymentAdapter,
5
- key: 'shop.unchained.invoice-prepaid',
6
- label: 'Invoice pre-paid',
7
- version: '1.0.0',
8
- initialConfiguration: [],
9
- typeSupported: (type) => {
10
- return type === PaymentProviderType.INVOICE;
11
- },
12
- actions: (config, context) => {
13
- return {
14
- ...PaymentAdapter.actions(config, context),
15
- configurationError: () => {
16
- return null;
17
- },
18
- isActive: () => {
19
- return true;
20
- },
21
- isPayLaterAllowed: () => {
22
- return false;
23
- },
24
- charge: async () => {
25
- return false;
26
- },
27
- };
28
- },
29
- };
30
- PaymentDirector.registerAdapter(InvoicePrepaid);
@@ -1 +0,0 @@
1
- export {};
@@ -1,27 +0,0 @@
1
- import { PaymentAdapter, PaymentDirector } from '@unchainedshop/core';
2
- import { PaymentProviderType } from '@unchainedshop/core-payment';
3
- const Invoice = {
4
- ...PaymentAdapter,
5
- key: 'shop.unchained.invoice',
6
- label: 'Invoice',
7
- version: '1.0.0',
8
- initialConfiguration: [],
9
- typeSupported: (type) => {
10
- return type === PaymentProviderType.INVOICE;
11
- },
12
- actions: (config, context) => {
13
- return {
14
- ...PaymentAdapter.actions(config, context),
15
- configurationError: () => {
16
- return null;
17
- },
18
- isActive: () => {
19
- return true;
20
- },
21
- isPayLaterAllowed: () => {
22
- return true;
23
- },
24
- };
25
- },
26
- };
27
- PaymentDirector.registerAdapter(Invoice);
@@ -1 +0,0 @@
1
- export {};
@@ -1,87 +0,0 @@
1
- import { OrderPricingSheet, PaymentAdapter, PaymentDirector, PaymentError, } from '@unchainedshop/core';
2
- import { createLogger } from '@unchainedshop/logger';
3
- const logger = createLogger('unchained:paypal-checkout');
4
- let checkoutNodeJssdk;
5
- try {
6
- checkoutNodeJssdk = await import('@paypal/checkout-server-sdk');
7
- }
8
- catch {
9
- logger.warn("npm dependency '@paypal/checkout-server-sdk' is not installed, paypal adapter will not work");
10
- }
11
- const { PAYPAL_CLIENT_ID, PAYPAL_SECRET, PAYPAL_ENVIRONMENT = 'sandbox' } = process.env;
12
- const environment = () => {
13
- const clientId = PAYPAL_CLIENT_ID;
14
- const clientSecret = PAYPAL_SECRET;
15
- return PAYPAL_ENVIRONMENT !== 'live'
16
- ? new checkoutNodeJssdk.core.SandboxEnvironment(clientId, clientSecret)
17
- : new checkoutNodeJssdk.core.LiveEnvironment(clientId, clientSecret);
18
- };
19
- const roundToDecimals = (number, decimals) => {
20
- const num = Math.pow(10, decimals);
21
- return Math.round(number * num) / num;
22
- };
23
- const PaypalCheckout = {
24
- ...PaymentAdapter,
25
- key: 'shop.unchained.payment.paypal',
26
- label: 'Paypal',
27
- version: '1.0.1',
28
- initialConfiguration: [],
29
- typeSupported: (type) => {
30
- return type === 'GENERIC';
31
- },
32
- actions: (config, context) => {
33
- const adapter = {
34
- ...PaymentAdapter.actions(config, context),
35
- configurationError: () => {
36
- const publicCredentialsValid = PAYPAL_CLIENT_ID && PAYPAL_SECRET;
37
- if (!publicCredentialsValid) {
38
- return PaymentError.WRONG_CREDENTIALS;
39
- }
40
- return null;
41
- },
42
- isActive: () => {
43
- if (adapter.configurationError() === null)
44
- return true;
45
- return false;
46
- },
47
- isPayLaterAllowed: () => {
48
- return false;
49
- },
50
- sign: async () => {
51
- return PAYPAL_CLIENT_ID || null;
52
- },
53
- charge: async ({ orderID }) => {
54
- const { order } = context;
55
- if (!order)
56
- throw new Error('Order missing in payment context');
57
- if (!orderID) {
58
- throw new Error('You have to provide orderID in paymentContext');
59
- }
60
- try {
61
- const request = new checkoutNodeJssdk.orders.OrdersGetRequest(orderID);
62
- const client = new checkoutNodeJssdk.core.PayPalHttpClient(environment());
63
- const paypalOrder = await client.execute(request);
64
- const pricing = OrderPricingSheet({
65
- calculation: order.calculation,
66
- currencyCode: order.currencyCode,
67
- });
68
- const ourTotal = roundToDecimals(pricing.total({ useNetPrice: false }).amount / 100, 2);
69
- const paypalTotal = roundToDecimals(paypalOrder.result.purchase_units[0].amount.value, 2);
70
- if (ourTotal === paypalTotal) {
71
- return order;
72
- }
73
- logger.warn('Missmatch PAYPAL ORDER', JSON.stringify(paypalOrder.result, null, 2));
74
- logger.debug('OUR ORDER', order);
75
- logger.debug('OUR PRICE', pricing);
76
- throw new Error(`Payment mismatch`);
77
- }
78
- catch (e) {
79
- logger.warn(e);
80
- throw new Error(e);
81
- }
82
- },
83
- };
84
- return adapter;
85
- },
86
- };
87
- PaymentDirector.registerAdapter(PaypalCheckout);
@@ -1 +0,0 @@
1
- export declare const payrexxHandler: (request: any, response: any) => Promise<void>;
@@ -1,85 +0,0 @@
1
- import { createLogger } from '@unchainedshop/logger';
2
- const logger = createLogger('unchained:payrexx:handler');
3
- export const payrexxHandler = async (request, response) => {
4
- const resolvedContext = request.unchainedContext;
5
- const { modules, services } = resolvedContext;
6
- const { transaction } = request.body;
7
- if (!transaction) {
8
- logger.info(`unhandled event type`, {
9
- type: Object.keys(request.body).join(','),
10
- });
11
- response.status(200).send({
12
- ignored: true,
13
- message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
14
- });
15
- return;
16
- }
17
- if (transaction.referenceId === '__IGNORE_WEBHOOK__' || transaction.status === 'waiting') {
18
- logger.info(`unhandled transaction state: ${transaction.status}`);
19
- response.status(200).send({
20
- ignored: true,
21
- message: `Unhandled transaction state: ${transaction.status}`,
22
- });
23
- return;
24
- }
25
- logger.info(`Processing event`, {
26
- transactionId: transaction.id,
27
- });
28
- try {
29
- if (transaction.preAuthorizationId) {
30
- const { referenceId: paymentProviderId, invoice } = transaction;
31
- const userId = '';
32
- logger.info(`register credentials for: ${userId}`);
33
- await services.orders.registerPaymentCredentials(paymentProviderId, {
34
- userId,
35
- transactionContext: { gatewayId: invoice.paymentRequestId },
36
- });
37
- logger.info(`registration successful`, {
38
- paymentProviderId,
39
- userId,
40
- });
41
- response.status(200).send({
42
- message: 'registration successful',
43
- paymentProviderId,
44
- userId,
45
- });
46
- }
47
- else {
48
- const { referenceId: orderPaymentId, invoice } = transaction;
49
- logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
50
- await modules.orders.payments.logEvent(orderPaymentId, {
51
- transactionId: transaction.id,
52
- });
53
- const orderPayment = await modules.orders.payments.findOrderPayment({
54
- orderPaymentId,
55
- });
56
- if (!orderPayment) {
57
- throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
58
- }
59
- const order = await services.orders.checkoutOrder(orderPayment.orderId, {
60
- paymentContext: {
61
- gatewayId: invoice.paymentRequestId,
62
- },
63
- });
64
- if (!order)
65
- throw new Error(`Order with id ${orderPayment.orderId} not found`);
66
- logger.info(`checkout successful`, {
67
- orderPaymentId,
68
- orderId: order._id,
69
- });
70
- response.status(200).send({
71
- message: 'checkout successful',
72
- orderId: order._id,
73
- });
74
- }
75
- }
76
- catch (error) {
77
- logger.error(error, {
78
- transactionId: transaction.id,
79
- });
80
- response.status(500).send({
81
- message: error.message,
82
- name: error.name,
83
- });
84
- }
85
- };
@@ -1,2 +0,0 @@
1
- import type { RouteHandlerMethod } from 'fastify';
2
- export declare const payrexxHandler: RouteHandlerMethod;
@@ -1,91 +0,0 @@
1
- import { createLogger } from '@unchainedshop/logger';
2
- const logger = createLogger('unchained:payrexx:handler');
3
- export const payrexxHandler = async (request, reply) => {
4
- const resolvedContext = request.unchainedContext;
5
- const { modules, services } = resolvedContext;
6
- const { transaction } = request.body;
7
- if (!transaction) {
8
- logger.info(`unhandled event type`, {
9
- type: Object.keys(request.body).join(','),
10
- });
11
- reply.status(200);
12
- return reply.send({
13
- success: false,
14
- ignored: true,
15
- message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
16
- });
17
- }
18
- if (transaction.referenceId === '__IGNORE_WEBHOOK__' || transaction.status === 'waiting') {
19
- logger.info(`unhandled transaction state: ${transaction.status}`);
20
- reply.status(200);
21
- return reply.send({
22
- success: false,
23
- ignored: true,
24
- message: `Unhandled transaction state: ${transaction.status}`,
25
- });
26
- }
27
- logger.info(`Processing event`, {
28
- transactionId: transaction.id,
29
- });
30
- try {
31
- if (transaction.preAuthorizationId) {
32
- const { referenceId: paymentProviderId, invoice } = transaction;
33
- const userId = '';
34
- logger.info(`register credentials for: ${userId}`);
35
- await services.orders.registerPaymentCredentials(paymentProviderId, {
36
- userId,
37
- transactionContext: { gatewayId: invoice.paymentRequestId },
38
- });
39
- logger.info(`registration successful`, {
40
- paymentProviderId,
41
- userId,
42
- });
43
- reply.status(200);
44
- return reply.send({
45
- success: true,
46
- paymentProviderId,
47
- userId,
48
- });
49
- }
50
- else {
51
- const { referenceId: orderPaymentId, invoice } = transaction;
52
- logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
53
- const orderPayment = await modules.orders.payments.findOrderPayment({
54
- orderPaymentId,
55
- });
56
- if (!orderPayment) {
57
- throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
58
- }
59
- await modules.orders.payments.logEvent(orderPaymentId, {
60
- transactionId: transaction.id,
61
- });
62
- const order = await services.orders.checkoutOrder(orderPayment.orderId, {
63
- paymentContext: {
64
- gatewayId: invoice.paymentRequestId,
65
- },
66
- });
67
- if (!order)
68
- throw new Error(`Order with id ${orderPayment.orderId} not found`);
69
- logger.info(`checkout successful`, {
70
- orderPaymentId,
71
- orderId: order._id,
72
- });
73
- reply.status(200);
74
- return reply.send({
75
- success: true,
76
- orderId: order._id,
77
- });
78
- }
79
- }
80
- catch (error) {
81
- logger.error(error, {
82
- transactionId: transaction.id,
83
- });
84
- reply.status(500);
85
- return reply.send({
86
- success: false,
87
- message: error.message,
88
- name: error.name,
89
- });
90
- }
91
- };
@@ -1 +0,0 @@
1
- export declare const postfinanceCheckoutHandler: (req: any, res: any) => Promise<void>;