@unchainedshop/plugins 3.1.14 → 4.0.0-rc.10
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.
- package/lib/delivery/pick-mup.js +0 -2
- package/lib/delivery/pick-mup.js.map +1 -1
- package/lib/files/gridfs/adapter.d.ts.map +1 -1
- package/lib/files/gridfs/adapter.js +3 -2
- package/lib/files/gridfs/adapter.js.map +1 -1
- package/lib/files/gridfs/handler-express.d.ts.map +1 -1
- package/lib/files/gridfs/handler-express.js +6 -2
- package/lib/files/gridfs/handler-express.js.map +1 -1
- package/lib/files/gridfs/handler-fastify.d.ts.map +1 -1
- package/lib/files/gridfs/handler-fastify.js +5 -2
- package/lib/files/gridfs/handler-fastify.js.map +1 -1
- package/lib/files/gridfs/module.d.ts +2 -2
- package/lib/files/gridfs/module.d.ts.map +1 -1
- package/lib/filters/local-search.d.ts.map +1 -1
- package/lib/filters/local-search.js +9 -2
- package/lib/filters/local-search.js.map +1 -1
- package/lib/filters/strict-equal.js +18 -0
- package/lib/filters/strict-equal.js.map +1 -1
- package/lib/payment/apple-iap/adapter.js +6 -13
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/fix-periods.d.ts.map +1 -1
- package/lib/payment/apple-iap/fix-periods.js +3 -5
- package/lib/payment/apple-iap/fix-periods.js.map +1 -1
- package/lib/payment/apple-iap/handler-express.js +4 -4
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +4 -4
- package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
- package/lib/payment/apple-iap/module.d.ts +2 -2
- package/lib/payment/apple-iap/module.d.ts.map +1 -1
- package/lib/payment/braintree.js +3 -4
- package/lib/payment/braintree.js.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -2
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.js.map +1 -1
- package/lib/payment/cryptopay/handle-webhook.js +1 -1
- package/lib/payment/cryptopay/handle-webhook.js.map +1 -1
- package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-express.js +4 -57
- package/lib/payment/cryptopay/handler-express.js.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.js +4 -56
- package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
- package/lib/payment/cryptopay/module.d.ts +26 -26
- package/lib/payment/cryptopay/module.d.ts.map +1 -1
- package/lib/payment/cryptopay/module.js +26 -24
- package/lib/payment/cryptopay/module.js.map +1 -1
- package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
- package/lib/payment/cryptopay/plugin.js +33 -79
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/datatrans-v2/api/types.d.ts +41 -41
- package/lib/payment/datatrans-v2/api/types.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/getPaths.d.ts +2 -2
- package/lib/payment/datatrans-v2/getPaths.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/index.js +16 -14
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +3 -3
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -1
- package/lib/payment/paypal-checkout.js +6 -8
- package/lib/payment/paypal-checkout.js.map +1 -1
- package/lib/payment/payrexx/api/index.d.ts +2 -2
- package/lib/payment/payrexx/api/index.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
- package/lib/payment/payrexx/index.js +4 -4
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/payrexx/payrexx.js +2 -2
- package/lib/payment/payrexx/payrexx.js.map +1 -1
- package/lib/payment/postfinance-checkout/api-client.d.ts +16 -0
- package/lib/payment/postfinance-checkout/api-client.d.ts.map +1 -0
- package/lib/payment/postfinance-checkout/api-client.js +75 -0
- package/lib/payment/postfinance-checkout/api-client.js.map +1 -0
- package/lib/payment/postfinance-checkout/api-types.d.ts +98 -0
- package/lib/payment/postfinance-checkout/api-types.d.ts.map +1 -0
- package/lib/payment/postfinance-checkout/api-types.js +51 -0
- package/lib/payment/postfinance-checkout/api-types.js.map +1 -0
- package/lib/payment/postfinance-checkout/api.d.ts +5 -5
- package/lib/payment/postfinance-checkout/api.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/api.js +38 -62
- package/lib/payment/postfinance-checkout/api.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.js +5 -5
- package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.js +6 -6
- package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.d.ts +2 -1
- package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/index.js +27 -30
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/types.d.ts +4 -4
- package/lib/payment/postfinance-checkout/types.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/utils.d.ts +3 -3
- package/lib/payment/postfinance-checkout/utils.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/utils.js +5 -6
- package/lib/payment/postfinance-checkout/utils.js.map +1 -1
- package/lib/payment/saferpay/adapter.d.ts.map +1 -1
- package/lib/payment/saferpay/adapter.js +4 -6
- package/lib/payment/saferpay/adapter.js.map +1 -1
- package/lib/payment/saferpay/api/models/Transaction.d.ts +2 -2
- package/lib/payment/saferpay/api/models/Transaction.d.ts.map +1 -1
- package/lib/payment/saferpay/module.d.ts +2 -2
- package/lib/payment/saferpay/module.d.ts.map +1 -1
- package/lib/payment/stripe/index.js +5 -5
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/stripe.js +3 -3
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/lib/presets/all.d.ts +15 -13
- package/lib/presets/all.d.ts.map +1 -1
- package/lib/presets/all.js +3 -1
- package/lib/presets/all.js.map +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +2 -2
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/order-delivery.js +1 -1
- package/lib/pricing/order-delivery.js.map +1 -1
- package/lib/pricing/order-discount.js +3 -3
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-items-discount.js +1 -1
- package/lib/pricing/order-items-discount.js.map +1 -1
- package/lib/pricing/order-items.js +1 -1
- package/lib/pricing/order-items.js.map +1 -1
- package/lib/pricing/order-payment.js +1 -1
- package/lib/pricing/order-payment.js.map +1 -1
- package/lib/pricing/order-round.d.ts +1 -1
- package/lib/pricing/order-round.d.ts.map +1 -1
- package/lib/pricing/order-round.js +8 -8
- package/lib/pricing/order-round.js.map +1 -1
- package/lib/pricing/product-catalog-price.d.ts +0 -1
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +6 -18
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +2 -2
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/pricing/product-round.d.ts +1 -1
- package/lib/pricing/product-round.d.ts.map +1 -1
- package/lib/pricing/product-round.js +2 -2
- package/lib/pricing/product-round.js.map +1 -1
- package/lib/pricing/product-swiss-tax.d.ts +1 -1
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +2 -2
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/warehousing/eth-minter.js +2 -2
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/budgetsms.d.ts +10 -0
- package/lib/worker/budgetsms.d.ts.map +1 -0
- package/lib/worker/budgetsms.js +217 -0
- package/lib/worker/budgetsms.js.map +1 -0
- package/lib/worker/bulk-import.js +1 -1
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/bulkgate.d.ts +2 -0
- package/lib/worker/bulkgate.d.ts.map +1 -0
- package/lib/worker/bulkgate.js +104 -0
- package/lib/worker/bulkgate.js.map +1 -0
- package/lib/worker/enrollment-order-generator.js +1 -1
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/error-notifications.d.ts +4 -4
- package/lib/worker/error-notifications.d.ts.map +1 -1
- package/lib/worker/heartbeat.js +2 -8
- package/lib/worker/heartbeat.js.map +1 -1
- package/lib/worker/message.d.ts +1 -1
- package/lib/worker/message.d.ts.map +1 -1
- package/lib/worker/sms.js +16 -16
- package/lib/worker/sms.js.map +1 -1
- package/lib/worker/twilio.d.ts +2 -0
- package/lib/worker/twilio.d.ts.map +1 -0
- package/lib/worker/twilio.js +56 -0
- package/lib/worker/twilio.js.map +1 -0
- package/lib/worker/update-coinbase-rates.js +1 -1
- package/lib/worker/update-coinbase-rates.js.map +1 -1
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/package.json +32 -53
- package/src/delivery/pick-mup.ts +0 -2
- package/src/files/gridfs/adapter.ts +7 -2
- package/src/files/gridfs/handler-express.ts +9 -2
- package/src/files/gridfs/handler-fastify.ts +8 -2
- package/src/files/gridfs/module.ts +2 -2
- package/src/filters/local-search.ts +11 -2
- package/src/filters/strict-equal.ts +21 -0
- package/src/payment/apple-iap/adapter.ts +7 -14
- package/src/payment/apple-iap/fix-periods.ts +4 -7
- package/src/payment/apple-iap/handler-express.ts +4 -4
- package/src/payment/apple-iap/handler-fastify.ts +4 -4
- package/src/payment/apple-iap/module.ts +2 -2
- package/src/payment/braintree.ts +3 -4
- package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -2
- package/src/payment/cryptopay/denote-amount.test.ts +28 -0
- package/src/payment/cryptopay/denote-amount.ts +29 -0
- package/src/payment/cryptopay/derive-btc-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-btc-address.ts +48 -0
- package/src/payment/cryptopay/derive-eth-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-eth-address.ts +38 -0
- package/src/payment/cryptopay/handle-webhook.ts +103 -0
- package/src/payment/cryptopay/handler-express.ts +4 -70
- package/src/payment/cryptopay/handler-fastify.ts +6 -71
- package/src/payment/cryptopay/module.ts +44 -40
- package/src/payment/cryptopay/plugin.ts +50 -87
- package/src/payment/cryptopay/readme.md +23 -1
- package/src/payment/datatrans-v2/api/types.ts +41 -41
- package/src/payment/datatrans-v2/getPaths.ts +2 -2
- package/src/payment/datatrans-v2/index.ts +17 -15
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +4 -4
- package/src/payment/paypal-checkout.ts +6 -11
- package/src/payment/payrexx/api/index.ts +2 -2
- package/src/payment/payrexx/api/makeFetcher.ts +1 -1
- package/src/payment/payrexx/index.ts +4 -4
- package/src/payment/payrexx/payrexx.ts +2 -2
- package/src/payment/postfinance-checkout/api-client.ts +106 -0
- package/src/payment/postfinance-checkout/api-types.ts +111 -0
- package/src/payment/postfinance-checkout/api.ts +58 -85
- package/src/payment/postfinance-checkout/handler-express.ts +5 -7
- package/src/payment/postfinance-checkout/handler-fastify.ts +6 -8
- package/src/payment/postfinance-checkout/index.ts +43 -35
- package/src/payment/postfinance-checkout/types.ts +6 -6
- package/src/payment/postfinance-checkout/utils.ts +7 -12
- package/src/payment/saferpay/adapter.ts +4 -6
- package/src/payment/saferpay/api/models/Transaction.ts +2 -2
- package/src/payment/saferpay/module.ts +2 -2
- package/src/payment/stripe/index.ts +5 -5
- package/src/payment/stripe/stripe.ts +3 -3
- package/src/presets/all.ts +3 -1
- package/src/pricing/delivery-swiss-tax.ts +6 -2
- package/src/pricing/order-delivery.ts +1 -1
- package/src/pricing/order-discount.ts +3 -3
- package/src/pricing/order-items-discount.ts +1 -1
- package/src/pricing/order-items.ts +1 -1
- package/src/pricing/order-payment.ts +1 -1
- package/src/pricing/order-round.ts +9 -9
- package/src/pricing/product-catalog-price.ts +6 -25
- package/src/pricing/product-price-rateconversion.ts +2 -2
- package/src/pricing/product-round.ts +3 -3
- package/src/pricing/product-swiss-tax.test.ts +6 -6
- package/src/pricing/product-swiss-tax.ts +2 -2
- package/src/warehousing/eth-minter.ts +2 -2
- package/src/worker/budgetsms.ts +268 -0
- package/src/worker/bulk-import.ts +1 -1
- package/src/worker/bulkgate.ts +138 -0
- package/src/worker/enrollment-order-generator.ts +3 -3
- package/src/worker/error-notifications.ts +4 -4
- package/src/worker/heartbeat.ts +4 -11
- package/src/worker/message.ts +1 -1
- package/src/worker/push-notification.ts +2 -2
- package/src/worker/twilio.ts +71 -0
- package/src/worker/update-coinbase-rates.ts +3 -6
- package/src/worker/update-ecb-rates.ts +3 -3
- package/lib/accounts/google-oauth.d.ts +0 -4
- package/lib/accounts/google-oauth.d.ts.map +0 -1
- package/lib/accounts/google-oauth.js +0 -145
- package/lib/accounts/google-oauth.js.map +0 -1
- package/lib/accounts/linkedin-oauth.d.ts +0 -4
- package/lib/accounts/linkedin-oauth.d.ts.map +0 -1
- package/lib/accounts/linkedin-oauth.js +0 -82
- package/lib/accounts/linkedin-oauth.js.map +0 -1
- package/lib/files/gridfs/gridfs-adapter.d.ts +0 -3
- package/lib/files/gridfs/gridfs-adapter.d.ts.map +0 -1
- package/lib/files/gridfs/gridfs-adapter.js +0 -97
- package/lib/files/gridfs/gridfs-adapter.js.map +0 -1
- package/lib/files/gridfs/gridfs-webhook.d.ts +0 -11
- package/lib/files/gridfs/gridfs-webhook.d.ts.map +0 -1
- package/lib/files/gridfs/gridfs-webhook.js +0 -84
- package/lib/files/gridfs/gridfs-webhook.js.map +0 -1
- package/lib/files/minio/minio-adapter.d.ts +0 -6
- package/lib/files/minio/minio-adapter.d.ts.map +0 -1
- package/lib/files/minio/minio-adapter.js +0 -181
- package/lib/files/minio/minio-adapter.js.map +0 -1
- package/lib/files/minio/minio-webhook.d.ts +0 -2
- package/lib/files/minio/minio-webhook.d.ts.map +0 -1
- package/lib/files/minio/minio-webhook.js +0 -33
- package/lib/files/minio/minio-webhook.js.map +0 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +0 -9
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +0 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +0 -17
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +0 -1
- package/lib/payment/cryptopay/middleware.d.ts +0 -2
- package/lib/payment/cryptopay/middleware.d.ts.map +0 -1
- package/lib/payment/cryptopay/middleware.js +0 -75
- package/lib/payment/cryptopay/middleware.js.map +0 -1
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +0 -25
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +0 -1
- package/lib/payment/cryptopay/module/configureCryptopayModule.js +0 -75
- package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +0 -1
- package/lib/payment/datatrans-v2/middleware.d.ts +0 -2
- package/lib/payment/datatrans-v2/middleware.d.ts.map +0 -1
- package/lib/payment/datatrans-v2/middleware.js +0 -68
- package/lib/payment/datatrans-v2/middleware.js.map +0 -1
- package/lib/payment/payrexx/middleware.d.ts +0 -2
- package/lib/payment/payrexx/middleware.d.ts.map +0 -1
- package/lib/payment/payrexx/middleware.js +0 -86
- package/lib/payment/payrexx/middleware.js.map +0 -1
- package/lib/payment/postfinance-checkout/middleware.d.ts +0 -2
- package/lib/payment/postfinance-checkout/middleware.d.ts.map +0 -1
- package/lib/payment/postfinance-checkout/middleware.js +0 -38
- package/lib/payment/postfinance-checkout/middleware.js.map +0 -1
- package/lib/payment/saferpay/middleware.d.ts +0 -2
- package/lib/payment/saferpay/middleware.d.ts.map +0 -1
- package/lib/payment/saferpay/middleware.js +0 -57
- package/lib/payment/saferpay/middleware.js.map +0 -1
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +0 -10
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +0 -1
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +0 -24
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +0 -1
- package/lib/payment/stripe/middleware.d.ts +0 -6
- package/lib/payment/stripe/middleware.d.ts.map +0 -1
- package/lib/payment/stripe/middleware.js +0 -114
- package/lib/payment/stripe/middleware.js.map +0 -1
- package/lib/plugins-index.d.ts +0 -48
- package/lib/plugins-index.d.ts.map +0 -1
- package/lib/plugins-index.js +0 -107
- package/lib/plugins-index.js.map +0 -1
- package/lib/worker/BaseWorker.d.ts +0 -30
- package/lib/worker/BaseWorker.d.ts.map +0 -1
- package/lib/worker/BaseWorker.js +0 -79
- package/lib/worker/BaseWorker.js.map +0 -1
- package/lib/worker/EventListenerWorker.d.ts +0 -6
- package/lib/worker/EventListenerWorker.d.ts.map +0 -1
- package/lib/worker/EventListenerWorker.js +0 -46
- package/lib/worker/EventListenerWorker.js.map +0 -1
- package/lib/worker/FailedRescheduler.d.ts +0 -15
- package/lib/worker/FailedRescheduler.d.ts.map +0 -1
- package/lib/worker/FailedRescheduler.js +0 -45
- package/lib/worker/FailedRescheduler.js.map +0 -1
- package/lib/worker/IntervalWorker.d.ts +0 -10
- package/lib/worker/IntervalWorker.d.ts.map +0 -1
- package/lib/worker/IntervalWorker.js +0 -37
- package/lib/worker/IntervalWorker.js.map +0 -1
- package/src/worker/BaseWorker.ts +0 -116
- package/src/worker/EventListenerWorker.ts +0 -61
- package/src/worker/FailedRescheduler.ts +0 -80
- package/src/worker/IntervalWorker.ts +0 -54
- package/src/worker/sms.ts +0 -87
|
@@ -3,7 +3,7 @@ import { createLogger } from '@unchainedshop/logger';
|
|
|
3
3
|
import { WebhookData } from './types.js';
|
|
4
4
|
import { getTransaction, getTransactionCompletion } from './api.js';
|
|
5
5
|
|
|
6
|
-
const logger = createLogger('unchained:core-payment:postfinance-checkout');
|
|
6
|
+
const logger = createLogger('unchained:core-payment:postfinance-checkout:handler');
|
|
7
7
|
|
|
8
8
|
export const postfinanceCheckoutHandler = async (req, res) => {
|
|
9
9
|
const context = req.unchainedContext as Context;
|
|
@@ -13,7 +13,7 @@ export const postfinanceCheckoutHandler = async (req, res) => {
|
|
|
13
13
|
try {
|
|
14
14
|
const transactionCompletion = await getTransactionCompletion(data.entityId as unknown as string);
|
|
15
15
|
const transaction = await getTransaction(
|
|
16
|
-
transactionCompletion
|
|
16
|
+
transactionCompletion ? (transactionCompletion as any).linkedTransaction : data.entityId,
|
|
17
17
|
);
|
|
18
18
|
const { orderPaymentId } = transaction.metaData as { orderPaymentId: string };
|
|
19
19
|
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
@@ -27,19 +27,17 @@ export const postfinanceCheckoutHandler = async (req, res) => {
|
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
29
|
logger.info(
|
|
30
|
-
`
|
|
30
|
+
`Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
|
|
31
31
|
);
|
|
32
32
|
res.writeHead(200);
|
|
33
33
|
res.end(`Order marked as paid: ${order.orderNumber}`);
|
|
34
34
|
} catch (e) {
|
|
35
|
-
logger.error(
|
|
35
|
+
logger.error(e);
|
|
36
36
|
res.writeHead(500);
|
|
37
37
|
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
|
|
38
38
|
}
|
|
39
39
|
} else {
|
|
40
|
-
logger.error(
|
|
41
|
-
`PostFinance Checkout Webhook: Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`,
|
|
42
|
-
);
|
|
40
|
+
logger.error(`Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
|
|
43
41
|
res.writeHead(404);
|
|
44
42
|
res.end();
|
|
45
43
|
}
|
|
@@ -4,7 +4,7 @@ import { WebhookData } from './types.js';
|
|
|
4
4
|
import { getTransaction, getTransactionCompletion } from './api.js';
|
|
5
5
|
import { FastifyRequest, RouteHandlerMethod } from 'fastify';
|
|
6
6
|
|
|
7
|
-
const logger = createLogger('unchained:core-payment:postfinance-checkout');
|
|
7
|
+
const logger = createLogger('unchained:core-payment:postfinance-checkout:handler');
|
|
8
8
|
|
|
9
9
|
export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
|
|
10
10
|
req: FastifyRequest & {
|
|
@@ -19,7 +19,7 @@ export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
|
|
|
19
19
|
try {
|
|
20
20
|
const transactionCompletion = await getTransactionCompletion(data.entityId as unknown as string);
|
|
21
21
|
const transaction = await getTransaction(
|
|
22
|
-
transactionCompletion
|
|
22
|
+
transactionCompletion ? (transactionCompletion as any).linkedTransaction : data.entityId,
|
|
23
23
|
);
|
|
24
24
|
const { orderPaymentId } = transaction.metaData as { orderPaymentId: string };
|
|
25
25
|
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
@@ -29,23 +29,21 @@ export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
|
|
|
29
29
|
|
|
30
30
|
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
31
31
|
paymentContext: {
|
|
32
|
-
transactionId:
|
|
32
|
+
transactionId: transaction.id,
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
35
|
logger.info(
|
|
36
|
-
`
|
|
36
|
+
`Transaction ${transaction.id} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
|
|
37
37
|
);
|
|
38
38
|
reply.status(200);
|
|
39
39
|
return reply.send(`Order marked as paid: ${order.orderNumber}`);
|
|
40
40
|
} catch (e) {
|
|
41
|
-
logger.error(
|
|
41
|
+
logger.error(e);
|
|
42
42
|
reply.status(500);
|
|
43
43
|
return reply.send({ name: e.name, code: e.code, message: e.message });
|
|
44
44
|
}
|
|
45
45
|
} else {
|
|
46
|
-
logger.error(
|
|
47
|
-
`PostFinance Checkout Webhook: Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`,
|
|
48
|
-
);
|
|
46
|
+
logger.error(`Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
|
|
49
47
|
reply.status(404);
|
|
50
48
|
return reply.send();
|
|
51
49
|
}
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
PaymentDirector,
|
|
9
9
|
PaymentError,
|
|
10
10
|
} from '@unchainedshop/core';
|
|
11
|
-
import * as pf from 'postfinancecheckout';
|
|
12
11
|
|
|
13
12
|
import {
|
|
14
13
|
confirmDeferredTransaction,
|
|
@@ -23,8 +22,15 @@ import {
|
|
|
23
22
|
} from './api.js';
|
|
24
23
|
import { orderIsPaid } from './utils.js';
|
|
25
24
|
import { CompletionModes, IntegrationModes, SignResponse } from './types.js';
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
import {
|
|
26
|
+
TransactionCreate,
|
|
27
|
+
LineItem,
|
|
28
|
+
LineItemType,
|
|
29
|
+
TokenizationMode,
|
|
30
|
+
TransactionCompletionBehavior,
|
|
31
|
+
TransactionState,
|
|
32
|
+
CreationEntityState,
|
|
33
|
+
} from './api-types.js';
|
|
28
34
|
|
|
29
35
|
const {
|
|
30
36
|
PFCHECKOUT_SPACE_ID,
|
|
@@ -34,7 +40,7 @@ const {
|
|
|
34
40
|
PFCHECKOUT_FAILED_URL,
|
|
35
41
|
} = process.env;
|
|
36
42
|
|
|
37
|
-
const logger = createLogger('unchained:core-payment:postfinance');
|
|
43
|
+
const logger = createLogger('unchained:core-payment:postfinance-checkout');
|
|
38
44
|
|
|
39
45
|
const newError = ({ code, message }: { code: string; message: string }) => {
|
|
40
46
|
const error = new Error(message);
|
|
@@ -66,9 +72,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
66
72
|
);
|
|
67
73
|
},
|
|
68
74
|
|
|
69
|
-
// eslint-disable-next-line
|
|
70
75
|
configurationError() {
|
|
71
|
-
// eslint-disable-line
|
|
72
76
|
if (
|
|
73
77
|
!PFCHECKOUT_SPACE_ID ||
|
|
74
78
|
!PFCHECKOUT_USER_ID ||
|
|
@@ -94,7 +98,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
94
98
|
if (!credentials.meta) return false;
|
|
95
99
|
const { linkedSpaceId } = credentials.meta;
|
|
96
100
|
const tokenData = await getToken(linkedSpaceId, credentials.token);
|
|
97
|
-
return tokenData.state ===
|
|
101
|
+
return tokenData.state === CreationEntityState.ACTIVE;
|
|
98
102
|
},
|
|
99
103
|
|
|
100
104
|
sign: async (transactionContext: any = {}) => {
|
|
@@ -105,41 +109,42 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
105
109
|
const completionMode = adapter.getCompletionMode();
|
|
106
110
|
const pricing = OrderPricingSheet({
|
|
107
111
|
calculation: order.calculation,
|
|
108
|
-
|
|
112
|
+
currencyCode: order.currencyCode,
|
|
109
113
|
});
|
|
110
114
|
|
|
111
115
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
112
|
-
const transaction =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
const transaction: TransactionCreate = {
|
|
117
|
+
currency: order.currencyCode,
|
|
118
|
+
metaData: {
|
|
119
|
+
orderPaymentId: orderPayment._id,
|
|
120
|
+
},
|
|
121
|
+
successUrl: `${transactionContext?.successUrl || PFCHECKOUT_SUCCESS_URL}?order_id=${
|
|
122
|
+
orderPayment.orderId
|
|
123
|
+
}`,
|
|
124
|
+
failedUrl: `${transactionContext?.failedUrl || PFCHECKOUT_FAILED_URL}?order_id=${
|
|
125
|
+
orderPayment.orderId
|
|
126
|
+
}`,
|
|
127
|
+
customerId: order?.userId || context?.userId,
|
|
128
|
+
tokenizationMode: TokenizationMode.ALLOW_ONE_CLICK_PAYMENT,
|
|
117
129
|
};
|
|
118
|
-
|
|
119
|
-
orderPayment.orderId
|
|
120
|
-
}`;
|
|
121
|
-
transaction.failedUrl = `${transactionContext?.failedUrl || PFCHECKOUT_FAILED_URL}?order_id=${
|
|
122
|
-
orderPayment.orderId
|
|
123
|
-
}`;
|
|
124
|
-
transaction.customerId = userId;
|
|
125
|
-
transaction.tokenizationMode =
|
|
126
|
-
PostFinanceCheckout.model.TokenizationMode.ALLOW_ONE_CLICK_PAYMENT;
|
|
130
|
+
|
|
127
131
|
if (completionMode === CompletionModes.Immediate) {
|
|
128
|
-
transaction.completionBehavior =
|
|
129
|
-
PostFinanceCheckout.model.TransactionCompletionBehavior.COMPLETE_IMMEDIATELY;
|
|
132
|
+
transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_IMMEDIATELY;
|
|
130
133
|
} else if (completionMode === CompletionModes.Deferred) {
|
|
131
|
-
transaction.completionBehavior =
|
|
132
|
-
PostFinanceCheckout.model.TransactionCompletionBehavior.COMPLETE_DEFERRED;
|
|
134
|
+
transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_DEFERRED;
|
|
133
135
|
}
|
|
136
|
+
|
|
134
137
|
if (totalAmount) {
|
|
135
|
-
const lineItemSum =
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
const lineItemSum: LineItem = {
|
|
139
|
+
name: `Bestellung ${orderPayment.orderId}`,
|
|
140
|
+
type: LineItemType.FEE,
|
|
141
|
+
quantity: 1,
|
|
142
|
+
uniqueId: orderPayment.orderId,
|
|
143
|
+
amountIncludingTax: totalAmount / 100,
|
|
144
|
+
};
|
|
141
145
|
transaction.lineItems = [lineItemSum];
|
|
142
146
|
}
|
|
147
|
+
|
|
143
148
|
const transactionId = await createTransaction(transaction);
|
|
144
149
|
let location = null;
|
|
145
150
|
if (integrationMode === IntegrationModes.PaymentPage) {
|
|
@@ -216,10 +221,10 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
216
221
|
return false;
|
|
217
222
|
}
|
|
218
223
|
const transaction = await getTransaction(transactionId);
|
|
219
|
-
const refund = transaction.state ===
|
|
224
|
+
const refund = transaction.state === TransactionState.FULFILL;
|
|
220
225
|
const pricing = OrderPricingSheet({
|
|
221
226
|
calculation: order.calculation,
|
|
222
|
-
|
|
227
|
+
currencyCode: order.currencyCode,
|
|
223
228
|
});
|
|
224
229
|
|
|
225
230
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
@@ -237,7 +242,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
237
242
|
return false;
|
|
238
243
|
}
|
|
239
244
|
const transaction = await getTransaction(transactionId);
|
|
240
|
-
if (transaction.state ===
|
|
245
|
+
if (transaction.state === TransactionState.AUTHORIZED) {
|
|
241
246
|
return confirmDeferredTransaction(transactionId);
|
|
242
247
|
}
|
|
243
248
|
return false;
|
|
@@ -249,3 +254,6 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
249
254
|
};
|
|
250
255
|
|
|
251
256
|
PaymentDirector.registerAdapter(PostfinanceCheckout);
|
|
257
|
+
|
|
258
|
+
export * from './types.js';
|
|
259
|
+
export * from './api-types.js';
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
export enum IntegrationModes {
|
|
1
|
+
export enum IntegrationModes {
|
|
2
2
|
PaymentPage = 'PaymentPage',
|
|
3
3
|
Lightbox = 'Lightbox',
|
|
4
4
|
iFrame = 'iFrame',
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export enum CompletionModes {
|
|
7
|
+
export enum CompletionModes {
|
|
8
8
|
Immediate = 'Immediate',
|
|
9
9
|
Deferred = 'Deferred',
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export
|
|
12
|
+
export interface SignResponse {
|
|
13
13
|
transactionId: number;
|
|
14
14
|
location: string | null;
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
|
|
17
17
|
export type listenerEntityTechnicalNames = 'TransactionCompletion';
|
|
18
18
|
|
|
19
|
-
export
|
|
19
|
+
export interface WebhookData {
|
|
20
20
|
eventId: number;
|
|
21
21
|
entityId: number;
|
|
22
22
|
listenerEntityId: number;
|
|
@@ -24,4 +24,4 @@ export type WebhookData = {
|
|
|
24
24
|
spaceId: number;
|
|
25
25
|
webhookListenerId: number;
|
|
26
26
|
timestamp: string; // "YYYY-MM-DDTHH:MM:ss+0000", e.g. "2022-02-18T12:40:42+0000"
|
|
27
|
-
}
|
|
27
|
+
}
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { OrderPricingSheet } from '@unchainedshop/core';
|
|
2
2
|
import { Order } from '@unchainedshop/core-orders';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const { PostFinanceCheckout } = pf;
|
|
3
|
+
import { Transaction, TransactionState } from './api-types.js';
|
|
6
4
|
|
|
7
5
|
export const transactionIsPaid = async (
|
|
8
|
-
transaction:
|
|
6
|
+
transaction: Transaction,
|
|
9
7
|
expectedCurrency: string,
|
|
10
8
|
expectedAmount: number,
|
|
11
9
|
): Promise<boolean> => {
|
|
12
|
-
if (transaction.state ===
|
|
10
|
+
if (transaction.state === TransactionState.FULFILL) {
|
|
13
11
|
return (
|
|
14
12
|
transaction.completedAmount !== undefined &&
|
|
15
13
|
transaction.completedAmount.toFixed(2) === expectedAmount.toFixed(2) &&
|
|
16
14
|
transaction.currency === expectedCurrency
|
|
17
15
|
);
|
|
18
16
|
}
|
|
19
|
-
if (transaction.state ===
|
|
17
|
+
if (transaction.state === TransactionState.AUTHORIZED) {
|
|
20
18
|
return (
|
|
21
19
|
transaction.authorizationAmount !== undefined &&
|
|
22
20
|
transaction.authorizationAmount.toFixed(2) === expectedAmount.toFixed(2) &&
|
|
@@ -26,14 +24,11 @@ export const transactionIsPaid = async (
|
|
|
26
24
|
return false;
|
|
27
25
|
};
|
|
28
26
|
|
|
29
|
-
export const orderIsPaid = async (
|
|
30
|
-
order: Order,
|
|
31
|
-
transaction: pf.PostFinanceCheckout.model.Transaction,
|
|
32
|
-
): Promise<boolean> => {
|
|
27
|
+
export const orderIsPaid = async (order: Order, transaction: Transaction): Promise<boolean> => {
|
|
33
28
|
const pricing = OrderPricingSheet({
|
|
34
29
|
calculation: order.calculation,
|
|
35
|
-
|
|
30
|
+
currencyCode: order.currencyCode,
|
|
36
31
|
});
|
|
37
32
|
const totalAmount = pricing.total({ useNetPrice: false }).amount / 100;
|
|
38
|
-
return transactionIsPaid(transaction, order.
|
|
33
|
+
return transactionIsPaid(transaction, order.currencyCode, totalAmount);
|
|
39
34
|
};
|
|
@@ -68,9 +68,7 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
68
68
|
return config.find((item) => item.key === 'terminalId')?.value;
|
|
69
69
|
},
|
|
70
70
|
|
|
71
|
-
// eslint-disable-next-line
|
|
72
71
|
configurationError() {
|
|
73
|
-
// eslint-disable-line
|
|
74
72
|
if (
|
|
75
73
|
!SAFERPAY_BASE_URL ||
|
|
76
74
|
!SAFERPAY_CUSTOMER_ID ||
|
|
@@ -100,7 +98,7 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
100
98
|
}
|
|
101
99
|
const pricing = OrderPricingSheet({
|
|
102
100
|
calculation: order.calculation,
|
|
103
|
-
|
|
101
|
+
currencyCode: order.currencyCode,
|
|
104
102
|
});
|
|
105
103
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
106
104
|
|
|
@@ -115,7 +113,7 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
115
113
|
Payment: {
|
|
116
114
|
Amount: {
|
|
117
115
|
Value: totalAmount.toString(),
|
|
118
|
-
CurrencyCode: order.
|
|
116
|
+
CurrencyCode: order.currencyCode,
|
|
119
117
|
},
|
|
120
118
|
OrderId: order._id,
|
|
121
119
|
Description: transactionContext.description || 'Bestellung',
|
|
@@ -160,7 +158,7 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
160
158
|
}
|
|
161
159
|
const pricing = OrderPricingSheet({
|
|
162
160
|
calculation: order.calculation,
|
|
163
|
-
|
|
161
|
+
currencyCode: order.currencyCode,
|
|
164
162
|
});
|
|
165
163
|
const totalAmount = pricing.total({ useNetPrice: false }).amount;
|
|
166
164
|
|
|
@@ -176,7 +174,7 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
176
174
|
const success =
|
|
177
175
|
!paymentPageAssert.ErrorMessage &&
|
|
178
176
|
paymentPageAssert.Transaction.Amount.Value === totalAmount.toString() &&
|
|
179
|
-
paymentPageAssert.Transaction.Amount.CurrencyCode === order.
|
|
177
|
+
paymentPageAssert.Transaction.Amount.CurrencyCode === order.currencyCode &&
|
|
180
178
|
(paymentPageAssert.Transaction.Status === 'AUTHORIZED' ||
|
|
181
179
|
paymentPageAssert.Transaction.Status === 'CAPTURED');
|
|
182
180
|
if (success) {
|
|
@@ -90,7 +90,7 @@ const Stripe: IPaymentAdapter = {
|
|
|
90
90
|
if (orderPayment) {
|
|
91
91
|
const pricing = OrderPricingSheet({
|
|
92
92
|
calculation: order.calculation,
|
|
93
|
-
|
|
93
|
+
currencyCode: order.currencyCode,
|
|
94
94
|
});
|
|
95
95
|
const { userId, name, email } = await getUserData(order?.userId);
|
|
96
96
|
const paymentIntent = await createOrderPaymentIntent(
|
|
@@ -121,7 +121,7 @@ const Stripe: IPaymentAdapter = {
|
|
|
121
121
|
const { userId, name, email } = await getUserData(order?.userId);
|
|
122
122
|
const pricing = OrderPricingSheet({
|
|
123
123
|
calculation: order.calculation,
|
|
124
|
-
|
|
124
|
+
currencyCode: order.currencyCode,
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
const paymentIntentObject = paymentIntentId
|
|
@@ -132,15 +132,15 @@ const Stripe: IPaymentAdapter = {
|
|
|
132
132
|
customer: paymentCredentials.meta?.customer,
|
|
133
133
|
confirm: true,
|
|
134
134
|
payment_method: paymentCredentials.token,
|
|
135
|
-
payment_method_types: paymentCredentials.meta?.payment_method_types,
|
|
135
|
+
payment_method_types: paymentCredentials.meta?.payment_method_types,
|
|
136
136
|
// payment_method_options: paymentCredentials.meta?.payment_method_options, // eslint-disable-line
|
|
137
137
|
},
|
|
138
138
|
);
|
|
139
139
|
|
|
140
|
-
const {
|
|
140
|
+
const { currencyCode, amount } = pricing.total({ useNetPrice: false });
|
|
141
141
|
|
|
142
142
|
if (
|
|
143
|
-
paymentIntentObject.currency !==
|
|
143
|
+
paymentIntentObject.currency !== currencyCode.toLowerCase() ||
|
|
144
144
|
paymentIntentObject.amount !== Math.round(amount)
|
|
145
145
|
) {
|
|
146
146
|
throw new Error('The price has changed since the intent has been created');
|
|
@@ -18,7 +18,7 @@ export const initStripeClient = async (): Promise<StripeType> => {
|
|
|
18
18
|
// @ts-ignore
|
|
19
19
|
const { default: Stripe } = await import('stripe');
|
|
20
20
|
stripe = new Stripe(STRIPE_SECRET, {
|
|
21
|
-
apiVersion: '2025-
|
|
21
|
+
apiVersion: '2025-06-30.basil',
|
|
22
22
|
});
|
|
23
23
|
return stripe;
|
|
24
24
|
};
|
|
@@ -122,11 +122,11 @@ export const createOrderPaymentIntent = async (
|
|
|
122
122
|
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'}`.trim();
|
|
123
123
|
const customer = options?.customer || (await upsertCustomer({ userId, name, email }));
|
|
124
124
|
|
|
125
|
-
const {
|
|
125
|
+
const { currencyCode, amount } = pricing.total({ useNetPrice: false });
|
|
126
126
|
|
|
127
127
|
const paymentIntent = await stripe.paymentIntents.create({
|
|
128
128
|
amount: Math.round(amount),
|
|
129
|
-
currency:
|
|
129
|
+
currency: currencyCode.toLowerCase(),
|
|
130
130
|
description,
|
|
131
131
|
statement_descriptor_suffix: `${order._id.substring(0, 4)}..${order._id.substring(order._id.length - 4)}`,
|
|
132
132
|
setup_future_usage: 'off_session', // Verify your integration in this guide by including this parameter
|
package/src/presets/all.ts
CHANGED
|
@@ -21,7 +21,9 @@ import '../filters/strict-equal.js';
|
|
|
21
21
|
import '../filters/local-search.js';
|
|
22
22
|
|
|
23
23
|
// Workers
|
|
24
|
-
import '../worker/
|
|
24
|
+
import '../worker/twilio.js';
|
|
25
|
+
import '../worker/bulkgate.js';
|
|
26
|
+
import '../worker/budgetsms.js';
|
|
25
27
|
import '../worker/push-notification.js';
|
|
26
28
|
import '../worker/enrollment-order-generator.js';
|
|
27
29
|
|
|
@@ -19,8 +19,12 @@ const getTaxRate = ({ order, provider }: { order?: Order; provider?: DeliveryPro
|
|
|
19
19
|
return taxCategory.rate(order?.ordered);
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const isDeliveryAddressInSwitzerland = ({
|
|
23
|
-
|
|
22
|
+
const isDeliveryAddressInSwitzerland = ({
|
|
23
|
+
orderDelivery,
|
|
24
|
+
order,
|
|
25
|
+
countryCode: forceCountryCode = null,
|
|
26
|
+
}) => {
|
|
27
|
+
let countryCode = forceCountryCode?.toUpperCase().trim() || order.countryCode;
|
|
24
28
|
|
|
25
29
|
const address = orderDelivery?.context?.address || order?.billingAddress;
|
|
26
30
|
|
|
@@ -29,7 +29,7 @@ export const OrderDelivery: IOrderPricingAdapter = {
|
|
|
29
29
|
if (!orderDelivery) return null;
|
|
30
30
|
const pricing = DeliveryPricingSheet({
|
|
31
31
|
calculation: orderDelivery.calculation,
|
|
32
|
-
|
|
32
|
+
currencyCode: order.currencyCode,
|
|
33
33
|
});
|
|
34
34
|
const tax = pricing.taxSum();
|
|
35
35
|
const shipping = pricing.gross();
|
|
@@ -48,7 +48,7 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
48
48
|
resolveRatioAndTaxDivisorForPricingSheet(
|
|
49
49
|
ProductPricingSheet({
|
|
50
50
|
calculation: orderPosition.calculation,
|
|
51
|
-
|
|
51
|
+
currencyCode: order.currencyCode,
|
|
52
52
|
quantity: orderPosition.quantity,
|
|
53
53
|
}),
|
|
54
54
|
totalAmountOfItems,
|
|
@@ -58,7 +58,7 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
58
58
|
const deliveryShare = resolveRatioAndTaxDivisorForPricingSheet(
|
|
59
59
|
DeliveryPricingSheet({
|
|
60
60
|
calculation: orderDelivery.calculation || [],
|
|
61
|
-
|
|
61
|
+
currencyCode: order.currencyCode,
|
|
62
62
|
}),
|
|
63
63
|
totalAmountOfPaymentAndDelivery,
|
|
64
64
|
);
|
|
@@ -66,7 +66,7 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
66
66
|
const paymentShare = resolveRatioAndTaxDivisorForPricingSheet(
|
|
67
67
|
PaymentPricingSheet({
|
|
68
68
|
calculation: orderPayment.calculation || [],
|
|
69
|
-
|
|
69
|
+
currencyCode: order.currencyCode,
|
|
70
70
|
}),
|
|
71
71
|
totalAmountOfPaymentAndDelivery,
|
|
72
72
|
);
|
|
@@ -42,7 +42,7 @@ const OrderItemsDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
42
42
|
resolveRatioAndTaxDivisorForPricingSheet(
|
|
43
43
|
ProductPricingSheet({
|
|
44
44
|
calculation: orderPosition.calculation,
|
|
45
|
-
|
|
45
|
+
currencyCode: order.currencyCode,
|
|
46
46
|
quantity: orderPosition.quantity,
|
|
47
47
|
}),
|
|
48
48
|
totalAmountOfItems,
|
|
@@ -30,7 +30,7 @@ const OrderItems: IOrderPricingAdapter = {
|
|
|
30
30
|
(current, orderPosition) => {
|
|
31
31
|
const pricing = ProductPricingSheet({
|
|
32
32
|
calculation: orderPosition.calculation,
|
|
33
|
-
|
|
33
|
+
currencyCode: order.currencyCode,
|
|
34
34
|
quantity: orderPosition.quantity,
|
|
35
35
|
});
|
|
36
36
|
const tax = pricing.taxSum();
|
|
@@ -30,7 +30,7 @@ const OrderPayment: IOrderPricingAdapter = {
|
|
|
30
30
|
|
|
31
31
|
const pricing = PaymentPricingSheet({
|
|
32
32
|
calculation: orderPayment.calculation,
|
|
33
|
-
|
|
33
|
+
currencyCode: order.currencyCode,
|
|
34
34
|
});
|
|
35
35
|
const tax = pricing.taxSum();
|
|
36
36
|
const paymentFees = pricing.gross();
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
interface PriceRoundSettings {
|
|
9
9
|
defaultPrecision: number;
|
|
10
|
-
roundTo: (value: number, precision: number,
|
|
10
|
+
roundTo: (value: number, precision: number, currencyCode: string) => number;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export const OrderPriceRound: IOrderPricingAdapter & {
|
|
@@ -39,11 +39,11 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
39
39
|
actions: (params) => {
|
|
40
40
|
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
41
41
|
|
|
42
|
-
const calculateDifference = (amount: number,
|
|
42
|
+
const calculateDifference = (amount: number, currencyCode: string) => {
|
|
43
43
|
const roundedAmount = OrderPriceRound.settings.roundTo(
|
|
44
44
|
amount,
|
|
45
45
|
OrderPriceRound.settings.defaultPrecision,
|
|
46
|
-
|
|
46
|
+
currencyCode,
|
|
47
47
|
);
|
|
48
48
|
return roundedAmount - amount;
|
|
49
49
|
};
|
|
@@ -52,7 +52,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
52
52
|
...pricingAdapter,
|
|
53
53
|
|
|
54
54
|
calculate: async () => {
|
|
55
|
-
const {
|
|
55
|
+
const { currencyCode } = params.context;
|
|
56
56
|
|
|
57
57
|
const { amount: deliveryAmount } = params.calculationSheet.total({
|
|
58
58
|
category: OrderPricingRowCategory.Delivery,
|
|
@@ -60,7 +60,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
60
60
|
});
|
|
61
61
|
if (deliveryAmount) {
|
|
62
62
|
pricingAdapter.resultSheet().addDelivery({
|
|
63
|
-
amount: calculateDifference(deliveryAmount,
|
|
63
|
+
amount: calculateDifference(deliveryAmount, currencyCode),
|
|
64
64
|
taxAmount: 0,
|
|
65
65
|
meta: {
|
|
66
66
|
adapter: OrderPriceRound.key,
|
|
@@ -74,7 +74,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
74
74
|
});
|
|
75
75
|
if (discountAmount) {
|
|
76
76
|
pricingAdapter.resultSheet().addDiscount({
|
|
77
|
-
amount: calculateDifference(discountAmount,
|
|
77
|
+
amount: calculateDifference(discountAmount, currencyCode),
|
|
78
78
|
taxAmount: 0,
|
|
79
79
|
meta: {
|
|
80
80
|
adapter: OrderPriceRound.key,
|
|
@@ -89,7 +89,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
89
89
|
});
|
|
90
90
|
if (itemsAmount) {
|
|
91
91
|
pricingAdapter.resultSheet().addItems({
|
|
92
|
-
amount: calculateDifference(itemsAmount,
|
|
92
|
+
amount: calculateDifference(itemsAmount, currencyCode),
|
|
93
93
|
taxAmount: 0,
|
|
94
94
|
meta: {
|
|
95
95
|
adapter: OrderPriceRound.key,
|
|
@@ -103,7 +103,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
103
103
|
});
|
|
104
104
|
if (paymentAmount) {
|
|
105
105
|
pricingAdapter.resultSheet().addPayment({
|
|
106
|
-
amount: calculateDifference(paymentAmount,
|
|
106
|
+
amount: calculateDifference(paymentAmount, currencyCode),
|
|
107
107
|
taxAmount: 0,
|
|
108
108
|
meta: {
|
|
109
109
|
adapter: OrderPriceRound.key,
|
|
@@ -115,7 +115,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
115
115
|
category: OrderPricingRowCategory.Taxes,
|
|
116
116
|
});
|
|
117
117
|
if (taxesAmount) {
|
|
118
|
-
const taxDifference = calculateDifference(taxesAmount,
|
|
118
|
+
const taxDifference = calculateDifference(taxesAmount, currencyCode);
|
|
119
119
|
pricingAdapter.resultSheet().calculation.push({
|
|
120
120
|
category: OrderPricingRowCategory.Taxes,
|
|
121
121
|
amount: taxDifference,
|
|
@@ -3,28 +3,6 @@ import {
|
|
|
3
3
|
ProductPricingAdapter,
|
|
4
4
|
IProductPricingAdapter,
|
|
5
5
|
} from '@unchainedshop/core';
|
|
6
|
-
import { resolveBestCurrency } from '@unchainedshop/utils';
|
|
7
|
-
import pMemoize from 'p-memoize';
|
|
8
|
-
import ExpiryMap from 'expiry-map';
|
|
9
|
-
|
|
10
|
-
const { NODE_ENV } = process.env;
|
|
11
|
-
|
|
12
|
-
const memoizeCache = new ExpiryMap(NODE_ENV === 'production' ? 1000 * 60 : 100); // Cached values expire after 10 seconds
|
|
13
|
-
|
|
14
|
-
export const resolveCurrency = pMemoize(
|
|
15
|
-
async (context) => {
|
|
16
|
-
const { country, currency: forcedCurrency, modules } = context;
|
|
17
|
-
const countryObject = await modules.countries.findCountry({ isoCode: country });
|
|
18
|
-
const currencies = await modules.currencies.findCurrencies({ includeInactive: false });
|
|
19
|
-
const currency =
|
|
20
|
-
forcedCurrency || resolveBestCurrency(countryObject.defaultCurrencyCode, currencies);
|
|
21
|
-
return currency;
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
cache: memoizeCache,
|
|
25
|
-
cacheKey: ([{ currency, country }]) => `${currency}-${country}`,
|
|
26
|
-
},
|
|
27
|
-
);
|
|
28
6
|
|
|
29
7
|
export const ProductPrice: IProductPricingAdapter = {
|
|
30
8
|
...ProductPricingAdapter,
|
|
@@ -45,9 +23,12 @@ export const ProductPrice: IProductPricingAdapter = {
|
|
|
45
23
|
...pricingAdapter,
|
|
46
24
|
|
|
47
25
|
calculate: async () => {
|
|
48
|
-
const { product,
|
|
49
|
-
const
|
|
50
|
-
|
|
26
|
+
const { product, countryCode, currencyCode, quantity, modules } = params.context;
|
|
27
|
+
const price = await modules.products.prices.price(product, {
|
|
28
|
+
countryCode,
|
|
29
|
+
currencyCode,
|
|
30
|
+
quantity,
|
|
31
|
+
});
|
|
51
32
|
if (price) {
|
|
52
33
|
const itemTotal = price.amount * quantity;
|
|
53
34
|
pricingAdapter.resultSheet().addItem({
|