@unchainedshop/plugins 1.1.3 → 1.1.4
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/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 +9 -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/email.js +55 -4
- package/lib/worker/email.js.map +1 -1
- package/package.json +18 -2
- 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/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/email.ts +56 -4
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { PaymentDirector, PaymentAdapter, PaymentError } from '@unchainedshop/core-payment';
|
|
2
|
+
|
|
3
|
+
import { IPaymentAdapter } from '@unchainedshop/types/payments';
|
|
4
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
5
|
+
|
|
6
|
+
import { OrderPricingSheet } from '@unchainedshop/core-orders';
|
|
7
|
+
import bodyParser from 'body-parser';
|
|
8
|
+
import { acl, roles, useMiddlewareWithCurrentContext } from 'meteor/unchained:api';
|
|
9
|
+
import crypto from 'crypto';
|
|
10
|
+
import fetch from 'isomorphic-unfetch';
|
|
11
|
+
import ClientOAuth2 from '@unchainedshop/client-oauth2';
|
|
12
|
+
import { Context } from '@unchainedshop/types/api';
|
|
13
|
+
import { BityModule } from './module/configureBityModule';
|
|
14
|
+
|
|
15
|
+
const logger = createLogger('unchained:core-payment:bity');
|
|
16
|
+
|
|
17
|
+
const { checkAction } = acl;
|
|
18
|
+
const { actions } = roles;
|
|
19
|
+
|
|
20
|
+
let currentToken;
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
BITY_CLIENT_ID,
|
|
24
|
+
BITY_CLIENT_SECRET,
|
|
25
|
+
BITY_BANK_ACCOUNT_IBAN,
|
|
26
|
+
BITY_BANK_ACCOUNT_ADDRESS,
|
|
27
|
+
BITY_BANK_ACCOUNT_CITY,
|
|
28
|
+
BITY_BANK_ACCOUNT_COUNTRY,
|
|
29
|
+
BITY_BANK_ACCOUNT_NAME,
|
|
30
|
+
BITY_BANK_ACCOUNT_ZIP,
|
|
31
|
+
BITY_API_ENDPOINT = 'https://exchange.api.bity.com',
|
|
32
|
+
BITY_OAUTH_INIT_PATH = '/graphql/bity-auth',
|
|
33
|
+
BITY_OAUTH_REDIRECT_URI = 'http://localhost:4010/graphql/bity',
|
|
34
|
+
BITY_OAUTH_STATE = 'unchained',
|
|
35
|
+
BITY_OAUTH_PATH = '/graphql/bity',
|
|
36
|
+
} = process.env;
|
|
37
|
+
|
|
38
|
+
const createBityAuth = () => {
|
|
39
|
+
if (!BITY_CLIENT_ID) throw new Error('Bity plugin is not setup');
|
|
40
|
+
|
|
41
|
+
return new ClientOAuth2({
|
|
42
|
+
clientId: BITY_CLIENT_ID,
|
|
43
|
+
clientSecret: BITY_CLIENT_SECRET,
|
|
44
|
+
accessTokenUri: 'https://connect.bity.com/oauth2/token',
|
|
45
|
+
authorizationUri: 'https://connect.bity.com/oauth2/auth',
|
|
46
|
+
redirectUri: BITY_OAUTH_REDIRECT_URI,
|
|
47
|
+
state: BITY_OAUTH_STATE,
|
|
48
|
+
scopes: [
|
|
49
|
+
'https://auth.bity.com/scopes/exchange.place',
|
|
50
|
+
'https://auth.bity.com/scopes/exchange.history',
|
|
51
|
+
'offline_access',
|
|
52
|
+
],
|
|
53
|
+
sendClientCredentialsInBody: true,
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const upsertBityCredentials = async (user, context: Context) => {
|
|
58
|
+
currentToken = user;
|
|
59
|
+
|
|
60
|
+
const iv = crypto.randomBytes(16);
|
|
61
|
+
const key = crypto
|
|
62
|
+
.createHash('sha256')
|
|
63
|
+
.update(String(BITY_CLIENT_SECRET))
|
|
64
|
+
.digest('base64')
|
|
65
|
+
.substring(0, 32);
|
|
66
|
+
|
|
67
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
|
|
68
|
+
let encrypted = cipher.update(JSON.stringify(user.data));
|
|
69
|
+
encrypted = Buffer.concat([encrypted, cipher.final()]);
|
|
70
|
+
|
|
71
|
+
const externalId = `${BITY_CLIENT_ID}-${BITY_OAUTH_REDIRECT_URI}-${BITY_OAUTH_STATE}`;
|
|
72
|
+
const doc = {
|
|
73
|
+
externalId,
|
|
74
|
+
data: {
|
|
75
|
+
iv: iv.toString('hex'),
|
|
76
|
+
encryptedData: encrypted.toString('hex'),
|
|
77
|
+
},
|
|
78
|
+
expires: user.expires,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const bityModule = (context.modules as any).bity as BityModule;
|
|
82
|
+
await bityModule.upsertCredentials(doc, context.userId);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const getTokenFromDb = async (bityAuth, context: Context) => {
|
|
86
|
+
const bityModule = (context.modules as any).bity as BityModule;
|
|
87
|
+
const credentials = await bityModule.findBityCredentials({
|
|
88
|
+
externalId: `${BITY_CLIENT_ID}-${BITY_OAUTH_REDIRECT_URI}-${BITY_OAUTH_STATE}`,
|
|
89
|
+
});
|
|
90
|
+
if (!credentials?.data) return null;
|
|
91
|
+
|
|
92
|
+
const iv = Buffer.from(credentials.data.iv, 'hex');
|
|
93
|
+
const encryptedText = Buffer.from(credentials.data.encryptedData, 'hex');
|
|
94
|
+
const key = crypto
|
|
95
|
+
.createHash('sha256')
|
|
96
|
+
.update(String(BITY_CLIENT_SECRET))
|
|
97
|
+
.digest('base64')
|
|
98
|
+
.substr(0, 32);
|
|
99
|
+
|
|
100
|
+
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
|
|
101
|
+
let decrypted = decipher.update(encryptedText);
|
|
102
|
+
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
103
|
+
const data = JSON.parse(decrypted.toString());
|
|
104
|
+
|
|
105
|
+
const token = bityAuth.createToken(data.access_token, data.refresh_token, data.token_type, { data });
|
|
106
|
+
return token;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const refreshBityUser = async (context: Context) => {
|
|
110
|
+
if (currentToken) {
|
|
111
|
+
const newToken = await currentToken.refresh();
|
|
112
|
+
if (newToken) {
|
|
113
|
+
await upsertBityCredentials(newToken, context);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const signPayload = (...args) => {
|
|
119
|
+
const resultString = args.filter(Boolean).join('');
|
|
120
|
+
const signKeyInBytes = Buffer.from(BITY_CLIENT_ID, 'hex');
|
|
121
|
+
|
|
122
|
+
const signedString = crypto.createHmac('sha256', signKeyInBytes).update(resultString).digest('hex');
|
|
123
|
+
return signedString;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const bityExchangeFetch = async (params: { path: string; data?: any }, context: Context) => {
|
|
127
|
+
const body = params.data && JSON.stringify(params.data);
|
|
128
|
+
const doFetch = async () => {
|
|
129
|
+
const response = await fetch(`${BITY_API_ENDPOINT}${params.path}`, {
|
|
130
|
+
method: body ? 'POST' : 'GET',
|
|
131
|
+
body: body || undefined,
|
|
132
|
+
headers: {
|
|
133
|
+
Authorization: `Bearer ${currentToken.accessToken}`,
|
|
134
|
+
'Content-Type': 'application/json',
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
return response;
|
|
138
|
+
};
|
|
139
|
+
const response = await doFetch();
|
|
140
|
+
if (response.status === 401) {
|
|
141
|
+
await refreshBityUser(context);
|
|
142
|
+
return doFetch();
|
|
143
|
+
}
|
|
144
|
+
return response;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const createBityOrder = async (data: any, context: Context) => {
|
|
148
|
+
const response = await bityExchangeFetch(
|
|
149
|
+
{
|
|
150
|
+
path: '/v2/orders',
|
|
151
|
+
data,
|
|
152
|
+
},
|
|
153
|
+
context,
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
if (response?.status !== 201) {
|
|
157
|
+
logger.error('Bity Plugin: Response invalid', {
|
|
158
|
+
data,
|
|
159
|
+
route: '/orders',
|
|
160
|
+
response,
|
|
161
|
+
});
|
|
162
|
+
throw new Error('Could not create Bity Order');
|
|
163
|
+
}
|
|
164
|
+
return response.headers.get('Location');
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// eslint-disable-next-line
|
|
168
|
+
const estimateBityOrder = async (data: any, context: Context) => {
|
|
169
|
+
const response = await bityExchangeFetch(
|
|
170
|
+
{
|
|
171
|
+
path: '/v2/orders/estimate',
|
|
172
|
+
data,
|
|
173
|
+
},
|
|
174
|
+
context,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
if (response?.status !== 200) {
|
|
178
|
+
logger.error('Bity Plugin: Response invalid', {
|
|
179
|
+
data,
|
|
180
|
+
route: '/orders/estimate',
|
|
181
|
+
response,
|
|
182
|
+
});
|
|
183
|
+
throw new Error('Could not estimate Bity Currency Conversion');
|
|
184
|
+
}
|
|
185
|
+
return response.json();
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
useMiddlewareWithCurrentContext(BITY_OAUTH_INIT_PATH, async (req, res) => {
|
|
189
|
+
if (req.method === 'GET') {
|
|
190
|
+
try {
|
|
191
|
+
const resolvedContext = req.unchainedContext;
|
|
192
|
+
await checkAction(resolvedContext, actions.managePaymentProviders);
|
|
193
|
+
|
|
194
|
+
const bityAuthClient = createBityAuth();
|
|
195
|
+
const uri = bityAuthClient.code.getUri();
|
|
196
|
+
logger.info(`Bity Webhook: Login ${uri}`);
|
|
197
|
+
res.writeHead(302, {
|
|
198
|
+
Location: uri,
|
|
199
|
+
});
|
|
200
|
+
res.end();
|
|
201
|
+
return;
|
|
202
|
+
} catch (e) {
|
|
203
|
+
logger.warn(`Bity Webhook: Failed with ${e.message}`);
|
|
204
|
+
res.writeHead(503);
|
|
205
|
+
res.end(JSON.stringify(e));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
res.writeHead(404);
|
|
210
|
+
res.end();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
useMiddlewareWithCurrentContext(BITY_OAUTH_PATH, async (req, res, next) => {
|
|
214
|
+
bodyParser.urlencoded({ extended: false })(req, res, next);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
useMiddlewareWithCurrentContext(BITY_OAUTH_PATH, async (req, res) => {
|
|
218
|
+
if (req.method === 'GET') {
|
|
219
|
+
try {
|
|
220
|
+
const resolvedContext = req.unchainedContext as Context;
|
|
221
|
+
await checkAction(resolvedContext, actions.managePaymentProviders);
|
|
222
|
+
const bityAuthClient = createBityAuth();
|
|
223
|
+
const user = await bityAuthClient.code.getToken(req.originalUrl);
|
|
224
|
+
await upsertBityCredentials(user, resolvedContext);
|
|
225
|
+
res.writeHead(200);
|
|
226
|
+
res.end('Bity Credentials Setup Complete');
|
|
227
|
+
return;
|
|
228
|
+
} catch (e) {
|
|
229
|
+
logger.warn(`Bity Webhook: Failed with ${e.message}`);
|
|
230
|
+
res.writeHead(503);
|
|
231
|
+
res.end(JSON.stringify(e));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
res.writeHead(404);
|
|
236
|
+
res.end();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
let bityAuthClient;
|
|
240
|
+
const loadToken = async (context: Context) => {
|
|
241
|
+
if (currentToken) return currentToken;
|
|
242
|
+
|
|
243
|
+
if (!bityAuthClient) {
|
|
244
|
+
bityAuthClient = createBityAuth();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (bityAuthClient) {
|
|
248
|
+
currentToken = await getTokenFromDb(bityAuthClient, context);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return currentToken;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
let token;
|
|
255
|
+
|
|
256
|
+
const Bity: IPaymentAdapter = {
|
|
257
|
+
...PaymentAdapter,
|
|
258
|
+
|
|
259
|
+
key: 'shop.unchained.payment.bity',
|
|
260
|
+
label: 'Bity',
|
|
261
|
+
version: '1.0',
|
|
262
|
+
|
|
263
|
+
initialConfiguration: [],
|
|
264
|
+
|
|
265
|
+
typeSupported: (type) => {
|
|
266
|
+
return type === 'GENERIC';
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
actions: (params) => {
|
|
270
|
+
loadToken(params.context).then((t) => {
|
|
271
|
+
token = t;
|
|
272
|
+
});
|
|
273
|
+
const adapter = {
|
|
274
|
+
...PaymentAdapter.actions(params),
|
|
275
|
+
|
|
276
|
+
configurationError: () => {
|
|
277
|
+
if (!token) {
|
|
278
|
+
return PaymentError.INCOMPLETE_CONFIGURATION;
|
|
279
|
+
}
|
|
280
|
+
return null;
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
isActive: () => {
|
|
284
|
+
if (adapter.configurationError() === null) return true;
|
|
285
|
+
return false;
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
isPayLaterAllowed() {
|
|
289
|
+
return false;
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
sign: async (transactionContext = {}) => {
|
|
293
|
+
// Signing the order will estimate a new order in bity and sign it with private data
|
|
294
|
+
logger.info(`Bity Plugin: Sign ${JSON.stringify(transactionContext)}`);
|
|
295
|
+
|
|
296
|
+
const { orderPayment } = params.paymentContext;
|
|
297
|
+
|
|
298
|
+
const order = await params.context.modules.orders.findOrder({
|
|
299
|
+
orderId: orderPayment.orderId,
|
|
300
|
+
});
|
|
301
|
+
const pricing = OrderPricingSheet({
|
|
302
|
+
calculation: order.calculation,
|
|
303
|
+
currency: order.currency,
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
if (!pricing) {
|
|
307
|
+
throw new Error('Price calculation of order invalid');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const totalAmount = Math.round(pricing.total({ useNetPrice: false }).amount / 10 || 0) * 10;
|
|
311
|
+
|
|
312
|
+
const payload = await estimateBityOrder(
|
|
313
|
+
{
|
|
314
|
+
output: {
|
|
315
|
+
currency: 'EUR',
|
|
316
|
+
amount: `${totalAmount / 100}`,
|
|
317
|
+
},
|
|
318
|
+
input: {
|
|
319
|
+
currency: 'BTC',
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
params.context,
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
const signature = signPayload(
|
|
326
|
+
JSON.stringify(payload),
|
|
327
|
+
order._id,
|
|
328
|
+
totalAmount,
|
|
329
|
+
BITY_CLIENT_SECRET,
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
return JSON.stringify({
|
|
333
|
+
payload,
|
|
334
|
+
signature,
|
|
335
|
+
});
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
charge: async () => {
|
|
339
|
+
const { order } = params.paymentContext;
|
|
340
|
+
const { bityPayload, bitySignature } = order?.context || {};
|
|
341
|
+
|
|
342
|
+
const pricing = OrderPricingSheet({
|
|
343
|
+
calculation: order.calculation,
|
|
344
|
+
currency: order.currency,
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
if (!pricing) {
|
|
348
|
+
throw new Error('Price calculation of order invalid');
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const totalAmount =
|
|
352
|
+
Math.round(
|
|
353
|
+
pricing.total({
|
|
354
|
+
useNetPrice: false,
|
|
355
|
+
}).amount / 10 || 0,
|
|
356
|
+
) * 10;
|
|
357
|
+
|
|
358
|
+
const signature = signPayload(
|
|
359
|
+
JSON.stringify(bityPayload),
|
|
360
|
+
order._id,
|
|
361
|
+
totalAmount,
|
|
362
|
+
BITY_CLIENT_SECRET,
|
|
363
|
+
);
|
|
364
|
+
if (bitySignature !== signature) {
|
|
365
|
+
logger.warn(`Bity Plugin: Signature Mismatch ${JSON.stringify(bityPayload)} ${bitySignature}`);
|
|
366
|
+
throw new Error('Signature Mismatch');
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const path = await createBityOrder(
|
|
370
|
+
{
|
|
371
|
+
input: {
|
|
372
|
+
amount: bityPayload.input.amount,
|
|
373
|
+
currency: bityPayload.input.currency,
|
|
374
|
+
},
|
|
375
|
+
output: {
|
|
376
|
+
currency: bityPayload.output.currency,
|
|
377
|
+
type: 'bank_account',
|
|
378
|
+
iban: BITY_BANK_ACCOUNT_IBAN,
|
|
379
|
+
reference: order._id,
|
|
380
|
+
owner: {
|
|
381
|
+
address: BITY_BANK_ACCOUNT_ADDRESS,
|
|
382
|
+
city: BITY_BANK_ACCOUNT_CITY,
|
|
383
|
+
country: BITY_BANK_ACCOUNT_COUNTRY,
|
|
384
|
+
name: BITY_BANK_ACCOUNT_NAME,
|
|
385
|
+
zip: BITY_BANK_ACCOUNT_ZIP,
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
params.context,
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
logger.info(`Bity Plugin: Prepared Bity Order`, path);
|
|
393
|
+
const response = await bityExchangeFetch({ path }, params.context);
|
|
394
|
+
|
|
395
|
+
const bityOrder = await response?.json();
|
|
396
|
+
if (!bityOrder) {
|
|
397
|
+
logger.warn(`Bity Plugin: Bity Order not found ${JSON.stringify(path)} ${bitySignature}`);
|
|
398
|
+
throw new Error('Bity Order not Found');
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
await params.context.modules.orders.updateContext(
|
|
402
|
+
order._id,
|
|
403
|
+
{
|
|
404
|
+
bityOrder,
|
|
405
|
+
},
|
|
406
|
+
params.context,
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
return false;
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
return adapter;
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
PaymentDirector.registerAdapter(Bity);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Db, TimestampFields, _ID } from '@unchainedshop/types/common';
|
|
2
|
+
|
|
3
|
+
export type BityCredentialsType = {
|
|
4
|
+
_id?: _ID;
|
|
5
|
+
externalId: string;
|
|
6
|
+
data: {
|
|
7
|
+
iv: string;
|
|
8
|
+
encryptedData: string;
|
|
9
|
+
};
|
|
10
|
+
expires: Date;
|
|
11
|
+
} & TimestampFields;
|
|
12
|
+
|
|
13
|
+
export const BityCredentialsCollection = (db: Db) => {
|
|
14
|
+
const BityCredentials = db.collection<BityCredentialsType>('bity_credentials');
|
|
15
|
+
|
|
16
|
+
return BityCredentials;
|
|
17
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Db } from '@unchainedshop/types/common';
|
|
2
|
+
import { generateDbObjectId } from '@unchainedshop/utils';
|
|
3
|
+
import { BityCredentialsCollection, BityCredentialsType } from '../db/BityCredentialsCollection';
|
|
4
|
+
|
|
5
|
+
export interface BityModule {
|
|
6
|
+
findBityCredentials: (query: { externalId: string }) => Promise<BityCredentialsType>;
|
|
7
|
+
|
|
8
|
+
upsertCredentials: (doc: BityCredentialsType, userId: string) => Promise<string | null>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const configureBityModule = ({ db }: { db: Db }): BityModule => {
|
|
12
|
+
const BityCredentials = BityCredentialsCollection(db);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
findBityCredentials: async ({ externalId }) => {
|
|
16
|
+
return BityCredentials.findOne({ externalId });
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
upsertCredentials: async (doc, userId) => {
|
|
20
|
+
await BityCredentials.updateOne(
|
|
21
|
+
{
|
|
22
|
+
externalId: doc.externalId,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
$set: {
|
|
26
|
+
data: {
|
|
27
|
+
iv: doc.data.iv,
|
|
28
|
+
encryptedData: doc.data.encryptedData,
|
|
29
|
+
},
|
|
30
|
+
expires: doc.expires,
|
|
31
|
+
updated: new Date(),
|
|
32
|
+
updatedBy: userId,
|
|
33
|
+
},
|
|
34
|
+
$setOnInsert: {
|
|
35
|
+
_id: generateDbObjectId(),
|
|
36
|
+
externalId: doc.externalId,
|
|
37
|
+
created: new Date(),
|
|
38
|
+
createdBy: userId,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return doc.externalId;
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { IPaymentAdapter } from '@unchainedshop/types/payments';
|
|
2
|
+
import { PaymentDirector, PaymentAdapter, PaymentError } from '@unchainedshop/core-payment';
|
|
3
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
4
|
+
|
|
5
|
+
const logger = createLogger('unchained:core-payment:braintree');
|
|
6
|
+
|
|
7
|
+
const { BRAINTREE_SANDBOX_TOKEN, BRAINTREE_PRIVATE_KEY } = process.env;
|
|
8
|
+
|
|
9
|
+
const BraintreeDirect: IPaymentAdapter = {
|
|
10
|
+
...PaymentAdapter,
|
|
11
|
+
|
|
12
|
+
key: 'shop.unchained.braintree-direct',
|
|
13
|
+
label: 'Braintree Direct',
|
|
14
|
+
version: '1.0',
|
|
15
|
+
|
|
16
|
+
initialConfiguration: [
|
|
17
|
+
{
|
|
18
|
+
key: 'publicKey',
|
|
19
|
+
value: null,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
key: 'merchantId',
|
|
23
|
+
value: null,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
|
|
27
|
+
typeSupported: (type) => {
|
|
28
|
+
return type === 'GENERIC';
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
actions: (params) => {
|
|
32
|
+
const getPublicKey = () => {
|
|
33
|
+
return params.config.reduce((current, item) => {
|
|
34
|
+
if (item.key === 'publicKey') return item.value;
|
|
35
|
+
return current;
|
|
36
|
+
}, null);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const getMerchantId = () => {
|
|
40
|
+
return params.config.reduce((current, item) => {
|
|
41
|
+
if (item.key === 'merchantId') return item.value;
|
|
42
|
+
return current;
|
|
43
|
+
}, null);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const getAccessToken = () => {
|
|
47
|
+
return BRAINTREE_SANDBOX_TOKEN;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// eslint-disable-next-line
|
|
51
|
+
const getPrivateKey = () => {
|
|
52
|
+
return BRAINTREE_PRIVATE_KEY;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const getGateway = (braintree) => {
|
|
56
|
+
const accessToken = getAccessToken();
|
|
57
|
+
if (accessToken) {
|
|
58
|
+
// sandbox mode!
|
|
59
|
+
return braintree.connect({
|
|
60
|
+
accessToken,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return braintree.connect({
|
|
64
|
+
environment: braintree.Environment.Production,
|
|
65
|
+
merchantId: getMerchantId(),
|
|
66
|
+
publicKey: getPublicKey(),
|
|
67
|
+
privateKey: getPrivateKey(),
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const adapter = {
|
|
72
|
+
...PaymentAdapter.actions(params),
|
|
73
|
+
|
|
74
|
+
configurationError: () => {
|
|
75
|
+
const publicCredentialsValid =
|
|
76
|
+
getAccessToken() || (getMerchantId() && getPublicKey() && getPrivateKey());
|
|
77
|
+
|
|
78
|
+
if (!publicCredentialsValid) {
|
|
79
|
+
return PaymentError.WRONG_CREDENTIALS;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
isActive: () => {
|
|
85
|
+
if (adapter.configurationError() === null) return true;
|
|
86
|
+
return false;
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
isPayLaterAllowed: () => {
|
|
90
|
+
return false;
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
sign: async () => {
|
|
94
|
+
const braintree = require('braintree'); // eslint-disable-line
|
|
95
|
+
const gateway = getGateway(braintree);
|
|
96
|
+
const result = await gateway.clientToken.generate({});
|
|
97
|
+
if (result.success) {
|
|
98
|
+
return result.clientToken;
|
|
99
|
+
}
|
|
100
|
+
throw new Error('Could not retrieve the client token');
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
charge: async ({ paypalPaymentMethodNonce }) => {
|
|
104
|
+
const { modules } = params.context;
|
|
105
|
+
const { order } = params.paymentContext;
|
|
106
|
+
if (!paypalPaymentMethodNonce)
|
|
107
|
+
throw new Error('You have to provide paypalPaymentMethodNonce in paymentContext');
|
|
108
|
+
const braintree = require('braintree'); // eslint-disable-line
|
|
109
|
+
const gateway = getGateway(braintree);
|
|
110
|
+
const address = order.billingAddress || {};
|
|
111
|
+
const pricing = modules.orders.pricingSheet(order);
|
|
112
|
+
const rounded = Math.round(pricing.total({ useNetPrice: false }).amount / 10 || 0) * 10;
|
|
113
|
+
const saleRequest = {
|
|
114
|
+
amount: rounded / 100,
|
|
115
|
+
merchantAccountId: order.currency,
|
|
116
|
+
paymentMethodNonce: paypalPaymentMethodNonce,
|
|
117
|
+
orderId: order.orderNumber || order._id,
|
|
118
|
+
shipping: {
|
|
119
|
+
firstName: address.firstName,
|
|
120
|
+
lastName: address.lastName,
|
|
121
|
+
company: address.company,
|
|
122
|
+
streetAddress: address.addressLine,
|
|
123
|
+
extendedAddress: address.addressLine2,
|
|
124
|
+
locality: address.city,
|
|
125
|
+
region: address.regionCode,
|
|
126
|
+
postalCode: address.postalCode,
|
|
127
|
+
countryCodeAlpha2: address.countryCode,
|
|
128
|
+
},
|
|
129
|
+
options: {
|
|
130
|
+
submitForSettlement: true,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
const result = await gateway.transaction.sale(saleRequest);
|
|
134
|
+
if (result.success) {
|
|
135
|
+
logger.info(`Braintree Plugin: ${result.message}`, saleRequest);
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
logger.warn(`Braintree Plugin: ${result.message}`, saleRequest);
|
|
139
|
+
throw new Error(result.message);
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
return adapter;
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
PaymentDirector.registerAdapter(BraintreeDirect);
|