@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,195 @@
|
|
|
1
|
+
import { Context } from '@unchainedshop/types/api';
|
|
2
|
+
import { IPaymentAdapter } from '@unchainedshop/types/payments';
|
|
3
|
+
import bodyParser from 'body-parser';
|
|
4
|
+
import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
|
|
5
|
+
import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment';
|
|
6
|
+
import { OrderPricingSheet } from '@unchainedshop/core-orders';
|
|
7
|
+
import { ethers } from 'ethers';
|
|
8
|
+
import BIP32Factory from 'bip32';
|
|
9
|
+
import * as ecc from 'tiny-secp256k1';
|
|
10
|
+
import * as bitcoin from 'bitcoinjs-lib';
|
|
11
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
12
|
+
|
|
13
|
+
const logger = createLogger('unchained:core-payment:cryptopay');
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
CRYPTOPAY_SECRET,
|
|
17
|
+
CRYPTOPAY_WEBHOOK_PATH = '/graphql/cryptopay',
|
|
18
|
+
CRYPTOPAY_BTC_XPUB,
|
|
19
|
+
CRYPTOPAY_ETH_XPUB,
|
|
20
|
+
CRYPTOPAY_BTC_TESTNET = false,
|
|
21
|
+
CRYPTOPAY_MAX_RATE_AGE = '360', // seconds
|
|
22
|
+
CRYPTOPAY_MAX_CONV_DIFF = '0.01',
|
|
23
|
+
} = process.env;
|
|
24
|
+
|
|
25
|
+
enum CryptopayCurrencies { // eslint-disable-line
|
|
26
|
+
BTC = 'BTC',
|
|
27
|
+
ETH = 'ETH',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const MAX_RATE_AGE = parseInt(CRYPTOPAY_MAX_RATE_AGE, 10);
|
|
31
|
+
const MAX_ALLOWED_DIFF = parseFloat(CRYPTOPAY_MAX_CONV_DIFF); // Accept payments when the converted amount differs by adapterActions much (in percent)
|
|
32
|
+
|
|
33
|
+
useMiddlewareWithCurrentContext(CRYPTOPAY_WEBHOOK_PATH, bodyParser.json());
|
|
34
|
+
|
|
35
|
+
useMiddlewareWithCurrentContext(CRYPTOPAY_WEBHOOK_PATH, async (request, response) => {
|
|
36
|
+
// Return a 200 response to acknowledge receipt of the event
|
|
37
|
+
const resolvedContext = request.unchainedContext as Context;
|
|
38
|
+
const { currency, contract, decimals, address, amount, secret } = request.body;
|
|
39
|
+
if (secret !== CRYPTOPAY_SECRET) {
|
|
40
|
+
logger.warn(`Cryptopay Plugin: Invalid Cryptopay Secret provided`);
|
|
41
|
+
response.end(JSON.stringify({ success: false }));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const orderPayment = await resolvedContext.modules.orders.payments.findOrderPaymentByContextData({
|
|
45
|
+
context: { currency, address },
|
|
46
|
+
});
|
|
47
|
+
if (orderPayment) {
|
|
48
|
+
if (currency === CryptopayCurrencies.ETH && contract && contract !== '') {
|
|
49
|
+
const ERC20CurrencyCount = await resolvedContext.modules.currencies.count({
|
|
50
|
+
includeInactive: false,
|
|
51
|
+
contractAddress: contract,
|
|
52
|
+
});
|
|
53
|
+
if (!ERC20CurrencyCount) {
|
|
54
|
+
logger.warn(`Cryptopay Plugin: ERC20 token address ${contract} not whitelisted.`);
|
|
55
|
+
response.end(JSON.stringify({ success: false }));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const order = await resolvedContext.modules.orders.findOrder({
|
|
60
|
+
orderId: orderPayment.orderId,
|
|
61
|
+
});
|
|
62
|
+
const pricing = OrderPricingSheet({
|
|
63
|
+
calculation: order.calculation,
|
|
64
|
+
currency: order.currency,
|
|
65
|
+
});
|
|
66
|
+
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
67
|
+
let convertedAmount: number;
|
|
68
|
+
if (order.currency === currency) {
|
|
69
|
+
convertedAmount = amount / 10 ** (decimals - 8); // All crypto native prices denoted with 8 decimals
|
|
70
|
+
} else {
|
|
71
|
+
// Need to convert
|
|
72
|
+
const rate = await resolvedContext.modules.products.prices.rates.getRate(
|
|
73
|
+
order.currency,
|
|
74
|
+
contract && contract !== '' ? contract : currency, // Convert to the smart contract if given
|
|
75
|
+
MAX_RATE_AGE,
|
|
76
|
+
);
|
|
77
|
+
if (rate) {
|
|
78
|
+
// We assume that we are converting to a fiat currency here (with 2 decimals).
|
|
79
|
+
// Paying an order with prices in crypto in another crypto is not supported.
|
|
80
|
+
convertedAmount = Math.round((amount / 10 ** decimals) * rate * 100);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (convertedAmount && convertedAmount >= totalAmount * (1 - MAX_ALLOWED_DIFF)) {
|
|
84
|
+
await resolvedContext.modules.orders.checkout(
|
|
85
|
+
order._id,
|
|
86
|
+
{
|
|
87
|
+
transactionContext: { address },
|
|
88
|
+
paymentContext: { address },
|
|
89
|
+
},
|
|
90
|
+
resolvedContext,
|
|
91
|
+
);
|
|
92
|
+
response.end(JSON.stringify({ success: true }));
|
|
93
|
+
} else {
|
|
94
|
+
logger.warn(
|
|
95
|
+
`Cryptopay Plugin: OrderPayment ${orderPayment._id} not marked as paid. Converted amount is ${convertedAmount}`,
|
|
96
|
+
);
|
|
97
|
+
response.end(JSON.stringify({ success: false }));
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
logger.info(
|
|
101
|
+
`Cryptopay Plugin: No orderPayment with address ${address} and currency ${currency} found`,
|
|
102
|
+
);
|
|
103
|
+
response.end(JSON.stringify({ success: false }));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const Cryptopay: IPaymentAdapter = {
|
|
108
|
+
...PaymentAdapter,
|
|
109
|
+
|
|
110
|
+
key: 'shop.unchained.payment.cryptopay',
|
|
111
|
+
label: 'Cryptopay',
|
|
112
|
+
version: '1.0',
|
|
113
|
+
|
|
114
|
+
typeSupported(type) {
|
|
115
|
+
return type === 'GENERIC';
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
actions: (params) => {
|
|
119
|
+
const { modules } = params.context;
|
|
120
|
+
|
|
121
|
+
const adapterActions = {
|
|
122
|
+
...PaymentAdapter.actions(params),
|
|
123
|
+
|
|
124
|
+
// eslint-disable-next-line
|
|
125
|
+
configurationError() {
|
|
126
|
+
// eslint-disable-line
|
|
127
|
+
if (!CRYPTOPAY_SECRET) {
|
|
128
|
+
return PaymentError.INCOMPLETE_CONFIGURATION;
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
isActive() {
|
|
134
|
+
if (adapterActions.configurationError() === null) return true;
|
|
135
|
+
return false;
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
isPayLaterAllowed() {
|
|
139
|
+
return false;
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
sign: async () => {
|
|
143
|
+
const { orderPayment } = params.paymentContext;
|
|
144
|
+
if (orderPayment?.context.length) {
|
|
145
|
+
// Do not derive address a second time for order payment, return existing address
|
|
146
|
+
const existingAddresses = orderPayment.context.filter((c) => c.currency);
|
|
147
|
+
if (existingAddresses) {
|
|
148
|
+
return JSON.stringify(existingAddresses);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const cryptoAddresses: { currency: CryptopayCurrencies; address: string }[] = [];
|
|
152
|
+
if (CRYPTOPAY_BTC_XPUB) {
|
|
153
|
+
const network = CRYPTOPAY_BTC_TESTNET ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
|
|
154
|
+
const bip32 = BIP32Factory(ecc);
|
|
155
|
+
const hardenedMaster = bip32.fromBase58(CRYPTOPAY_BTC_XPUB, network);
|
|
156
|
+
const btcDerivationNumber = await modules.orders.payments.countOrderPaymentsByContextData({
|
|
157
|
+
context: { currency: CryptopayCurrencies.BTC },
|
|
158
|
+
});
|
|
159
|
+
const child = hardenedMaster.derivePath(`0/${btcDerivationNumber}`);
|
|
160
|
+
cryptoAddresses.push({
|
|
161
|
+
currency: CryptopayCurrencies.BTC,
|
|
162
|
+
address: bitcoin.payments.p2pkh({
|
|
163
|
+
pubkey: child.publicKey,
|
|
164
|
+
network,
|
|
165
|
+
}).address,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (CRYPTOPAY_ETH_XPUB) {
|
|
169
|
+
const hardenedMaster = ethers.utils.HDNode.fromExtendedKey(CRYPTOPAY_ETH_XPUB);
|
|
170
|
+
const ethDerivationNumber = await modules.orders.payments.countOrderPaymentsByContextData({
|
|
171
|
+
context: { currency: CryptopayCurrencies.ETH },
|
|
172
|
+
});
|
|
173
|
+
cryptoAddresses.push({
|
|
174
|
+
currency: CryptopayCurrencies.ETH,
|
|
175
|
+
address: hardenedMaster.derivePath(`0/${ethDerivationNumber}`).address,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
await modules.orders.payments.updateContext(
|
|
179
|
+
orderPayment._id,
|
|
180
|
+
{ cryptoAddresses },
|
|
181
|
+
params.context,
|
|
182
|
+
);
|
|
183
|
+
return JSON.stringify(cryptoAddresses);
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
charge: async () => {
|
|
187
|
+
return false;
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
return adapterActions;
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
PaymentDirector.registerAdapter(Cryptopay);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// https://api-reference.datatrans.ch/#operation/Authorize
|
|
2
|
+
|
|
3
|
+
import type { FetchDatatransFn, AuthorizeRequestPayload, AuthorizeResponse } from './types';
|
|
4
|
+
|
|
5
|
+
export default async function authorize({
|
|
6
|
+
...payload
|
|
7
|
+
}: AuthorizeRequestPayload): Promise<AuthorizeResponse> {
|
|
8
|
+
const reqBody = {
|
|
9
|
+
...payload,
|
|
10
|
+
autoSettle: false,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const { fetchDatatrans }: { fetchDatatrans: FetchDatatransFn } = this;
|
|
14
|
+
const result = await fetchDatatrans('/v1/transactions/authorize', reqBody);
|
|
15
|
+
const json = await result.json();
|
|
16
|
+
return json;
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FetchDatatransFn,
|
|
3
|
+
AuthorizeAuthenticatedRequestPayload,
|
|
4
|
+
AuthorizeAuthenticatedResponse,
|
|
5
|
+
} from './types';
|
|
6
|
+
|
|
7
|
+
export default async function authorizeAuthenticated({
|
|
8
|
+
transactionId,
|
|
9
|
+
...payload
|
|
10
|
+
}: AuthorizeAuthenticatedRequestPayload): Promise<AuthorizeAuthenticatedResponse> {
|
|
11
|
+
const reqBody = {
|
|
12
|
+
...payload,
|
|
13
|
+
autoSettle: false,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const { fetchDatatrans }: { fetchDatatrans: FetchDatatransFn } = this;
|
|
17
|
+
const result = await fetchDatatrans(`/v1/transactions/${transactionId}/authorize`, reqBody);
|
|
18
|
+
const json = await result.json();
|
|
19
|
+
return json;
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FetchDatatransFn, CancelRequestPayload, CancelResponse } from './types';
|
|
2
|
+
|
|
3
|
+
export default async function cancel({
|
|
4
|
+
transactionId,
|
|
5
|
+
...payload
|
|
6
|
+
}: CancelRequestPayload): Promise<CancelResponse> {
|
|
7
|
+
const reqBody = payload;
|
|
8
|
+
const { fetchDatatrans }: { fetchDatatrans: FetchDatatransFn } = this;
|
|
9
|
+
const result = await fetchDatatrans(`/v1/transactions/${transactionId}/cancel`, reqBody);
|
|
10
|
+
if (result.status === 204) return true;
|
|
11
|
+
const json = await result.json();
|
|
12
|
+
return json;
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import makeFetcher from './makeFetcher';
|
|
2
|
+
import status from './status';
|
|
3
|
+
import init from './init';
|
|
4
|
+
import secureFields from './secureFields';
|
|
5
|
+
import authorize from './authorize';
|
|
6
|
+
import validate from './validate';
|
|
7
|
+
import settle from './settle';
|
|
8
|
+
import cancel from './cancel';
|
|
9
|
+
import authorizeAuthenticated from './authorizeAuthenticated';
|
|
10
|
+
|
|
11
|
+
export default function createDatatransAPI(endpoint: string, merchantId: string, secret: string) {
|
|
12
|
+
const fetchDatatrans = makeFetcher(endpoint, merchantId, secret);
|
|
13
|
+
return {
|
|
14
|
+
fetchDatatrans,
|
|
15
|
+
init,
|
|
16
|
+
authorize,
|
|
17
|
+
validate,
|
|
18
|
+
secureFields,
|
|
19
|
+
status,
|
|
20
|
+
authorizeAuthenticated,
|
|
21
|
+
settle,
|
|
22
|
+
cancel,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// https://api-reference.datatrans.ch/#operation/init
|
|
2
|
+
import getPaths from '../getPaths';
|
|
3
|
+
|
|
4
|
+
import type { FetchDatatransFn, InitRequestPayload, InitResponse } from './types';
|
|
5
|
+
|
|
6
|
+
const defaultRedirect = getPaths();
|
|
7
|
+
|
|
8
|
+
export default async function init({
|
|
9
|
+
option,
|
|
10
|
+
redirect: userRedirect,
|
|
11
|
+
...payload
|
|
12
|
+
}: InitRequestPayload): Promise<InitResponse> {
|
|
13
|
+
const redirect = {
|
|
14
|
+
...defaultRedirect,
|
|
15
|
+
...(userRedirect || {}),
|
|
16
|
+
} as Partial<typeof defaultRedirect>;
|
|
17
|
+
delete redirect?.postUrl;
|
|
18
|
+
delete redirect?.returnUrl;
|
|
19
|
+
|
|
20
|
+
const reqBody = {
|
|
21
|
+
...payload,
|
|
22
|
+
autoSettle: false,
|
|
23
|
+
option: {
|
|
24
|
+
...(option || {}),
|
|
25
|
+
createAlias: true,
|
|
26
|
+
returnCustomerCountry: true,
|
|
27
|
+
authenticationOnly: false,
|
|
28
|
+
},
|
|
29
|
+
redirect,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const { fetchDatatrans }: { fetchDatatrans: FetchDatatransFn } = this;
|
|
33
|
+
const result = await fetchDatatrans('/v1/transactions', reqBody);
|
|
34
|
+
const json = await result.json();
|
|
35
|
+
const location = result.headers?.get('location');
|
|
36
|
+
return {
|
|
37
|
+
location,
|
|
38
|
+
...json,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import util from 'util';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import { log, LogLevel } from '@unchainedshop/logger';
|
|
5
|
+
|
|
6
|
+
const readFile = util.promisify(fs.readFile);
|
|
7
|
+
|
|
8
|
+
const { DATATRANS_API_MOCKS_PATH } = process.env;
|
|
9
|
+
|
|
10
|
+
export default (
|
|
11
|
+
endpoint: string,
|
|
12
|
+
merchantId: string,
|
|
13
|
+
secret: string,
|
|
14
|
+
): ((path: string) => Promise<Response>) => {
|
|
15
|
+
if (DATATRANS_API_MOCKS_PATH) {
|
|
16
|
+
return async (path): Promise<Response> => {
|
|
17
|
+
try {
|
|
18
|
+
const filePath = resolve(process.env.PWD, DATATRANS_API_MOCKS_PATH, `.${path}.json`);
|
|
19
|
+
const content = await readFile(filePath);
|
|
20
|
+
const json = JSON.parse(content.toString());
|
|
21
|
+
return {
|
|
22
|
+
json: async () => json,
|
|
23
|
+
status: json?.error ? 500 : 204,
|
|
24
|
+
};
|
|
25
|
+
} catch (error) {
|
|
26
|
+
log('DataTrans V2 (makeFetcher) -> Error while trying reading and parsing file', {
|
|
27
|
+
level: LogLevel.Error,
|
|
28
|
+
...error,
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
json: async () => ({ error: { code: 'MOCK', message: 'MOCK' } }),
|
|
32
|
+
status: 500,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const token = `${merchantId}:${secret}`;
|
|
39
|
+
|
|
40
|
+
return async (path: string, body: unknown): Promise<Response> =>
|
|
41
|
+
fetch(`${endpoint}${path}`, {
|
|
42
|
+
method: body ? 'POST' : 'GET',
|
|
43
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
Authorization: `Basic ${Buffer.from(token, 'utf-8').toString('base64')}`,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// https://api-reference.datatrans.ch/#operation/init
|
|
2
|
+
import getPaths from '../getPaths';
|
|
3
|
+
|
|
4
|
+
import type { FetchDatatransFn, SecureFieldsRequestPayload, SecureFieldsResponse } from './types';
|
|
5
|
+
|
|
6
|
+
const defaultRedirect = getPaths();
|
|
7
|
+
|
|
8
|
+
export default async function secureFields(
|
|
9
|
+
payload: SecureFieldsRequestPayload,
|
|
10
|
+
): Promise<SecureFieldsResponse> {
|
|
11
|
+
const reqBody = {
|
|
12
|
+
returnUrl: defaultRedirect.returnUrl,
|
|
13
|
+
...payload,
|
|
14
|
+
};
|
|
15
|
+
const { fetchDatatrans }: { fetchDatatrans: FetchDatatransFn } = this;
|
|
16
|
+
const result = await fetchDatatrans('/v1/transactions/secureFields', reqBody);
|
|
17
|
+
const json = await result.json();
|
|
18
|
+
return json;
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FetchDatatransFn, SettleRequestPayload, SettleResponse } from './types';
|
|
2
|
+
|
|
3
|
+
export default async function settle({
|
|
4
|
+
transactionId,
|
|
5
|
+
...payload
|
|
6
|
+
}: SettleRequestPayload): Promise<SettleResponse> {
|
|
7
|
+
const reqBody = payload;
|
|
8
|
+
const { fetchDatatrans }: { fetchDatatrans: FetchDatatransFn } = this;
|
|
9
|
+
const result = await fetchDatatrans(`/v1/transactions/${transactionId}/settle`, reqBody);
|
|
10
|
+
if (result.status === 204) return true;
|
|
11
|
+
const json = await result.json();
|
|
12
|
+
return json;
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FetchDatatransFn, StatusRequestPayload, StatusResponse } from './types';
|
|
2
|
+
|
|
3
|
+
export default async function status({ transactionId }: StatusRequestPayload): Promise<StatusResponse> {
|
|
4
|
+
const { fetchDatatrans }: { fetchDatatrans: FetchDatatransFn } = this;
|
|
5
|
+
const result = await fetchDatatrans(`/v1/transactions/${transactionId}`);
|
|
6
|
+
const json = await result.json();
|
|
7
|
+
return json;
|
|
8
|
+
}
|