@unchainedshop/plugins 1.1.3 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/delivery/pick-mup.d.ts +1 -0
- package/lib/delivery/pick-mup.js +98 -0
- package/lib/delivery/pick-mup.js.map +1 -0
- package/lib/delivery/post.d.ts +1 -0
- package/lib/delivery/post.js +23 -0
- package/lib/delivery/post.js.map +1 -0
- package/lib/delivery/send-message.d.ts +1 -0
- package/lib/delivery/send-message.js +41 -0
- package/lib/delivery/send-message.js.map +1 -0
- package/lib/delivery/stores.d.ts +1 -0
- package/lib/delivery/stores.js +39 -0
- package/lib/delivery/stores.js.map +1 -0
- package/lib/enrollments/licensed.d.ts +1 -0
- package/lib/enrollments/licensed.js +40 -0
- package/lib/enrollments/licensed.js.map +1 -0
- package/lib/files/gridfs/gridfs-adapter.js +1 -1
- package/lib/files/gridfs/gridfs-adapter.js.map +1 -1
- package/lib/files/gridfs/gridfs-webhook.js +2 -2
- package/lib/files/gridfs/gridfs-webhook.js.map +1 -1
- package/lib/files/minio/minio-webhook.js +1 -1
- package/lib/files/minio/minio-webhook.js.map +1 -1
- package/lib/filters/local-search.d.ts +3 -0
- package/lib/filters/local-search.js +84 -0
- package/lib/filters/local-search.js.map +1 -0
- package/lib/filters/strict-equal.d.ts +1 -0
- package/lib/filters/strict-equal.js +25 -0
- package/lib/filters/strict-equal.js.map +1 -0
- package/lib/payment/apple-iap/adapter.d.ts +1 -0
- package/lib/payment/apple-iap/adapter.js +284 -0
- package/lib/payment/apple-iap/adapter.js.map +1 -0
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +7 -0
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.js +5 -0
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.js.map +1 -0
- package/lib/payment/apple-iap/index.d.ts +2 -0
- package/lib/payment/apple-iap/index.js +3 -0
- package/lib/payment/apple-iap/index.js.map +1 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +18 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
- package/lib/payment/bity/adapter.d.ts +1 -0
- package/lib/payment/bity/adapter.js +316 -0
- package/lib/payment/bity/adapter.js.map +1 -0
- package/lib/payment/bity/db/BityCredentialsCollection.d.ts +11 -0
- package/lib/payment/bity/db/BityCredentialsCollection.js +5 -0
- package/lib/payment/bity/db/BityCredentialsCollection.js.map +1 -0
- package/lib/payment/bity/index.d.ts +2 -0
- package/lib/payment/bity/index.js +3 -0
- package/lib/payment/bity/index.js.map +1 -0
- package/lib/payment/bity/module/configureBityModule.d.ts +11 -0
- package/lib/payment/bity/module/configureBityModule.js +33 -0
- package/lib/payment/bity/module/configureBityModule.js.map +1 -0
- package/lib/payment/braintree.d.ts +1 -0
- package/lib/payment/braintree.js +129 -0
- package/lib/payment/braintree.js.map +1 -0
- package/lib/payment/cryptopay.d.ts +1 -0
- package/lib/payment/cryptopay.js +159 -0
- package/lib/payment/cryptopay.js.map +1 -0
- package/lib/payment/datatrans-v2/api/authorize.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/authorize.js +12 -0
- package/lib/payment/datatrans-v2/api/authorize.js.map +1 -0
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js +11 -0
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js.map +1 -0
- package/lib/payment/datatrans-v2/api/cancel.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/cancel.js +10 -0
- package/lib/payment/datatrans-v2/api/cancel.js.map +1 -0
- package/lib/payment/datatrans-v2/api/index.d.ts +19 -0
- package/lib/payment/datatrans-v2/api/index.js +24 -0
- package/lib/payment/datatrans-v2/api/index.js.map +1 -0
- package/lib/payment/datatrans-v2/api/init.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/init.js +31 -0
- package/lib/payment/datatrans-v2/api/init.js.map +1 -0
- package/lib/payment/datatrans-v2/api/makeFetcher.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/makeFetcher.js +41 -0
- package/lib/payment/datatrans-v2/api/makeFetcher.js.map +1 -0
- package/lib/payment/datatrans-v2/api/secureFields.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/secureFields.js +14 -0
- package/lib/payment/datatrans-v2/api/secureFields.js.map +1 -0
- package/lib/payment/datatrans-v2/api/settle.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/settle.js +10 -0
- package/lib/payment/datatrans-v2/api/settle.js.map +1 -0
- package/lib/payment/datatrans-v2/api/status.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/status.js +7 -0
- package/lib/payment/datatrans-v2/api/status.js.map +1 -0
- package/lib/payment/datatrans-v2/api/validate.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/validate.js +10 -0
- package/lib/payment/datatrans-v2/api/validate.js.map +1 -0
- package/lib/payment/datatrans-v2/generateSignature.d.ts +10 -0
- package/lib/payment/datatrans-v2/generateSignature.js +19 -0
- package/lib/payment/datatrans-v2/generateSignature.js.map +1 -0
- package/lib/payment/datatrans-v2/getPaths.d.ts +9 -0
- package/lib/payment/datatrans-v2/getPaths.js +9 -0
- package/lib/payment/datatrans-v2/getPaths.js.map +1 -0
- package/lib/payment/datatrans-v2/index.d.ts +1 -0
- package/lib/payment/datatrans-v2/index.js +384 -0
- package/lib/payment/datatrans-v2/index.js.map +1 -0
- package/lib/payment/datatrans-v2/middleware.d.ts +1 -0
- package/lib/payment/datatrans-v2/middleware.js +111 -0
- package/lib/payment/datatrans-v2/middleware.js.map +1 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +11 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.js +26 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.js.map +1 -0
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +7 -0
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +10 -0
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -0
- package/lib/payment/datatrans-v2/splitProperties.d.ts +8 -0
- package/lib/payment/datatrans-v2/splitProperties.js +58 -0
- package/lib/payment/datatrans-v2/splitProperties.js.map +1 -0
- package/lib/payment/invoice-prepaid.d.ts +1 -0
- package/lib/payment/invoice-prepaid.js +30 -0
- package/lib/payment/invoice-prepaid.js.map +1 -0
- package/lib/payment/invoice.d.ts +1 -0
- package/lib/payment/invoice.js +27 -0
- package/lib/payment/invoice.js.map +1 -0
- package/lib/payment/paypal-checkout.d.ts +1 -0
- package/lib/payment/paypal-checkout.js +82 -0
- package/lib/payment/paypal-checkout.js.map +1 -0
- package/lib/payment/postfinance-checkout/api.d.ts +11 -0
- package/lib/payment/postfinance-checkout/api.js +109 -0
- package/lib/payment/postfinance-checkout/api.js.map +1 -0
- package/lib/payment/postfinance-checkout/index.d.ts +1 -0
- package/lib/payment/postfinance-checkout/index.js +186 -0
- package/lib/payment/postfinance-checkout/index.js.map +1 -0
- package/lib/payment/postfinance-checkout/middleware.d.ts +1 -0
- package/lib/payment/postfinance-checkout/middleware.js +42 -0
- package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
- package/lib/payment/postfinance-checkout/types.d.ts +23 -0
- package/lib/payment/postfinance-checkout/types.js +12 -0
- package/lib/payment/postfinance-checkout/types.js.map +1 -0
- package/lib/payment/postfinance-checkout/utils.d.ts +4 -0
- package/lib/payment/postfinance-checkout/utils.js +20 -0
- package/lib/payment/postfinance-checkout/utils.js.map +1 -0
- package/lib/payment/stripe.d.ts +1 -0
- package/lib/payment/stripe.js +214 -0
- package/lib/payment/stripe.js.map +1 -0
- package/lib/payment/worldline-saferpay/index.d.ts +1 -0
- package/lib/payment/worldline-saferpay/index.js +112 -0
- package/lib/payment/worldline-saferpay/index.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.d.ts +14 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js +29 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.d.ts +9 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js +28 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.d.ts +4 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.d.ts +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.d.ts +73 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.d.ts +53 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.d.ts +13 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.d.ts +9 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.d.ts +5 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.d.ts +13 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js.map +1 -0
- package/lib/pricing/delivery-swiss-tax.d.ts +15 -0
- package/lib/pricing/delivery-swiss-tax.js +98 -0
- package/lib/pricing/delivery-swiss-tax.js.map +1 -0
- package/lib/pricing/discount-100-off.d.ts +1 -0
- package/lib/pricing/discount-100-off.js +34 -0
- package/lib/pricing/discount-100-off.js.map +1 -0
- package/lib/pricing/discount-half-price-manual.d.ts +1 -0
- package/lib/pricing/discount-half-price-manual.js +34 -0
- package/lib/pricing/discount-half-price-manual.js.map +1 -0
- package/lib/pricing/discount-half-price.d.ts +1 -0
- package/lib/pricing/discount-half-price.js +37 -0
- package/lib/pricing/discount-half-price.js.map +1 -0
- package/lib/pricing/free-delivery.d.ts +2 -0
- package/lib/pricing/free-delivery.js +26 -0
- package/lib/pricing/free-delivery.js.map +1 -0
- package/lib/pricing/free-payment.d.ts +2 -0
- package/lib/pricing/free-payment.js +26 -0
- package/lib/pricing/free-payment.js.map +1 -0
- package/lib/pricing/order-delivery.d.ts +1 -0
- package/lib/pricing/order-delivery.js +33 -0
- package/lib/pricing/order-delivery.js.map +1 -0
- package/lib/pricing/order-discount.d.ts +1 -0
- package/lib/pricing/order-discount.js +110 -0
- package/lib/pricing/order-discount.js.map +1 -0
- package/lib/pricing/order-items-discount.d.ts +1 -0
- package/lib/pricing/order-items-discount.js +88 -0
- package/lib/pricing/order-items-discount.js.map +1 -0
- package/lib/pricing/order-items.d.ts +1 -0
- package/lib/pricing/order-items.js +44 -0
- package/lib/pricing/order-items.js.map +1 -0
- package/lib/pricing/order-payment.d.ts +1 -0
- package/lib/pricing/order-payment.js +33 -0
- package/lib/pricing/order-payment.js.map +1 -0
- package/lib/pricing/product-catalog-price.d.ts +1 -0
- package/lib/pricing/product-catalog-price.js +37 -0
- package/lib/pricing/product-catalog-price.js.map +1 -0
- package/lib/pricing/product-discount.d.ts +1 -0
- package/lib/pricing/product-discount.js +55 -0
- package/lib/pricing/product-discount.js.map +1 -0
- package/lib/pricing/product-price-ECB-interbank-exchange.d.ts +1 -0
- package/lib/pricing/product-price-ECB-interbank-exchange.js +90 -0
- package/lib/pricing/product-price-ECB-interbank-exchange.js.map +1 -0
- package/lib/pricing/product-price-coinbase-exchange.d.ts +1 -0
- package/lib/pricing/product-price-coinbase-exchange.js +60 -0
- package/lib/pricing/product-price-coinbase-exchange.js.map +1 -0
- package/lib/pricing/product-price-cryptopay.d.ts +1 -0
- package/lib/pricing/product-price-cryptopay.js +21 -0
- package/lib/pricing/product-price-cryptopay.js.map +1 -0
- package/lib/pricing/product-price-rateconversion.d.ts +1 -0
- package/lib/pricing/product-price-rateconversion.js +51 -0
- package/lib/pricing/product-price-rateconversion.js.map +1 -0
- package/lib/pricing/product-price-round.d.ts +11 -0
- package/lib/pricing/product-price-round.js +54 -0
- package/lib/pricing/product-price-round.js.map +1 -0
- package/lib/pricing/product-swiss-tax.d.ts +13 -0
- package/lib/pricing/product-swiss-tax.js +102 -0
- package/lib/pricing/product-swiss-tax.js.map +1 -0
- package/lib/pricing/utils/cache.d.ts +8 -0
- package/lib/pricing/utils/cache.js +28 -0
- package/lib/pricing/utils/cache.js.map +1 -0
- package/lib/quotations/manual.d.ts +1 -0
- package/lib/quotations/manual.js +21 -0
- package/lib/quotations/manual.js.map +1 -0
- package/lib/warehousing/google-sheets.d.ts +1 -0
- package/lib/warehousing/google-sheets.js +153 -0
- package/lib/warehousing/google-sheets.js.map +1 -0
- package/lib/warehousing/store.d.ts +1 -0
- package/lib/warehousing/store.js +33 -0
- package/lib/warehousing/store.js.map +1 -0
- package/lib/worker/BulkImportWorker.js +3 -3
- package/lib/worker/BulkImportWorker.js.map +1 -1
- package/lib/worker/GenerateOrderWorker.js +1 -1
- package/lib/worker/GenerateOrderWorker.js.map +1 -1
- package/lib/worker/ZombieKillerWorker.js.map +1 -1
- package/lib/worker/email.js +55 -4
- package/lib/worker/email.js.map +1 -1
- package/license +274 -0
- package/package.json +29 -12
- package/src/delivery/pick-mup.ts +119 -0
- package/src/delivery/post.ts +30 -0
- package/src/delivery/send-message.ts +54 -0
- package/src/delivery/stores.ts +49 -0
- package/src/enrollments/licensed.ts +49 -0
- package/src/files/gridfs/gridfs-adapter.ts +1 -1
- package/src/files/gridfs/gridfs-webhook.js +2 -2
- package/src/files/minio/minio-webhook.js +1 -1
- package/src/filters/local-search.ts +105 -0
- package/src/filters/strict-equal.ts +31 -0
- package/src/payment/apple-iap/adapter.ts +390 -0
- package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +13 -0
- package/src/payment/apple-iap/index.ts +3 -0
- package/src/payment/apple-iap/module/configureAppleTransactionsModule.ts +31 -0
- package/src/payment/bity/adapter.ts +417 -0
- package/src/payment/bity/db/BityCredentialsCollection.ts +17 -0
- package/src/payment/bity/index.ts +3 -0
- package/src/payment/bity/module/configureBityModule.ts +46 -0
- package/src/payment/braintree.ts +147 -0
- package/src/payment/cryptopay.ts +195 -0
- package/src/payment/datatrans-v2/api/authorize.ts +17 -0
- package/src/payment/datatrans-v2/api/authorizeAuthenticated.ts +20 -0
- package/src/payment/datatrans-v2/api/cancel.ts +13 -0
- package/src/payment/datatrans-v2/api/index.ts +24 -0
- package/src/payment/datatrans-v2/api/init.ts +40 -0
- package/src/payment/datatrans-v2/api/makeFetcher.ts +49 -0
- package/src/payment/datatrans-v2/api/secureFields.ts +19 -0
- package/src/payment/datatrans-v2/api/settle.ts +13 -0
- package/src/payment/datatrans-v2/api/status.ts +8 -0
- package/src/payment/datatrans-v2/api/types.d.ts +378 -0
- package/src/payment/datatrans-v2/api/validate.ts +13 -0
- package/src/payment/datatrans-v2/generateSignature.ts +24 -0
- package/src/payment/datatrans-v2/getPaths.ts +24 -0
- package/src/payment/datatrans-v2/index.ts +476 -0
- package/src/payment/datatrans-v2/middleware.ts +147 -0
- package/src/payment/datatrans-v2/parseRegistrationData.ts +32 -0
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +16 -0
- package/src/payment/datatrans-v2/splitProperties.ts +63 -0
- package/src/payment/invoice-prepaid.ts +40 -0
- package/src/payment/invoice.ts +36 -0
- package/src/payment/paypal-checkout.ts +107 -0
- package/src/payment/postfinance-checkout/api.ts +142 -0
- package/src/payment/postfinance-checkout/index.ts +241 -0
- package/src/payment/postfinance-checkout/middleware.ts +54 -0
- package/src/payment/postfinance-checkout/types.ts +27 -0
- package/src/payment/postfinance-checkout/utils.ts +35 -0
- package/src/payment/stripe.ts +278 -0
- package/src/payment/worldline-saferpay/index.ts +140 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.ts +54 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.ts +36 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/index.ts +8 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.ts +26 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.ts +75 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.ts +55 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Request.ts +14 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Response.ts +9 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.ts +6 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.ts +15 -0
- package/src/pricing/delivery-swiss-tax.ts +115 -0
- package/src/pricing/discount-100-off.ts +44 -0
- package/src/pricing/discount-half-price-manual.ts +43 -0
- package/src/pricing/discount-half-price.ts +46 -0
- package/src/pricing/free-delivery.ts +31 -0
- package/src/pricing/free-payment.ts +32 -0
- package/src/pricing/order-delivery.ts +45 -0
- package/src/pricing/order-discount.ts +158 -0
- package/src/pricing/order-items-discount.ts +116 -0
- package/src/pricing/order-items.ts +61 -0
- package/src/pricing/order-payment.ts +46 -0
- package/src/pricing/product-catalog-price.ts +56 -0
- package/src/pricing/product-discount.ts +69 -0
- package/src/pricing/product-price-ECB-interbank-exchange.ts +108 -0
- package/src/pricing/product-price-coinbase-exchange.ts +82 -0
- package/src/pricing/product-price-cryptopay.ts +25 -0
- package/src/pricing/product-price-rateconversion.ts +73 -0
- package/src/pricing/product-price-round.ts +78 -0
- package/src/pricing/product-swiss-tax.ts +117 -0
- package/src/pricing/utils/cache.js +32 -0
- package/src/quotations/manual.ts +27 -0
- package/src/warehousing/google-sheets.ts +165 -0
- package/src/warehousing/store.ts +47 -0
- package/src/worker/BulkImportWorker.ts +3 -3
- package/src/worker/GenerateOrderWorker.ts +1 -1
- package/src/worker/ZombieKillerWorker.ts +5 -5
- package/src/worker/email.ts +56 -4
- package/lib/worker/MessageWorker.d.ts +0 -10
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { IOrderPricingAdapter, OrderPricingRowCategory } from '@unchainedshop/types/orders.pricing';
|
|
2
|
+
import { OrderPricingDirector, OrderPricingAdapter } from '@unchainedshop/core-orders';
|
|
3
|
+
|
|
4
|
+
const resolveRatioAndTaxDivisorForPricingSheet = (pricing, total) => {
|
|
5
|
+
if (total === 0 || !pricing) {
|
|
6
|
+
return {
|
|
7
|
+
ratio: 1,
|
|
8
|
+
taxDivisor: 1,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const tax = pricing.taxSum();
|
|
12
|
+
const gross = pricing.gross();
|
|
13
|
+
return {
|
|
14
|
+
ratio: gross / total,
|
|
15
|
+
taxDivisor: gross / (gross - tax),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const resolveAmountAndTax = ({ ratio, taxDivisor }, amount) => {
|
|
20
|
+
const shareAmount = Number.isFinite(ratio) ? amount * ratio : 0;
|
|
21
|
+
const shareTaxAmount = Number.isFinite(taxDivisor) ? shareAmount - shareAmount / taxDivisor : 0;
|
|
22
|
+
return [shareAmount, shareTaxAmount];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const applyDiscountToMultipleShares = (shares, amount) => {
|
|
26
|
+
return shares.reduce(
|
|
27
|
+
([currentDiscountAmount, currentTaxAmount], share) => {
|
|
28
|
+
const [shareAmount, shareTaxAmount] = resolveAmountAndTax(share, amount);
|
|
29
|
+
return [currentDiscountAmount + shareAmount, currentTaxAmount + shareTaxAmount];
|
|
30
|
+
},
|
|
31
|
+
[0, 0],
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const calculateAmountToSplit = (configuration, amount) => {
|
|
36
|
+
const deductionAmount = configuration.rate
|
|
37
|
+
? amount * configuration.rate
|
|
38
|
+
: Math.min(configuration.fixedRate, amount);
|
|
39
|
+
|
|
40
|
+
return Math.max(0, deductionAmount - (configuration.alreadyDeducted || 0));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const OrderItemsDiscount: IOrderPricingAdapter = {
|
|
44
|
+
...OrderPricingAdapter,
|
|
45
|
+
|
|
46
|
+
key: 'shop.unchained.pricing.order-items-discount',
|
|
47
|
+
version: '1.0',
|
|
48
|
+
label: 'Apply Discounts on Total Value Of Goods',
|
|
49
|
+
orderIndex: 89,
|
|
50
|
+
|
|
51
|
+
isActivatedFor: () => {
|
|
52
|
+
return true;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
actions: (params) => {
|
|
56
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
57
|
+
const { order, orderPositions, modules } = params.context;
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
...pricingAdapter,
|
|
61
|
+
|
|
62
|
+
calculate: async () => {
|
|
63
|
+
// discounts need to provide a *fixedRate*
|
|
64
|
+
// if you want to add percentual discounts,
|
|
65
|
+
// add it to the order item calculation
|
|
66
|
+
|
|
67
|
+
const totalAmountOfItems = params.calculationSheet.sum({
|
|
68
|
+
category: OrderPricingRowCategory.Items,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const itemShares = orderPositions.map((orderPosition) =>
|
|
72
|
+
resolveRatioAndTaxDivisorForPricingSheet(
|
|
73
|
+
modules.orders.positions.pricingSheet(orderPosition, order.currency, params.context),
|
|
74
|
+
totalAmountOfItems,
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
let alreadyDeducted = 0;
|
|
79
|
+
|
|
80
|
+
params.discounts.forEach(({ configuration, discountId }) => {
|
|
81
|
+
// First, we deduce the discount from the items
|
|
82
|
+
const [itemsDiscountAmount, itemsTaxAmount] = applyDiscountToMultipleShares(
|
|
83
|
+
itemShares,
|
|
84
|
+
calculateAmountToSplit({ ...configuration, alreadyDeducted }, totalAmountOfItems),
|
|
85
|
+
);
|
|
86
|
+
alreadyDeducted = +itemsDiscountAmount;
|
|
87
|
+
|
|
88
|
+
const discountAmount = itemsDiscountAmount;
|
|
89
|
+
const taxAmount = itemsTaxAmount;
|
|
90
|
+
if (discountAmount) {
|
|
91
|
+
pricingAdapter.resultSheet().addDiscount({
|
|
92
|
+
amount: discountAmount * -1,
|
|
93
|
+
discountId,
|
|
94
|
+
meta: {
|
|
95
|
+
adapter: OrderItemsDiscount.key,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
if (taxAmount !== 0) {
|
|
99
|
+
pricingAdapter.resultSheet().addTax({
|
|
100
|
+
amount: taxAmount * -1,
|
|
101
|
+
meta: {
|
|
102
|
+
discountId,
|
|
103
|
+
adapter: OrderItemsDiscount.key,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return pricingAdapter.calculate();
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
OrderPricingDirector.registerAdapter(OrderItemsDiscount);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { IOrderPricingAdapter } from '@unchainedshop/types/orders.pricing';
|
|
2
|
+
import { OrderPricingDirector, OrderPricingAdapter } from '@unchainedshop/core-orders';
|
|
3
|
+
|
|
4
|
+
const OrderItems: IOrderPricingAdapter = {
|
|
5
|
+
...OrderPricingAdapter,
|
|
6
|
+
|
|
7
|
+
key: 'shop.unchained.pricing.order-items',
|
|
8
|
+
version: '1.0',
|
|
9
|
+
label: 'Add Total Value Of Goods to Order',
|
|
10
|
+
orderIndex: 0,
|
|
11
|
+
|
|
12
|
+
isActivatedFor: () => {
|
|
13
|
+
return true;
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
actions: (params) => {
|
|
17
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
18
|
+
const { order, orderPositions, modules } = params.context;
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
...pricingAdapter,
|
|
22
|
+
|
|
23
|
+
calculate: async () => {
|
|
24
|
+
// just sum up all products items prices, taxes & fees
|
|
25
|
+
const totalAndTaxesOfAllItems = orderPositions.reduce(
|
|
26
|
+
(current, orderPosition) => {
|
|
27
|
+
const pricing = modules.orders.positions.pricingSheet(
|
|
28
|
+
orderPosition,
|
|
29
|
+
order.currency,
|
|
30
|
+
params.context,
|
|
31
|
+
);
|
|
32
|
+
const tax = pricing.taxSum();
|
|
33
|
+
const items = pricing.gross();
|
|
34
|
+
return {
|
|
35
|
+
taxes: current.taxes + tax,
|
|
36
|
+
items: current.items + items,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
taxes: 0,
|
|
41
|
+
items: 0,
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
pricingAdapter.resultSheet().addItems({
|
|
46
|
+
amount: totalAndTaxesOfAllItems.items,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (totalAndTaxesOfAllItems.taxes !== 0) {
|
|
50
|
+
pricingAdapter.resultSheet().addTax({
|
|
51
|
+
amount: totalAndTaxesOfAllItems.taxes,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return pricingAdapter.calculate();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
OrderPricingDirector.registerAdapter(OrderItems);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { IOrderPricingAdapter } from '@unchainedshop/types/orders.pricing';
|
|
2
|
+
import { OrderPricingDirector, OrderPricingAdapter } from '@unchainedshop/core-orders';
|
|
3
|
+
|
|
4
|
+
const OrderPayment: IOrderPricingAdapter = {
|
|
5
|
+
...OrderPricingAdapter,
|
|
6
|
+
|
|
7
|
+
key: 'shop.unchained.pricing.order-payment',
|
|
8
|
+
version: '1.0',
|
|
9
|
+
label: 'Add Payment Fees to Order',
|
|
10
|
+
orderIndex: 20,
|
|
11
|
+
|
|
12
|
+
isActivatedFor: () => {
|
|
13
|
+
return true;
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
actions: (params) => {
|
|
17
|
+
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
18
|
+
const { order, orderPayment, modules } = params.context;
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
...pricingAdapter,
|
|
22
|
+
|
|
23
|
+
calculate: async () => {
|
|
24
|
+
// just add tax + net price to order pricing
|
|
25
|
+
if (!orderPayment) return null;
|
|
26
|
+
|
|
27
|
+
const pricing = modules.orders.payments.pricingSheet(
|
|
28
|
+
orderPayment,
|
|
29
|
+
order.currency,
|
|
30
|
+
params.context,
|
|
31
|
+
);
|
|
32
|
+
const tax = pricing.taxSum();
|
|
33
|
+
const paymentFees = pricing.gross();
|
|
34
|
+
|
|
35
|
+
pricingAdapter.resultSheet().addPayment({ amount: paymentFees });
|
|
36
|
+
if (tax !== 0) {
|
|
37
|
+
pricingAdapter.resultSheet().addTax({ amount: tax });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return pricingAdapter.calculate();
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
OrderPricingDirector.registerAdapter(OrderPayment);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
|
|
2
|
+
import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
|
|
3
|
+
|
|
4
|
+
const ProductPrice: IProductPricingAdapter = {
|
|
5
|
+
...ProductPricingAdapter,
|
|
6
|
+
|
|
7
|
+
key: 'shop.unchained.pricing.product-price',
|
|
8
|
+
version: '1.0',
|
|
9
|
+
label: 'Add Gross Price to Product',
|
|
10
|
+
orderIndex: 0,
|
|
11
|
+
|
|
12
|
+
isActivatedFor: () => {
|
|
13
|
+
return true;
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
actions: (params) => {
|
|
17
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
...pricingAdapter,
|
|
21
|
+
|
|
22
|
+
calculate: async () => {
|
|
23
|
+
const {
|
|
24
|
+
product,
|
|
25
|
+
country,
|
|
26
|
+
currency: forcedCurrency,
|
|
27
|
+
quantity,
|
|
28
|
+
modules,
|
|
29
|
+
services,
|
|
30
|
+
} = params.context;
|
|
31
|
+
const currency =
|
|
32
|
+
forcedCurrency ||
|
|
33
|
+
(await services.countries.resolveDefaultCurrencyCode(
|
|
34
|
+
{
|
|
35
|
+
isoCode: country,
|
|
36
|
+
},
|
|
37
|
+
params.context,
|
|
38
|
+
));
|
|
39
|
+
const price = await modules.products.prices.price(product, { country, currency, quantity });
|
|
40
|
+
if (price) {
|
|
41
|
+
const itemTotal = price.amount * quantity;
|
|
42
|
+
pricingAdapter.resultSheet().addItem({
|
|
43
|
+
amount: itemTotal,
|
|
44
|
+
isTaxable: price.isTaxable,
|
|
45
|
+
isNetPrice: price.isNetPrice,
|
|
46
|
+
meta: { adapter: ProductPrice.key },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return pricingAdapter.calculate();
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
ProductPricingDirector.registerAdapter(ProductPrice);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Discount, DiscountConfiguration } from '@unchainedshop/types/discount';
|
|
2
|
+
import {
|
|
3
|
+
IProductPricingAdapter,
|
|
4
|
+
ProductPricingRowCategory,
|
|
5
|
+
} from '@unchainedshop/types/products.pricing';
|
|
6
|
+
import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
|
|
7
|
+
|
|
8
|
+
const applyRate = (configuration: DiscountConfiguration, amount) => {
|
|
9
|
+
const { rate, fixedRate } = configuration;
|
|
10
|
+
return rate ? amount * rate : Math.min(fixedRate, amount);
|
|
11
|
+
};
|
|
12
|
+
const ProductDiscount: IProductPricingAdapter = {
|
|
13
|
+
...ProductPricingAdapter,
|
|
14
|
+
|
|
15
|
+
key: 'shop.unchained.pricing.product-discount',
|
|
16
|
+
version: '1.0',
|
|
17
|
+
label: 'Apply Discounts on Product Price',
|
|
18
|
+
orderIndex: 10,
|
|
19
|
+
|
|
20
|
+
isActivatedFor: () => {
|
|
21
|
+
return true;
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
actions: (params) => {
|
|
25
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
26
|
+
|
|
27
|
+
const addDiscount = (discount: Discount, total: number, isTaxable: boolean) => {
|
|
28
|
+
const { configuration, discountId } = discount;
|
|
29
|
+
const { isNetPrice = false, ...meta } = configuration;
|
|
30
|
+
const amount = applyRate(configuration, total);
|
|
31
|
+
|
|
32
|
+
pricingAdapter.resultSheet().addDiscount({
|
|
33
|
+
amount: amount * -1,
|
|
34
|
+
discountId,
|
|
35
|
+
isNetPrice,
|
|
36
|
+
isTaxable,
|
|
37
|
+
meta: { adapter: ProductDiscount.key, ...meta },
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
...pricingAdapter,
|
|
43
|
+
|
|
44
|
+
calculate: async () => {
|
|
45
|
+
const taxableTotal = params.calculationSheet.sum({
|
|
46
|
+
category: ProductPricingRowCategory.Item,
|
|
47
|
+
isTaxable: true,
|
|
48
|
+
});
|
|
49
|
+
const nonTaxableTotal = params.calculationSheet.sum({
|
|
50
|
+
category: ProductPricingRowCategory.Item,
|
|
51
|
+
isTaxable: false,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
params.discounts.forEach((discount) => {
|
|
55
|
+
if (taxableTotal !== 0) {
|
|
56
|
+
addDiscount(discount, taxableTotal, true);
|
|
57
|
+
}
|
|
58
|
+
if (nonTaxableTotal !== 0) {
|
|
59
|
+
addDiscount(discount, nonTaxableTotal, false);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return pricingAdapter.calculate();
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
ProductPricingDirector.registerAdapter(ProductDiscount);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
|
|
2
|
+
import fetch from 'isomorphic-unfetch';
|
|
3
|
+
import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
|
|
4
|
+
|
|
5
|
+
import Cache from './utils/cache';
|
|
6
|
+
|
|
7
|
+
const CACHE_PERIOD = 60 * 60 * 24; // 1 day
|
|
8
|
+
|
|
9
|
+
const SUPPORTED_CURRENCIES = [
|
|
10
|
+
'USD',
|
|
11
|
+
'JPY',
|
|
12
|
+
'BGN',
|
|
13
|
+
'CZK',
|
|
14
|
+
'DKK',
|
|
15
|
+
'GBP',
|
|
16
|
+
'HUF',
|
|
17
|
+
'PLN',
|
|
18
|
+
'RON',
|
|
19
|
+
'SEK',
|
|
20
|
+
'CHF',
|
|
21
|
+
'ISK',
|
|
22
|
+
'NOK',
|
|
23
|
+
'HRK',
|
|
24
|
+
'RUB',
|
|
25
|
+
'TRY',
|
|
26
|
+
'AUD',
|
|
27
|
+
'BRL',
|
|
28
|
+
'CAD',
|
|
29
|
+
'CNY',
|
|
30
|
+
'HKD',
|
|
31
|
+
'IDR',
|
|
32
|
+
'ILS',
|
|
33
|
+
'INR',
|
|
34
|
+
'KRW',
|
|
35
|
+
'MXN',
|
|
36
|
+
'MYR',
|
|
37
|
+
'NZD',
|
|
38
|
+
'PHP',
|
|
39
|
+
'SGD',
|
|
40
|
+
'THB',
|
|
41
|
+
'ZAR',
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const cache = new Cache(CACHE_PERIOD);
|
|
45
|
+
const xmlJs = require('xml-js'); // eslint-disable-line
|
|
46
|
+
|
|
47
|
+
const getEURexchangeRateForCurrency = async (currency) => {
|
|
48
|
+
const response = cache.get(currency, () =>
|
|
49
|
+
fetch(`https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml`, {
|
|
50
|
+
method: 'GET',
|
|
51
|
+
})
|
|
52
|
+
.then((res) => res.text())
|
|
53
|
+
.then((text) => JSON.parse(xmlJs.xml2json(text)))
|
|
54
|
+
.then(
|
|
55
|
+
(json) =>
|
|
56
|
+
json.elements?.[0]?.elements
|
|
57
|
+
.filter((e) => e.name.toLowerCase() === 'cube')[0]
|
|
58
|
+
?.elements[0]?.elements.filter((a) => a.attributes.currency === currency)?.[0]?.attributes,
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
return response;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const ProductPriceECBIntraBankExchange: IProductPricingAdapter = {
|
|
65
|
+
...ProductPricingAdapter,
|
|
66
|
+
|
|
67
|
+
key: 'shop.unchained.pricing.price-ECB-intrabank-exchange',
|
|
68
|
+
version: '1.0',
|
|
69
|
+
label: 'Convert EUR to X with current exchange rate',
|
|
70
|
+
orderIndex: 1,
|
|
71
|
+
|
|
72
|
+
isActivatedFor: (context) => {
|
|
73
|
+
return SUPPORTED_CURRENCIES.indexOf(context.currency) !== -1;
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
actions: (params) => {
|
|
77
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
...pricingAdapter,
|
|
81
|
+
|
|
82
|
+
calculate: async () => {
|
|
83
|
+
const { product, country, quantity, currency, modules } = params.context;
|
|
84
|
+
const { calculation = [] } = params.calculationSheet;
|
|
85
|
+
const EURprice = await modules.products.prices.price(product, {
|
|
86
|
+
country,
|
|
87
|
+
currency: 'EUR',
|
|
88
|
+
quantity,
|
|
89
|
+
});
|
|
90
|
+
if (!EURprice || !EURprice?.amount || calculation?.length) return pricingAdapter.calculate();
|
|
91
|
+
|
|
92
|
+
const exchange = await getEURexchangeRateForCurrency(currency);
|
|
93
|
+
const convertedAmount = EURprice.amount * exchange.rate;
|
|
94
|
+
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
95
|
+
pricingAdapter.resultSheet().addItem({
|
|
96
|
+
amount: convertedAmount * quantity,
|
|
97
|
+
isTaxable: EURprice.isTaxable,
|
|
98
|
+
isNetPrice: EURprice.isNetPrice,
|
|
99
|
+
meta: { adapter: ProductPriceECBIntraBankExchange.key },
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return pricingAdapter.calculate();
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
ProductPricingDirector.registerAdapter(ProductPriceECBIntraBankExchange);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
|
|
2
|
+
import fetch from 'isomorphic-unfetch';
|
|
3
|
+
import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
|
|
4
|
+
|
|
5
|
+
import Cache from './utils/cache';
|
|
6
|
+
|
|
7
|
+
const CACHE_PERIOD = 60 * 60 * 0.1; // 10 minutes
|
|
8
|
+
const SUPPORTED_CURRENCIES = ['BTC', 'ETH', 'XRP', 'USDT', 'BCH', 'BSV', 'LTC', 'EOS', 'BNB', 'XTZ'];
|
|
9
|
+
const cache = new Cache(CACHE_PERIOD);
|
|
10
|
+
|
|
11
|
+
const getFiatexchangeRateForCrypto = async (base, target) => {
|
|
12
|
+
const { data } = await cache.get(`${base}-${target}`, () =>
|
|
13
|
+
fetch(`https://api.coinbase.com/v2/exchange-rates?currency=${base}`, {
|
|
14
|
+
method: 'GET',
|
|
15
|
+
}).then((res) => res.json()),
|
|
16
|
+
);
|
|
17
|
+
return data?.rates?.[target];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const ProductPriceCoinbaseExchange: IProductPricingAdapter = {
|
|
21
|
+
...ProductPricingAdapter,
|
|
22
|
+
|
|
23
|
+
key: 'shop.unchained.pricing.price-coinbase-exchange',
|
|
24
|
+
version: '1.0',
|
|
25
|
+
label: 'Convert fiat/crypto to crypto with current exchange rate',
|
|
26
|
+
orderIndex: 1,
|
|
27
|
+
|
|
28
|
+
isActivatedFor: (context) => {
|
|
29
|
+
return SUPPORTED_CURRENCIES.indexOf(context.currency.toUpperCase()) !== -1;
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
actions: (params) => {
|
|
33
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
34
|
+
const { services, modules } = params.context;
|
|
35
|
+
return {
|
|
36
|
+
...pricingAdapter,
|
|
37
|
+
|
|
38
|
+
calculate: async () => {
|
|
39
|
+
const { product, country, quantity, currency } = params.context;
|
|
40
|
+
const defaultCurrency = await services.countries.resolveDefaultCurrencyCode(
|
|
41
|
+
{
|
|
42
|
+
isoCode: country,
|
|
43
|
+
},
|
|
44
|
+
params.context,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const productPrice = await modules.products.prices.price(product, {
|
|
48
|
+
country,
|
|
49
|
+
currency: defaultCurrency,
|
|
50
|
+
quantity,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const { calculation = [] } = params.calculationSheet;
|
|
54
|
+
|
|
55
|
+
if (
|
|
56
|
+
!productPrice ||
|
|
57
|
+
!productPrice?.amount ||
|
|
58
|
+
calculation?.length ||
|
|
59
|
+
defaultCurrency === currency
|
|
60
|
+
)
|
|
61
|
+
return pricingAdapter.calculate();
|
|
62
|
+
|
|
63
|
+
const rate = await getFiatexchangeRateForCrypto(defaultCurrency, currency);
|
|
64
|
+
|
|
65
|
+
if (rate > 0) {
|
|
66
|
+
const convertedAmount = productPrice.amount * rate;
|
|
67
|
+
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
68
|
+
pricingAdapter.resultSheet().addItem({
|
|
69
|
+
amount: convertedAmount * quantity,
|
|
70
|
+
isTaxable: productPrice?.isTaxable,
|
|
71
|
+
isNetPrice: productPrice?.isNetPrice,
|
|
72
|
+
meta: { adapter: ProductPriceCoinbaseExchange.key },
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return pricingAdapter.calculate();
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
ProductPricingDirector.registerAdapter(ProductPriceCoinbaseExchange);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Context } from '@unchainedshop/types/api';
|
|
2
|
+
import { ProductPriceRate } from '@unchainedshop/types/products.pricing';
|
|
3
|
+
import bodyParser from 'body-parser';
|
|
4
|
+
import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
|
|
5
|
+
|
|
6
|
+
const { CRYPTOPAY_SECRET, CRYPTOPAY_PRICING_WEBHOOK_PATH = '/graphql/cryptopay-pricing' } = process.env;
|
|
7
|
+
|
|
8
|
+
useMiddlewareWithCurrentContext(CRYPTOPAY_PRICING_WEBHOOK_PATH, bodyParser.json());
|
|
9
|
+
|
|
10
|
+
useMiddlewareWithCurrentContext(CRYPTOPAY_PRICING_WEBHOOK_PATH, async (request, response) => {
|
|
11
|
+
const resolvedContext = request.unchainedContext as Context;
|
|
12
|
+
const { baseCurrency, token, rate, timestamp, secret } = request.body;
|
|
13
|
+
if (secret !== CRYPTOPAY_SECRET) {
|
|
14
|
+
response.end(JSON.stringify({ success: false }));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const rateData: ProductPriceRate = {
|
|
18
|
+
baseCurrency,
|
|
19
|
+
quoteCurrency: token,
|
|
20
|
+
rate,
|
|
21
|
+
timestamp,
|
|
22
|
+
};
|
|
23
|
+
const success = await resolvedContext.modules.products.prices.rates.updateRate(rateData);
|
|
24
|
+
response.end(JSON.stringify({ success }));
|
|
25
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
|
|
2
|
+
import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
|
|
3
|
+
|
|
4
|
+
const { RATECONVERSION_MAX_AGE = '360' } = process.env;
|
|
5
|
+
|
|
6
|
+
const MAX_RATE_AGE = parseInt(RATECONVERSION_MAX_AGE, 10);
|
|
7
|
+
|
|
8
|
+
const ProductPriceRateConversion: IProductPricingAdapter = {
|
|
9
|
+
...ProductPricingAdapter,
|
|
10
|
+
|
|
11
|
+
key: 'shop.unchained.pricing.rate-conversion',
|
|
12
|
+
version: '1.0',
|
|
13
|
+
label: 'Generic rate conversion plugin that converts between rates if entry in DB exists.',
|
|
14
|
+
orderIndex: 1,
|
|
15
|
+
|
|
16
|
+
isActivatedFor: () => {
|
|
17
|
+
return true;
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
actions: (params) => {
|
|
21
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
22
|
+
const { services, modules } = params.context;
|
|
23
|
+
return {
|
|
24
|
+
...pricingAdapter,
|
|
25
|
+
|
|
26
|
+
calculate: async () => {
|
|
27
|
+
const { product, country, quantity, currency } = params.context;
|
|
28
|
+
const defaultCurrency = await services.countries.resolveDefaultCurrencyCode(
|
|
29
|
+
{
|
|
30
|
+
isoCode: country,
|
|
31
|
+
},
|
|
32
|
+
params.context,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const productPrice = await modules.products.prices.price(product, {
|
|
36
|
+
country,
|
|
37
|
+
currency: defaultCurrency,
|
|
38
|
+
quantity,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const { calculation = [] } = params.calculationSheet;
|
|
42
|
+
if (
|
|
43
|
+
!productPrice ||
|
|
44
|
+
!productPrice?.amount ||
|
|
45
|
+
calculation?.length ||
|
|
46
|
+
defaultCurrency === currency
|
|
47
|
+
)
|
|
48
|
+
return pricingAdapter.calculate();
|
|
49
|
+
|
|
50
|
+
const rate = await modules.products.prices.rates.getRate(
|
|
51
|
+
defaultCurrency,
|
|
52
|
+
currency,
|
|
53
|
+
MAX_RATE_AGE,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
if (rate > 0) {
|
|
57
|
+
const convertedAmount = productPrice.amount * rate;
|
|
58
|
+
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
59
|
+
pricingAdapter.resultSheet().addItem({
|
|
60
|
+
amount: convertedAmount * quantity,
|
|
61
|
+
isTaxable: productPrice?.isTaxable,
|
|
62
|
+
isNetPrice: productPrice?.isNetPrice,
|
|
63
|
+
meta: { adapter: ProductPriceRateConversion.key },
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return pricingAdapter.calculate();
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
ProductPricingDirector.registerAdapter(ProductPriceRateConversion);
|