@unchainedshop/plugins 4.6.1 → 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.
- package/README.md +0 -2
- package/lib/delivery/post/adapter.d.ts +2 -0
- package/lib/delivery/{post.js → post/adapter.js} +2 -3
- package/lib/delivery/post/index.d.ts +4 -0
- package/lib/delivery/post/index.js +10 -0
- package/lib/delivery/send-message/adapter.d.ts +2 -0
- package/lib/delivery/{send-message.js → send-message/adapter.js} +2 -3
- package/lib/delivery/send-message/index.d.ts +4 -0
- package/lib/delivery/send-message/index.js +10 -0
- package/lib/delivery/stores/adapter.d.ts +2 -0
- package/lib/delivery/{stores.js → stores/adapter.js} +2 -3
- package/lib/delivery/stores/index.d.ts +4 -0
- package/lib/delivery/stores/index.js +10 -0
- package/lib/enrollments/licensed/adapter.d.ts +6 -0
- package/lib/enrollments/{licensed.js → licensed/adapter.js} +2 -3
- package/lib/enrollments/licensed/index.d.ts +4 -0
- package/lib/enrollments/licensed/index.js +10 -0
- package/lib/events/node-event-emitter.d.ts +3 -1
- package/lib/events/node-event-emitter.js +3 -3
- package/lib/files/gridfs/adapter.d.ts +2 -2
- package/lib/files/gridfs/adapter.js +2 -5
- package/lib/files/gridfs/api.d.ts +7 -0
- package/lib/files/gridfs/api.js +163 -0
- package/lib/files/gridfs/index.d.ts +5 -4
- package/lib/files/gridfs/index.js +30 -3
- package/lib/files/minio/adapter.d.ts +4 -0
- package/lib/files/minio/adapter.js +160 -0
- package/lib/files/minio/api.d.ts +2 -0
- package/lib/files/minio/api.js +41 -0
- package/lib/files/minio/index.d.ts +4 -5
- package/lib/files/minio/index.js +18 -157
- package/lib/files/temp-upload/api.d.ts +6 -0
- package/lib/files/temp-upload/api.js +49 -0
- package/lib/files/temp-upload/index.d.ts +3 -0
- package/lib/files/temp-upload/index.js +15 -0
- package/lib/filters/local-search/adapter.d.ts +2 -0
- package/lib/filters/{local-search.js → local-search/adapter.js} +2 -12
- package/lib/filters/local-search/index.d.ts +4 -0
- package/lib/filters/local-search/index.js +16 -0
- package/lib/filters/strict-equal/adapter.d.ts +2 -0
- package/lib/filters/{strict-equal.js → strict-equal/adapter.js} +2 -3
- package/lib/filters/strict-equal/index.d.ts +4 -0
- package/lib/filters/strict-equal/index.js +10 -0
- package/lib/payment/apple-iap/adapter.d.ts +2 -1
- package/lib/payment/apple-iap/adapter.js +2 -3
- package/lib/payment/apple-iap/api.d.ts +2 -0
- package/lib/payment/apple-iap/{handler-fastify.js → api.js} +47 -30
- package/lib/payment/apple-iap/index.d.ts +6 -4
- package/lib/payment/apple-iap/index.js +28 -3
- package/lib/payment/cryptopay/adapter.d.ts +2 -0
- package/lib/payment/cryptopay/{plugin.js → adapter.js} +2 -4
- package/lib/payment/cryptopay/api.d.ts +2 -0
- package/lib/payment/cryptopay/api.js +23 -0
- package/lib/payment/cryptopay/index.d.ts +5 -4
- package/lib/payment/cryptopay/index.js +31 -3
- package/lib/payment/datatrans-v2/adapter.d.ts +2 -0
- package/lib/payment/datatrans-v2/adapter.js +406 -0
- package/lib/payment/datatrans-v2/api.d.ts +2 -0
- package/lib/payment/datatrans-v2/api.js +108 -0
- package/lib/payment/datatrans-v2/index.d.ts +4 -1
- package/lib/payment/datatrans-v2/index.js +17 -400
- package/lib/payment/invoice/adapter.d.ts +2 -0
- package/lib/payment/{invoice.js → invoice/adapter.js} +2 -3
- package/lib/payment/invoice/index.d.ts +4 -0
- package/lib/payment/invoice/index.js +10 -0
- package/lib/payment/invoice-prepaid/adapter.d.ts +2 -0
- package/lib/payment/{invoice-prepaid.js → invoice-prepaid/adapter.js} +2 -3
- package/lib/payment/invoice-prepaid/index.d.ts +4 -0
- package/lib/payment/invoice-prepaid/index.js +10 -0
- package/lib/payment/payrexx/adapter.d.ts +2 -0
- package/lib/payment/payrexx/adapter.js +161 -0
- package/lib/payment/payrexx/api.d.ts +2 -0
- package/lib/payment/payrexx/api.js +97 -0
- package/lib/payment/payrexx/index.d.ts +4 -1
- package/lib/payment/payrexx/index.js +19 -158
- package/lib/payment/postfinance-checkout/adapter.d.ts +2 -0
- package/lib/payment/postfinance-checkout/adapter.js +189 -0
- package/lib/payment/postfinance-checkout/index.d.ts +5 -0
- package/lib/payment/postfinance-checkout/index.js +25 -186
- package/lib/payment/postfinance-checkout/webhook.d.ts +2 -0
- package/lib/payment/postfinance-checkout/webhook.js +48 -0
- package/lib/payment/saferpay/adapter.js +1 -2
- package/lib/payment/saferpay/index.d.ts +5 -4
- package/lib/payment/saferpay/index.js +29 -3
- package/lib/payment/saferpay/webhook.d.ts +2 -0
- package/lib/payment/saferpay/webhook.js +64 -0
- package/lib/payment/stripe/adapter.d.ts +2 -0
- package/lib/payment/stripe/adapter.js +121 -0
- package/lib/payment/stripe/api.d.ts +6 -0
- package/lib/payment/stripe/api.js +165 -0
- package/lib/payment/stripe/index.d.ts +4 -1
- package/lib/payment/stripe/index.js +22 -116
- package/lib/payment/stripe/stripe.js +2 -5
- package/lib/presets/all.d.ts +1 -70
- package/lib/presets/all.js +41 -27
- package/lib/presets/base.d.ts +1 -25
- package/lib/presets/base.js +56 -25
- package/lib/presets/countries/ch.d.ts +1 -2
- package/lib/presets/countries/ch.js +7 -2
- package/lib/presets/crypto.d.ts +3 -7
- package/lib/presets/crypto.js +18 -7
- package/lib/pricing/{delivery-swiss-tax.d.ts → delivery-swiss-tax/adapter.d.ts} +1 -0
- package/lib/pricing/{delivery-swiss-tax.js → delivery-swiss-tax/adapter.js} +4 -4
- package/lib/pricing/delivery-swiss-tax/index.d.ts +4 -0
- package/lib/pricing/delivery-swiss-tax/index.js +10 -0
- package/lib/pricing/{discount-100-off.d.ts → discount-100-off/adapter.d.ts} +1 -0
- package/lib/pricing/{discount-100-off.js → discount-100-off/adapter.js} +2 -2
- package/lib/pricing/discount-100-off/index.d.ts +4 -0
- package/lib/pricing/discount-100-off/index.js +10 -0
- package/lib/pricing/{discount-half-price-manual.d.ts → discount-half-price-manual/adapter.d.ts} +1 -0
- package/lib/pricing/{discount-half-price-manual.js → discount-half-price-manual/adapter.js} +2 -2
- package/lib/pricing/discount-half-price-manual/index.d.ts +4 -0
- package/lib/pricing/discount-half-price-manual/index.js +10 -0
- package/lib/pricing/{free-delivery.d.ts → free-delivery/adapter.d.ts} +1 -0
- package/lib/pricing/{free-delivery.js → free-delivery/adapter.js} +2 -2
- package/lib/pricing/free-delivery/index.d.ts +4 -0
- package/lib/pricing/free-delivery/index.js +10 -0
- package/lib/pricing/{free-payment.d.ts → free-payment/adapter.d.ts} +1 -0
- package/lib/pricing/{free-payment.js → free-payment/adapter.js} +2 -2
- package/lib/pricing/free-payment/index.d.ts +4 -0
- package/lib/pricing/free-payment/index.js +10 -0
- package/lib/pricing/{order-delivery.d.ts → order-delivery/adapter.d.ts} +1 -0
- package/lib/pricing/{order-delivery.js → order-delivery/adapter.js} +2 -2
- package/lib/pricing/order-delivery/index.d.ts +4 -0
- package/lib/pricing/order-delivery/index.js +10 -0
- package/lib/pricing/{order-discount.d.ts → order-discount/adapter.d.ts} +1 -0
- package/lib/pricing/{order-discount.js → order-discount/adapter.js} +2 -2
- package/lib/pricing/order-discount/index.d.ts +4 -0
- package/lib/pricing/order-discount/index.js +10 -0
- package/lib/pricing/{order-items.d.ts → order-items/adapter.d.ts} +1 -0
- package/lib/pricing/{order-items.js → order-items/adapter.js} +2 -2
- package/lib/pricing/order-items/index.d.ts +4 -0
- package/lib/pricing/order-items/index.js +10 -0
- package/lib/pricing/{order-payment.d.ts → order-payment/adapter.d.ts} +1 -0
- package/lib/pricing/{order-payment.js → order-payment/adapter.js} +2 -2
- package/lib/pricing/order-payment/index.d.ts +4 -0
- package/lib/pricing/order-payment/index.js +10 -0
- package/lib/pricing/{product-catalog-price.d.ts → product-catalog-price/adapter.d.ts} +1 -0
- package/lib/pricing/{product-catalog-price.js → product-catalog-price/adapter.js} +2 -2
- package/lib/pricing/product-catalog-price/index.d.ts +4 -0
- package/lib/pricing/product-catalog-price/index.js +10 -0
- package/lib/pricing/{product-discount.d.ts → product-discount/adapter.d.ts} +1 -0
- package/lib/pricing/{product-discount.js → product-discount/adapter.js} +2 -2
- package/lib/pricing/product-discount/index.d.ts +4 -0
- package/lib/pricing/product-discount/index.js +10 -0
- package/lib/pricing/{product-price-rateconversion.d.ts → product-price-rateconversion/adapter.d.ts} +1 -0
- package/lib/pricing/{product-price-rateconversion.js → product-price-rateconversion/adapter.js} +2 -2
- package/lib/pricing/product-price-rateconversion/index.d.ts +4 -0
- package/lib/pricing/product-price-rateconversion/index.js +10 -0
- package/lib/pricing/{product-swiss-tax.d.ts → product-swiss-tax/adapter.d.ts} +1 -0
- package/lib/pricing/{product-swiss-tax.js → product-swiss-tax/adapter.js} +4 -4
- package/lib/pricing/product-swiss-tax/index.d.ts +4 -0
- package/lib/pricing/product-swiss-tax/index.js +10 -0
- package/lib/quotations/manual/adapter.d.ts +2 -0
- package/lib/quotations/{manual.js → manual/adapter.js} +2 -3
- package/lib/quotations/manual/index.d.ts +4 -0
- package/lib/quotations/manual/index.js +10 -0
- package/lib/warehousing/erc-metadata/api.d.ts +12 -0
- package/lib/warehousing/erc-metadata/api.js +43 -0
- package/lib/warehousing/erc-metadata/index.d.ts +3 -0
- package/lib/warehousing/erc-metadata/index.js +15 -0
- package/lib/warehousing/eth-minter/adapter.d.ts +2 -0
- package/lib/warehousing/{eth-minter.js → eth-minter/adapter.js} +3 -4
- package/lib/warehousing/eth-minter/index.d.ts +4 -0
- package/lib/warehousing/eth-minter/index.js +10 -0
- package/lib/warehousing/store/adapter.d.ts +2 -0
- package/lib/warehousing/{store.js → store/adapter.js} +2 -3
- package/lib/warehousing/store/index.d.ts +4 -0
- package/lib/warehousing/store/index.js +10 -0
- package/lib/worker/budgetsms/adapter.d.ts +22 -0
- package/lib/worker/{budgetsms.js → budgetsms/adapter.js} +3 -3
- package/lib/worker/budgetsms/index.d.ts +4 -0
- package/lib/worker/budgetsms/index.js +10 -0
- package/lib/worker/bulk-export/adapter.d.ts +3 -0
- package/lib/worker/{bulk-export.js → bulk-export/adapter.js} +3 -3
- package/lib/worker/bulk-export/index.d.ts +4 -0
- package/lib/worker/bulk-export/index.js +10 -0
- package/lib/worker/{bulk-import.d.ts → bulk-import/adapter.d.ts} +1 -0
- package/lib/worker/{bulk-import.js → bulk-import/adapter.js} +2 -2
- package/lib/worker/bulk-import/api.d.ts +7 -0
- package/lib/worker/bulk-import/api.js +53 -0
- package/lib/worker/bulk-import/index.d.ts +4 -0
- package/lib/worker/bulk-import/index.js +18 -0
- package/lib/worker/bulkgate/adapter.d.ts +12 -0
- package/lib/worker/{bulkgate.js → bulkgate/adapter.js} +3 -3
- package/lib/worker/bulkgate/index.d.ts +4 -0
- package/lib/worker/bulkgate/index.js +10 -0
- package/lib/worker/email/adapter.d.ts +9 -0
- package/lib/worker/{email.js → email/adapter.js} +27 -13
- package/lib/worker/email/index.d.ts +4 -0
- package/lib/worker/email/index.js +10 -0
- package/lib/worker/enrollment-order-generator/adapter.d.ts +4 -0
- package/lib/worker/{enrollment-order-generator.js → enrollment-order-generator/adapter.js} +2 -2
- package/lib/worker/enrollment-order-generator/index.d.ts +4 -0
- package/lib/worker/enrollment-order-generator/index.js +13 -0
- package/lib/worker/{error-notifications.d.ts → error-notifications/adapter.d.ts} +1 -0
- package/lib/worker/{error-notifications.js → error-notifications/adapter.js} +9 -8
- package/lib/worker/error-notifications/index.d.ts +4 -0
- package/lib/worker/error-notifications/index.js +13 -0
- package/lib/worker/{export-token.d.ts → export-token/adapter.d.ts} +1 -1
- package/lib/worker/{export-token.js → export-token/adapter.js} +2 -3
- package/lib/worker/export-token/index.d.ts +4 -0
- package/lib/worker/export-token/index.js +13 -0
- package/lib/worker/{external.d.ts → external/adapter.d.ts} +1 -0
- package/lib/worker/{external.js → external/adapter.js} +2 -2
- package/lib/worker/external/index.d.ts +4 -0
- package/lib/worker/external/index.js +10 -0
- package/lib/worker/heartbeat/adapter.d.ts +8 -0
- package/lib/worker/{heartbeat.js → heartbeat/adapter.js} +3 -3
- package/lib/worker/heartbeat/index.d.ts +4 -0
- package/lib/worker/heartbeat/index.js +10 -0
- package/lib/worker/{http-request.d.ts → http-request/adapter.d.ts} +1 -1
- package/lib/worker/{http-request.js → http-request/adapter.js} +2 -3
- package/lib/worker/http-request/index.d.ts +4 -0
- package/lib/worker/http-request/index.js +10 -0
- package/lib/worker/{message.d.ts → message/adapter.d.ts} +1 -0
- package/lib/worker/{message.js → message/adapter.js} +2 -2
- package/lib/worker/message/index.d.ts +4 -0
- package/lib/worker/message/index.js +10 -0
- package/lib/worker/push-notification/adapter.d.ts +9 -0
- package/lib/worker/{push-notification.js → push-notification/adapter.js} +3 -3
- package/lib/worker/push-notification/index.d.ts +4 -0
- package/lib/worker/push-notification/index.js +10 -0
- package/lib/worker/twilio/adapter.d.ts +8 -0
- package/lib/worker/{twilio.js → twilio/adapter.js} +3 -3
- package/lib/worker/twilio/index.d.ts +4 -0
- package/lib/worker/twilio/index.js +10 -0
- package/lib/worker/update-coinbase-rates/adapter.d.ts +4 -0
- package/lib/worker/{update-coinbase-rates.js → update-coinbase-rates/adapter.js} +8 -6
- package/lib/worker/update-coinbase-rates/index.d.ts +4 -0
- package/lib/worker/update-coinbase-rates/index.js +13 -0
- package/lib/worker/update-ecb-rates/adapter.d.ts +4 -0
- package/lib/worker/{update-ecb-rates.js → update-ecb-rates/adapter.js} +11 -9
- package/lib/worker/update-ecb-rates/index.d.ts +4 -0
- package/lib/worker/update-ecb-rates/index.js +13 -0
- package/lib/worker/{update-token-ownership.d.ts → update-token-ownership/adapter.d.ts} +2 -0
- package/lib/worker/{update-token-ownership.js → update-token-ownership/adapter.js} +8 -7
- package/lib/worker/update-token-ownership/index.d.ts +4 -0
- package/lib/worker/update-token-ownership/index.js +13 -0
- package/lib/worker/{zombie-killer.js → zombie-killer/adapter.js} +1 -2
- package/lib/worker/zombie-killer/index.d.ts +4 -0
- package/lib/worker/zombie-killer/index.js +10 -0
- package/package.json +15 -10
- package/lib/delivery/post.d.ts +0 -1
- package/lib/delivery/send-message.d.ts +0 -1
- package/lib/delivery/stores.d.ts +0 -1
- package/lib/enrollments/licensed.d.ts +0 -4
- package/lib/files/gridfs/handler-express.d.ts +0 -9
- package/lib/files/gridfs/handler-express.js +0 -110
- package/lib/files/gridfs/handler-fastify.d.ts +0 -3
- package/lib/files/gridfs/handler-fastify.js +0 -138
- package/lib/files/minio/handler-express.d.ts +0 -2
- package/lib/files/minio/handler-express.js +0 -36
- package/lib/files/minio/handler-fastify.d.ts +0 -3
- package/lib/files/minio/handler-fastify.js +0 -40
- package/lib/filters/local-search.d.ts +0 -3
- package/lib/filters/strict-equal.d.ts +0 -1
- package/lib/payment/apple-iap/handler-express.d.ts +0 -2
- package/lib/payment/apple-iap/handler-express.js +0 -103
- package/lib/payment/apple-iap/handler-fastify.d.ts +0 -3
- package/lib/payment/braintree.d.ts +0 -1
- package/lib/payment/braintree.js +0 -138
- package/lib/payment/cryptopay/handler-express.d.ts +0 -2
- package/lib/payment/cryptopay/handler-express.js +0 -19
- package/lib/payment/cryptopay/handler-fastify.d.ts +0 -3
- package/lib/payment/cryptopay/handler-fastify.js +0 -17
- package/lib/payment/cryptopay/plugin.d.ts +0 -3
- package/lib/payment/datatrans-v2/handler-express.d.ts +0 -1
- package/lib/payment/datatrans-v2/handler-express.js +0 -71
- package/lib/payment/datatrans-v2/handler-fastify.d.ts +0 -2
- package/lib/payment/datatrans-v2/handler-fastify.js +0 -71
- package/lib/payment/invoice-prepaid.d.ts +0 -1
- package/lib/payment/invoice.d.ts +0 -1
- package/lib/payment/paypal-checkout.d.ts +0 -1
- package/lib/payment/paypal-checkout.js +0 -87
- package/lib/payment/payrexx/handler-express.d.ts +0 -1
- package/lib/payment/payrexx/handler-express.js +0 -85
- package/lib/payment/payrexx/handler-fastify.d.ts +0 -2
- package/lib/payment/payrexx/handler-fastify.js +0 -91
- package/lib/payment/postfinance-checkout/handler-express.d.ts +0 -1
- package/lib/payment/postfinance-checkout/handler-express.js +0 -37
- package/lib/payment/postfinance-checkout/handler-fastify.d.ts +0 -2
- package/lib/payment/postfinance-checkout/handler-fastify.js +0 -40
- package/lib/payment/saferpay/handler-express.d.ts +0 -1
- package/lib/payment/saferpay/handler-express.js +0 -59
- package/lib/payment/saferpay/handler-fastify.d.ts +0 -2
- package/lib/payment/saferpay/handler-fastify.js +0 -62
- package/lib/payment/stripe/handler-express.d.ts +0 -5
- package/lib/payment/stripe/handler-express.js +0 -121
- package/lib/payment/stripe/handler-fastify.d.ts +0 -6
- package/lib/payment/stripe/handler-fastify.js +0 -131
- package/lib/presets/all-express.d.ts +0 -6
- package/lib/presets/all-express.js +0 -26
- package/lib/presets/all-fastify.d.ts +0 -6
- package/lib/presets/all-fastify.js +0 -49
- package/lib/presets/base-express.d.ts +0 -2
- package/lib/presets/base-express.js +0 -5
- package/lib/presets/base-fastify.d.ts +0 -3
- package/lib/presets/base-fastify.js +0 -16
- package/lib/presets/crypto-express.d.ts +0 -3
- package/lib/presets/crypto-express.js +0 -8
- package/lib/presets/crypto-fastify.d.ts +0 -3
- package/lib/presets/crypto-fastify.js +0 -11
- package/lib/pricing/discount-half-price.d.ts +0 -2
- package/lib/pricing/discount-half-price.js +0 -33
- package/lib/pricing/order-items-discount.d.ts +0 -2
- package/lib/pricing/order-items-discount.js +0 -50
- package/lib/pricing/order-round.d.ts +0 -10
- package/lib/pricing/order-round.js +0 -135
- package/lib/pricing/product-catalog-price-options.d.ts +0 -2
- package/lib/pricing/product-catalog-price-options.js +0 -51
- package/lib/pricing/product-round.d.ts +0 -10
- package/lib/pricing/product-round.js +0 -44
- package/lib/quotations/manual.d.ts +0 -1
- package/lib/warehousing/eth-minter.d.ts +0 -1
- package/lib/warehousing/store.d.ts +0 -1
- package/lib/worker/budgetsms.d.ts +0 -9
- package/lib/worker/bulk-export.d.ts +0 -2
- package/lib/worker/bulkgate.d.ts +0 -1
- package/lib/worker/email.d.ts +0 -1
- package/lib/worker/enrollment-order-generator.d.ts +0 -1
- package/lib/worker/heartbeat.d.ts +0 -1
- package/lib/worker/push-notification.d.ts +0 -1
- package/lib/worker/twilio.d.ts +0 -1
- package/lib/worker/update-coinbase-rates.d.ts +0 -1
- package/lib/worker/update-ecb-rates.d.ts +0 -1
- /package/lib/worker/{zombie-killer.d.ts → zombie-killer/adapter.d.ts} +0 -0
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { stripe } from "./stripe.js";
|
|
3
|
-
const logger = createLogger('unchained:stripe:handler');
|
|
4
|
-
export const WebhookEventTypes = {
|
|
5
|
-
PAYMENT_INTENT_SUCCEEDED: 'payment_intent.succeeded',
|
|
6
|
-
SETUP_INTENT_SUCCEEDED: 'setup_intent.succeeded',
|
|
7
|
-
};
|
|
8
|
-
export const stripeHandler = async (request, response) => {
|
|
9
|
-
const resolvedContext = request.unchainedContext;
|
|
10
|
-
const { modules, services } = resolvedContext;
|
|
11
|
-
let event;
|
|
12
|
-
try {
|
|
13
|
-
const sig = request.headers['stripe-signature'];
|
|
14
|
-
if (!sig) {
|
|
15
|
-
throw new Error('stripe-signature header was not provided for webhook');
|
|
16
|
-
}
|
|
17
|
-
if (!process.env.STRIPE_ENDPOINT_SECRET) {
|
|
18
|
-
throw new Error('env STRIPE_ENDPOINT_SECRET is required for webhook handling');
|
|
19
|
-
}
|
|
20
|
-
event = stripe.webhooks.constructEvent(request.body, sig, process.env.STRIPE_ENDPOINT_SECRET);
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
logger.error(`Error constructing event: ${err.message}`);
|
|
24
|
-
response.status(400).send({
|
|
25
|
-
message: err.message,
|
|
26
|
-
name: err.name,
|
|
27
|
-
});
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (!Object.values(WebhookEventTypes).includes(event.type)) {
|
|
31
|
-
logger.info(`unhandled event type`, {
|
|
32
|
-
type: event.type,
|
|
33
|
-
});
|
|
34
|
-
response.status(200).send({
|
|
35
|
-
ignored: true,
|
|
36
|
-
message: `Unhandled event type: ${event.type}. Supported types: ${Object.values(WebhookEventTypes).join(', ')}`,
|
|
37
|
-
});
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const environmentInMetadata = event.data?.object?.metadata?.environment || '';
|
|
41
|
-
const environmentInEnv = process.env.STRIPE_WEBHOOK_ENVIRONMENT || '';
|
|
42
|
-
if (environmentInMetadata !== environmentInEnv) {
|
|
43
|
-
logger.info(`unhandled event environment`, {
|
|
44
|
-
type: event.type,
|
|
45
|
-
environment: environmentInMetadata,
|
|
46
|
-
});
|
|
47
|
-
response.status(200).send({
|
|
48
|
-
ignored: true,
|
|
49
|
-
message: `Unhandled event environment: ${environmentInMetadata}. Supported environment: ${environmentInEnv}`,
|
|
50
|
-
});
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
logger.info(`Processing event`, {
|
|
54
|
-
type: event.type,
|
|
55
|
-
});
|
|
56
|
-
try {
|
|
57
|
-
if (event.type === WebhookEventTypes.PAYMENT_INTENT_SUCCEEDED) {
|
|
58
|
-
const paymentIntent = event.data.object;
|
|
59
|
-
const { orderPaymentId } = paymentIntent.metadata || {};
|
|
60
|
-
logger.info(`checkout with orderPaymentId: ${orderPaymentId}`, {
|
|
61
|
-
type: event.type,
|
|
62
|
-
});
|
|
63
|
-
await modules.orders.payments.logEvent(orderPaymentId, event);
|
|
64
|
-
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
65
|
-
orderPaymentId,
|
|
66
|
-
});
|
|
67
|
-
if (!orderPayment) {
|
|
68
|
-
throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
69
|
-
}
|
|
70
|
-
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
71
|
-
paymentContext: {
|
|
72
|
-
paymentIntentId: paymentIntent.id,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
if (!order)
|
|
76
|
-
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
77
|
-
logger.info(`checkout successful`, {
|
|
78
|
-
orderPaymentId,
|
|
79
|
-
orderId: order._id,
|
|
80
|
-
type: event.type,
|
|
81
|
-
});
|
|
82
|
-
response.status(200).send({
|
|
83
|
-
message: 'checkout successful',
|
|
84
|
-
orderId: order._id,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
else if (event.type === WebhookEventTypes.SETUP_INTENT_SUCCEEDED) {
|
|
88
|
-
const setupIntent = event.data.object;
|
|
89
|
-
const { paymentProviderId, userId } = setupIntent.metadata || {};
|
|
90
|
-
logger.info(`registered payment credential with paymentProviderId: ${paymentProviderId}`, {
|
|
91
|
-
type: event.type,
|
|
92
|
-
userId,
|
|
93
|
-
});
|
|
94
|
-
const paymentCredentials = await services.orders.registerPaymentCredentials(paymentProviderId, {
|
|
95
|
-
transactionContext: {
|
|
96
|
-
setupIntentId: setupIntent.id,
|
|
97
|
-
},
|
|
98
|
-
userId,
|
|
99
|
-
});
|
|
100
|
-
logger.info(`payment credentials registration successful`, {
|
|
101
|
-
userId,
|
|
102
|
-
paymentProviderId,
|
|
103
|
-
paymentCredentialsId: paymentCredentials?._id,
|
|
104
|
-
type: event.type,
|
|
105
|
-
});
|
|
106
|
-
response.status(200).send({
|
|
107
|
-
message: 'payment credentials registration successful',
|
|
108
|
-
paymentCredentialsId: paymentCredentials?._id,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
logger.error(error, {
|
|
114
|
-
type: event.type,
|
|
115
|
-
});
|
|
116
|
-
response.status(500).send({
|
|
117
|
-
message: error.message,
|
|
118
|
-
name: error.name,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
};
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { stripe } from "./stripe.js";
|
|
3
|
-
const logger = createLogger('unchained:stripe:handler');
|
|
4
|
-
export const WebhookEventTypes = {
|
|
5
|
-
PAYMENT_INTENT_SUCCEEDED: 'payment_intent.succeeded',
|
|
6
|
-
SETUP_INTENT_SUCCEEDED: 'setup_intent.succeeded',
|
|
7
|
-
};
|
|
8
|
-
export const stripeHandler = async (req, reply) => {
|
|
9
|
-
const resolvedContext = req.unchainedContext;
|
|
10
|
-
const { modules, services } = resolvedContext;
|
|
11
|
-
let event;
|
|
12
|
-
try {
|
|
13
|
-
const sig = req.headers['stripe-signature'];
|
|
14
|
-
if (!process.env.STRIPE_ENDPOINT_SECRET) {
|
|
15
|
-
throw new Error('env STRIPE_ENDPOINT_SECRET is required for webhook handling');
|
|
16
|
-
}
|
|
17
|
-
if (!sig) {
|
|
18
|
-
throw new Error('stripe-signature header was not provided for webhook');
|
|
19
|
-
}
|
|
20
|
-
event = stripe.webhooks.constructEvent(req.body, sig, process.env.STRIPE_ENDPOINT_SECRET);
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
logger.error(`Error constructing event: ${err.message}`);
|
|
24
|
-
reply.status(400);
|
|
25
|
-
return reply.send({
|
|
26
|
-
success: false,
|
|
27
|
-
message: err.message,
|
|
28
|
-
name: err.name,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (!Object.values(WebhookEventTypes).includes(event.type)) {
|
|
32
|
-
logger.info(`unhandled event type`, {
|
|
33
|
-
type: event.type,
|
|
34
|
-
});
|
|
35
|
-
reply.status(200);
|
|
36
|
-
return reply.send({
|
|
37
|
-
success: false,
|
|
38
|
-
ignored: true,
|
|
39
|
-
name: 'UNHANDLED_EVENT_TYPE',
|
|
40
|
-
message: `Unhandled event type: ${event.type}. Supported types: ${Object.values(WebhookEventTypes).join(', ')}`,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
const environmentInMetadata = event.data?.object?.metadata?.environment || '';
|
|
44
|
-
const environmentInEnv = process.env.STRIPE_WEBHOOK_ENVIRONMENT || '';
|
|
45
|
-
if (environmentInMetadata !== environmentInEnv) {
|
|
46
|
-
logger.info(`unhandled event environment`, {
|
|
47
|
-
type: event.type,
|
|
48
|
-
environment: environmentInMetadata,
|
|
49
|
-
});
|
|
50
|
-
reply.status(200);
|
|
51
|
-
return reply.send({
|
|
52
|
-
success: false,
|
|
53
|
-
ignored: true,
|
|
54
|
-
name: 'UNHANDLED_EVENT_ENVIRONMENT',
|
|
55
|
-
message: `Unhandled event environment: ${environmentInMetadata}. Supported environment: ${environmentInEnv}`,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
logger.info(`Processing event`, {
|
|
59
|
-
type: event.type,
|
|
60
|
-
});
|
|
61
|
-
try {
|
|
62
|
-
if (event.type === WebhookEventTypes.PAYMENT_INTENT_SUCCEEDED) {
|
|
63
|
-
const paymentIntent = event.data.object;
|
|
64
|
-
const { orderPaymentId } = paymentIntent.metadata || {};
|
|
65
|
-
logger.info(`checkout with orderPaymentId: ${orderPaymentId}`, {
|
|
66
|
-
type: event.type,
|
|
67
|
-
});
|
|
68
|
-
await modules.orders.payments.logEvent(orderPaymentId, event);
|
|
69
|
-
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
70
|
-
orderPaymentId,
|
|
71
|
-
});
|
|
72
|
-
if (!orderPayment) {
|
|
73
|
-
throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
74
|
-
}
|
|
75
|
-
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
76
|
-
paymentContext: {
|
|
77
|
-
paymentIntentId: paymentIntent.id,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
if (!order)
|
|
81
|
-
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
82
|
-
logger.info(`checkout successful`, {
|
|
83
|
-
orderPaymentId,
|
|
84
|
-
orderId: order._id,
|
|
85
|
-
type: event.type,
|
|
86
|
-
});
|
|
87
|
-
reply.status(200);
|
|
88
|
-
return reply.send({
|
|
89
|
-
success: true,
|
|
90
|
-
orderId: order._id,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
else if (event.type === WebhookEventTypes.SETUP_INTENT_SUCCEEDED) {
|
|
94
|
-
const setupIntent = event.data.object;
|
|
95
|
-
const { paymentProviderId, userId } = setupIntent.metadata || {};
|
|
96
|
-
logger.info(`registered payment credential with paymentProviderId: ${paymentProviderId}`, {
|
|
97
|
-
type: event.type,
|
|
98
|
-
userId,
|
|
99
|
-
});
|
|
100
|
-
const paymentCredentials = await services.orders.registerPaymentCredentials(paymentProviderId, {
|
|
101
|
-
transactionContext: {
|
|
102
|
-
setupIntentId: setupIntent.id,
|
|
103
|
-
},
|
|
104
|
-
userId,
|
|
105
|
-
});
|
|
106
|
-
logger.info(`payment credentials registration successful`, {
|
|
107
|
-
userId,
|
|
108
|
-
paymentProviderId,
|
|
109
|
-
paymentCredentialsId: paymentCredentials?._id,
|
|
110
|
-
type: event.type,
|
|
111
|
-
});
|
|
112
|
-
reply.status(200);
|
|
113
|
-
return reply.send({
|
|
114
|
-
success: true,
|
|
115
|
-
message: 'payment credentials registration successful',
|
|
116
|
-
paymentCredentialsId: paymentCredentials?._id,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
logger.error(error, {
|
|
122
|
-
type: event.type,
|
|
123
|
-
});
|
|
124
|
-
reply.status(500);
|
|
125
|
-
return reply.send({
|
|
126
|
-
success: false,
|
|
127
|
-
message: error.message,
|
|
128
|
-
name: error.name,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import connectCryptoToExpress from "./crypto-express.js";
|
|
3
|
-
import connectBaseToExpress from "./base-express.js";
|
|
4
|
-
import { datatransHandler } from "../payment/datatrans-v2/handler-express.js";
|
|
5
|
-
import { stripeHandler } from "../payment/stripe/handler-express.js";
|
|
6
|
-
import { postfinanceCheckoutHandler } from "../payment/postfinance-checkout/handler-express.js";
|
|
7
|
-
import { appleIAPHandler } from "../payment/apple-iap/handler-express.js";
|
|
8
|
-
import { payrexxHandler } from "../payment/payrexx/handler-express.js";
|
|
9
|
-
import { saferpayHandler } from "../payment/saferpay/handler-express.js";
|
|
10
|
-
import { configureGenerateOrderAutoscheduling } from "../worker/enrollment-order-generator.js";
|
|
11
|
-
const { STRIPE_WEBHOOK_PATH = '/payment/stripe', PAYREXX_WEBHOOK_PATH = '/payment/payrexx', PFCHECKOUT_WEBHOOK_PATH = '/payment/postfinance-checkout', DATATRANS_WEBHOOK_PATH = '/payment/datatrans/webhook', APPLE_IAP_WEBHOOK_PATH = '/payment/apple-iap', SAFERPAY_WEBHOOK_PATH = '/payment/saferpay/webhook', } = process.env;
|
|
12
|
-
export default (app, { unchainedAPI }) => {
|
|
13
|
-
connectBaseToExpress(app);
|
|
14
|
-
connectCryptoToExpress(app, unchainedAPI);
|
|
15
|
-
app.use(STRIPE_WEBHOOK_PATH, express.raw({ type: 'application/json' }), stripeHandler);
|
|
16
|
-
app.use(PFCHECKOUT_WEBHOOK_PATH, express.json(), postfinanceCheckoutHandler);
|
|
17
|
-
app.use(DATATRANS_WEBHOOK_PATH, express.text({
|
|
18
|
-
type: 'application/json',
|
|
19
|
-
}), datatransHandler);
|
|
20
|
-
app.use(APPLE_IAP_WEBHOOK_PATH, express.json({
|
|
21
|
-
strict: false,
|
|
22
|
-
}), appleIAPHandler);
|
|
23
|
-
app.use(PAYREXX_WEBHOOK_PATH, express.json({ type: 'application/json' }), payrexxHandler);
|
|
24
|
-
app.use(SAFERPAY_WEBHOOK_PATH, saferpayHandler);
|
|
25
|
-
configureGenerateOrderAutoscheduling();
|
|
26
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import connectCryptoToFastify from "./crypto-fastify.js";
|
|
2
|
-
import connectBaseToFastify from "./base-fastify.js";
|
|
3
|
-
import { stripeHandler } from "../payment/stripe/handler-fastify.js";
|
|
4
|
-
import { postfinanceCheckoutHandler } from "../payment/postfinance-checkout/handler-fastify.js";
|
|
5
|
-
import { datatransHandler } from "../payment/datatrans-v2/handler-fastify.js";
|
|
6
|
-
import { appleIAPHandler } from "../payment/apple-iap/handler-fastify.js";
|
|
7
|
-
import { payrexxHandler } from "../payment/payrexx/handler-fastify.js";
|
|
8
|
-
import { saferpayHandler } from "../payment/saferpay/handler-fastify.js";
|
|
9
|
-
import { configureGenerateOrderAutoscheduling } from "../worker/enrollment-order-generator.js";
|
|
10
|
-
const { STRIPE_WEBHOOK_PATH = '/payment/stripe', PAYREXX_WEBHOOK_PATH = '/payment/payrexx', PFCHECKOUT_WEBHOOK_PATH = '/payment/postfinance-checkout', DATATRANS_WEBHOOK_PATH = '/payment/datatrans/webhook', APPLE_IAP_WEBHOOK_PATH = '/payment/apple-iap', SAFERPAY_WEBHOOK_PATH = '/payment/saferpay/webhook', } = process.env;
|
|
11
|
-
export default (fastify, { unchainedAPI }) => {
|
|
12
|
-
connectBaseToFastify(fastify);
|
|
13
|
-
connectCryptoToFastify(fastify, unchainedAPI);
|
|
14
|
-
fastify.register((s, opts, registered) => {
|
|
15
|
-
s.addContentTypeParser('application/json', { parseAs: 'string', bodyLimit: 1024 * 1024 }, s.defaultTextParser);
|
|
16
|
-
s.route({
|
|
17
|
-
url: STRIPE_WEBHOOK_PATH,
|
|
18
|
-
method: 'POST',
|
|
19
|
-
handler: stripeHandler,
|
|
20
|
-
});
|
|
21
|
-
s.route({
|
|
22
|
-
url: DATATRANS_WEBHOOK_PATH,
|
|
23
|
-
method: 'POST',
|
|
24
|
-
handler: datatransHandler,
|
|
25
|
-
});
|
|
26
|
-
registered();
|
|
27
|
-
});
|
|
28
|
-
fastify.route({
|
|
29
|
-
url: PFCHECKOUT_WEBHOOK_PATH,
|
|
30
|
-
method: 'POST',
|
|
31
|
-
handler: postfinanceCheckoutHandler,
|
|
32
|
-
});
|
|
33
|
-
fastify.route({
|
|
34
|
-
url: APPLE_IAP_WEBHOOK_PATH,
|
|
35
|
-
method: 'POST',
|
|
36
|
-
handler: appleIAPHandler,
|
|
37
|
-
});
|
|
38
|
-
fastify.route({
|
|
39
|
-
url: PAYREXX_WEBHOOK_PATH,
|
|
40
|
-
method: 'POST',
|
|
41
|
-
handler: payrexxHandler,
|
|
42
|
-
});
|
|
43
|
-
fastify.route({
|
|
44
|
-
url: SAFERPAY_WEBHOOK_PATH,
|
|
45
|
-
method: 'GET',
|
|
46
|
-
handler: saferpayHandler,
|
|
47
|
-
});
|
|
48
|
-
configureGenerateOrderAutoscheduling();
|
|
49
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import handler from "../files/gridfs/handler-fastify.js";
|
|
2
|
-
const { GRIDFS_PUT_SERVER_PATH = '/gridfs' } = process.env;
|
|
3
|
-
export default (fastify) => {
|
|
4
|
-
fastify.register((s, opts, registered) => {
|
|
5
|
-
s.removeAllContentTypeParsers();
|
|
6
|
-
s.addContentTypeParser('*', function (req, payload, done) {
|
|
7
|
-
done(null);
|
|
8
|
-
});
|
|
9
|
-
s.route({
|
|
10
|
-
url: GRIDFS_PUT_SERVER_PATH + '/:directoryName/:fileName',
|
|
11
|
-
method: ['GET', 'PUT', 'OPTIONS'],
|
|
12
|
-
handler,
|
|
13
|
-
});
|
|
14
|
-
registered();
|
|
15
|
-
});
|
|
16
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import handler from "../payment/cryptopay/handler-express.js";
|
|
3
|
-
import { configureExportToken } from "../worker/export-token.js";
|
|
4
|
-
const { CRYPTOPAY_WEBHOOK_PATH = '/payment/cryptopay' } = process.env;
|
|
5
|
-
export default (app, unchainedAPI) => {
|
|
6
|
-
app.use(CRYPTOPAY_WEBHOOK_PATH, express.json(), handler);
|
|
7
|
-
configureExportToken(unchainedAPI);
|
|
8
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import handler from "../payment/cryptopay/handler-fastify.js";
|
|
2
|
-
import { configureExportToken } from "../worker/export-token.js";
|
|
3
|
-
const { CRYPTOPAY_WEBHOOK_PATH = '/payment/cryptopay' } = process.env;
|
|
4
|
-
export default (fastify, unchainedAPI) => {
|
|
5
|
-
fastify.route({
|
|
6
|
-
url: CRYPTOPAY_WEBHOOK_PATH,
|
|
7
|
-
method: 'POST',
|
|
8
|
-
handler,
|
|
9
|
-
});
|
|
10
|
-
configureExportToken(unchainedAPI);
|
|
11
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { OrderDiscountDirector, OrderDiscountAdapter, } from '@unchainedshop/core';
|
|
2
|
-
export const HalfPrice = {
|
|
3
|
-
...OrderDiscountAdapter,
|
|
4
|
-
key: 'shop.unchained.discount.half-price',
|
|
5
|
-
label: 'Half Price',
|
|
6
|
-
version: '1.0.0',
|
|
7
|
-
orderIndex: 10,
|
|
8
|
-
isManualAdditionAllowed: async () => {
|
|
9
|
-
return false;
|
|
10
|
-
},
|
|
11
|
-
isManualRemovalAllowed: async () => {
|
|
12
|
-
return false;
|
|
13
|
-
},
|
|
14
|
-
actions: async ({ context }) => ({
|
|
15
|
-
...(await OrderDiscountAdapter.actions({ context })),
|
|
16
|
-
isValidForSystemTriggering: async () => {
|
|
17
|
-
const { order } = context;
|
|
18
|
-
const user = await context.modules.users.findUserById(order.userId);
|
|
19
|
-
const isUserEligibleForHalfPrice = user?.tags && user.tags.indexOf('half-price') !== -1;
|
|
20
|
-
return !!isUserEligibleForHalfPrice;
|
|
21
|
-
},
|
|
22
|
-
isValidForCodeTriggering: async () => {
|
|
23
|
-
return false;
|
|
24
|
-
},
|
|
25
|
-
discountForPricingAdapterKey({ pricingAdapterKey }) {
|
|
26
|
-
if (pricingAdapterKey === 'shop.unchained.pricing.product-discount') {
|
|
27
|
-
return { rate: 0.5 };
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
},
|
|
31
|
-
}),
|
|
32
|
-
};
|
|
33
|
-
OrderDiscountDirector.registerAdapter(HalfPrice);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { ProductPricingSheet, OrderPricingDirector, OrderPricingAdapter, OrderPricingRowCategory, resolveRatioAndTaxDivisorForPricingSheet, } from '@unchainedshop/core';
|
|
2
|
-
import { calculation as calcUtils } from '@unchainedshop/utils';
|
|
3
|
-
export const OrderItemsDiscount = {
|
|
4
|
-
...OrderPricingAdapter,
|
|
5
|
-
key: 'shop.unchained.pricing.order-items-discount',
|
|
6
|
-
version: '1.0.0',
|
|
7
|
-
label: 'Apply Discounts on Total Value Of Goods',
|
|
8
|
-
orderIndex: 30,
|
|
9
|
-
isActivatedFor: () => {
|
|
10
|
-
return true;
|
|
11
|
-
},
|
|
12
|
-
actions: (params) => {
|
|
13
|
-
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
14
|
-
const { order, orderPositions } = params.context;
|
|
15
|
-
return {
|
|
16
|
-
...pricingAdapter,
|
|
17
|
-
calculate: async () => {
|
|
18
|
-
const totalAmountOfItems = params.calculationSheet.total({
|
|
19
|
-
category: OrderPricingRowCategory.Items,
|
|
20
|
-
useNetPrice: false,
|
|
21
|
-
}).amount;
|
|
22
|
-
const itemShares = orderPositions.map((orderPosition) => resolveRatioAndTaxDivisorForPricingSheet(ProductPricingSheet({
|
|
23
|
-
calculation: orderPosition.calculation,
|
|
24
|
-
currencyCode: order.currencyCode,
|
|
25
|
-
quantity: orderPosition.quantity,
|
|
26
|
-
}), totalAmountOfItems));
|
|
27
|
-
let amountLeft = totalAmountOfItems;
|
|
28
|
-
params.discounts.forEach(({ configuration, discountId }) => {
|
|
29
|
-
const leftInItemsToSplit = calcUtils.calculateAmountToSplit({ ...configuration }, totalAmountOfItems);
|
|
30
|
-
const [itemsDiscountAmount, itemsTaxAmount] = calcUtils.applyDiscountToMultipleShares(itemShares, Math.max(0, Math.min(amountLeft, leftInItemsToSplit)));
|
|
31
|
-
amountLeft -= itemsDiscountAmount;
|
|
32
|
-
const discountAmount = itemsDiscountAmount * -1;
|
|
33
|
-
const taxAmount = itemsTaxAmount * -1;
|
|
34
|
-
if (discountAmount) {
|
|
35
|
-
pricingAdapter.resultSheet().addDiscount({
|
|
36
|
-
amount: discountAmount,
|
|
37
|
-
taxAmount,
|
|
38
|
-
discountId,
|
|
39
|
-
meta: {
|
|
40
|
-
adapter: OrderItemsDiscount.key,
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return pricingAdapter.calculate();
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
OrderPricingDirector.registerAdapter(OrderItemsDiscount);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type IOrderPricingAdapter } from '@unchainedshop/core';
|
|
2
|
-
interface PriceRoundSettings {
|
|
3
|
-
defaultPrecision: number;
|
|
4
|
-
roundTo: (value: number, precision: number, currencyCode: string) => number;
|
|
5
|
-
}
|
|
6
|
-
export declare const OrderPriceRound: IOrderPricingAdapter & {
|
|
7
|
-
configure: (params: PriceRoundSettings) => void;
|
|
8
|
-
settings: PriceRoundSettings;
|
|
9
|
-
};
|
|
10
|
-
export {};
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { OrderPricingAdapter, OrderPricingDirector, OrderPricingRowCategory, } from '@unchainedshop/core';
|
|
2
|
-
const calculateDifference = (amount, currencyCode) => {
|
|
3
|
-
const roundedAmount = OrderPriceRound.settings.roundTo(amount, OrderPriceRound.settings.defaultPrecision, currencyCode);
|
|
4
|
-
return roundedAmount - amount;
|
|
5
|
-
};
|
|
6
|
-
export const OrderPriceRound = {
|
|
7
|
-
...OrderPricingAdapter,
|
|
8
|
-
key: 'shop.unchained.pricing.order-round',
|
|
9
|
-
version: '1.0.0',
|
|
10
|
-
label: 'Round order price to the next precision number',
|
|
11
|
-
orderIndex: 90,
|
|
12
|
-
isActivatedFor: () => {
|
|
13
|
-
return true;
|
|
14
|
-
},
|
|
15
|
-
settings: {
|
|
16
|
-
defaultPrecision: 5,
|
|
17
|
-
roundTo: (value, precision) => precision !== 0 ? Math.round(value / precision) * precision : value,
|
|
18
|
-
},
|
|
19
|
-
configure({ defaultPrecision, roundTo }) {
|
|
20
|
-
if (defaultPrecision)
|
|
21
|
-
this.settings.defaultPrecision = defaultPrecision;
|
|
22
|
-
if (roundTo)
|
|
23
|
-
this.settings.roundTo = roundTo;
|
|
24
|
-
},
|
|
25
|
-
actions: (params) => {
|
|
26
|
-
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
27
|
-
return {
|
|
28
|
-
...pricingAdapter,
|
|
29
|
-
calculate: async () => {
|
|
30
|
-
const { currencyCode } = params.context;
|
|
31
|
-
if (!currencyCode)
|
|
32
|
-
return pricingAdapter.calculate();
|
|
33
|
-
const { amount: deliveryAmount } = params.calculationSheet.total({
|
|
34
|
-
category: OrderPricingRowCategory.Delivery,
|
|
35
|
-
useNetPrice: true,
|
|
36
|
-
});
|
|
37
|
-
if (deliveryAmount) {
|
|
38
|
-
const taxes = params.calculationSheet.taxSum({
|
|
39
|
-
baseCategory: OrderPricingRowCategory.Delivery,
|
|
40
|
-
});
|
|
41
|
-
const deliveryTaxRate = taxes / deliveryAmount;
|
|
42
|
-
const deliveryDifference = calculateDifference(deliveryAmount, currencyCode);
|
|
43
|
-
pricingAdapter.resultSheet().addDelivery({
|
|
44
|
-
amount: deliveryDifference,
|
|
45
|
-
taxAmount: deliveryTaxRate * deliveryDifference,
|
|
46
|
-
meta: {
|
|
47
|
-
adapter: OrderPriceRound.key,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
const { amount: discountAmount } = params.calculationSheet.total({
|
|
52
|
-
category: OrderPricingRowCategory.Discounts,
|
|
53
|
-
useNetPrice: true,
|
|
54
|
-
});
|
|
55
|
-
if (discountAmount) {
|
|
56
|
-
const taxes = params.calculationSheet.taxSum({
|
|
57
|
-
baseCategory: OrderPricingRowCategory.Discounts,
|
|
58
|
-
});
|
|
59
|
-
const discountTaxRate = taxes / discountAmount;
|
|
60
|
-
const discountsDifference = calculateDifference(discountAmount, currencyCode);
|
|
61
|
-
pricingAdapter.resultSheet().addDiscount({
|
|
62
|
-
amount: discountsDifference,
|
|
63
|
-
taxAmount: discountsDifference * discountTaxRate,
|
|
64
|
-
meta: {
|
|
65
|
-
adapter: OrderPriceRound.key,
|
|
66
|
-
},
|
|
67
|
-
discountId: null,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
const { amount: itemsAmount } = params.calculationSheet.total({
|
|
71
|
-
category: OrderPricingRowCategory.Items,
|
|
72
|
-
useNetPrice: true,
|
|
73
|
-
});
|
|
74
|
-
if (itemsAmount) {
|
|
75
|
-
const taxes = params.calculationSheet.taxSum({
|
|
76
|
-
baseCategory: OrderPricingRowCategory.Items,
|
|
77
|
-
});
|
|
78
|
-
const itemTaxRate = taxes / itemsAmount;
|
|
79
|
-
const itemsDifference = calculateDifference(itemsAmount, currencyCode);
|
|
80
|
-
pricingAdapter.resultSheet().addItems({
|
|
81
|
-
amount: itemsDifference,
|
|
82
|
-
taxAmount: itemsDifference * itemTaxRate,
|
|
83
|
-
meta: {
|
|
84
|
-
adapter: OrderPriceRound.key,
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
const { amount: paymentAmount } = params.calculationSheet.total({
|
|
89
|
-
category: OrderPricingRowCategory.Payment,
|
|
90
|
-
useNetPrice: true,
|
|
91
|
-
});
|
|
92
|
-
if (paymentAmount) {
|
|
93
|
-
const taxes = params.calculationSheet.taxSum({
|
|
94
|
-
baseCategory: OrderPricingRowCategory.Payment,
|
|
95
|
-
});
|
|
96
|
-
const paymentTaxRate = taxes / paymentAmount;
|
|
97
|
-
const paymentsDifference = calculateDifference(paymentAmount, currencyCode);
|
|
98
|
-
pricingAdapter.resultSheet().addPayment({
|
|
99
|
-
amount: paymentsDifference,
|
|
100
|
-
taxAmount: paymentsDifference * paymentTaxRate,
|
|
101
|
-
meta: {
|
|
102
|
-
adapter: OrderPriceRound.key,
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
const priorTaxesAmount = params.calculationSheet.taxSum({
|
|
107
|
-
category: OrderPricingRowCategory.Taxes,
|
|
108
|
-
});
|
|
109
|
-
const additionalRoundedTaxes = pricingAdapter.resultSheet().taxSum({
|
|
110
|
-
category: OrderPricingRowCategory.Taxes,
|
|
111
|
-
});
|
|
112
|
-
const taxesAmount = priorTaxesAmount + additionalRoundedTaxes;
|
|
113
|
-
if (taxesAmount) {
|
|
114
|
-
const taxDifference = calculateDifference(taxesAmount, currencyCode);
|
|
115
|
-
pricingAdapter.resultSheet().calculation.push({
|
|
116
|
-
category: OrderPricingRowCategory.Taxes,
|
|
117
|
-
amount: taxDifference,
|
|
118
|
-
meta: {
|
|
119
|
-
adapter: OrderPriceRound.key,
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
pricingAdapter.resultSheet().calculation.push({
|
|
123
|
-
category: null,
|
|
124
|
-
amount: taxDifference,
|
|
125
|
-
meta: {
|
|
126
|
-
adapter: OrderPriceRound.key,
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
return pricingAdapter.calculate();
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
OrderPricingDirector.registerAdapter(OrderPriceRound);
|