@unchainedshop/plugins 3.1.14 → 4.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/delivery/pick-mup.js +0 -2
- package/lib/delivery/pick-mup.js.map +1 -1
- package/lib/files/gridfs/adapter.d.ts.map +1 -1
- package/lib/files/gridfs/adapter.js +3 -2
- package/lib/files/gridfs/adapter.js.map +1 -1
- package/lib/files/gridfs/handler-express.d.ts.map +1 -1
- package/lib/files/gridfs/handler-express.js +6 -2
- package/lib/files/gridfs/handler-express.js.map +1 -1
- package/lib/files/gridfs/handler-fastify.d.ts.map +1 -1
- package/lib/files/gridfs/handler-fastify.js +5 -2
- package/lib/files/gridfs/handler-fastify.js.map +1 -1
- package/lib/files/gridfs/module.d.ts +2 -2
- package/lib/files/gridfs/module.d.ts.map +1 -1
- package/lib/filters/local-search.d.ts.map +1 -1
- package/lib/filters/local-search.js +9 -2
- package/lib/filters/local-search.js.map +1 -1
- package/lib/filters/strict-equal.js +18 -0
- package/lib/filters/strict-equal.js.map +1 -1
- package/lib/payment/apple-iap/adapter.js +6 -13
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/fix-periods.d.ts.map +1 -1
- package/lib/payment/apple-iap/fix-periods.js +3 -5
- package/lib/payment/apple-iap/fix-periods.js.map +1 -1
- package/lib/payment/apple-iap/handler-express.js +4 -4
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +4 -4
- package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
- package/lib/payment/apple-iap/module.d.ts +2 -2
- package/lib/payment/apple-iap/module.d.ts.map +1 -1
- package/lib/payment/braintree.js +3 -4
- package/lib/payment/braintree.js.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -2
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.js.map +1 -1
- package/lib/payment/cryptopay/handle-webhook.js +1 -1
- package/lib/payment/cryptopay/handle-webhook.js.map +1 -1
- package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-express.js +4 -57
- package/lib/payment/cryptopay/handler-express.js.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.js +4 -56
- package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
- package/lib/payment/cryptopay/module.d.ts +26 -26
- package/lib/payment/cryptopay/module.d.ts.map +1 -1
- package/lib/payment/cryptopay/module.js +26 -24
- package/lib/payment/cryptopay/module.js.map +1 -1
- package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
- package/lib/payment/cryptopay/plugin.js +33 -79
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/datatrans-v2/api/types.d.ts +41 -41
- package/lib/payment/datatrans-v2/api/types.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/getPaths.d.ts +2 -2
- package/lib/payment/datatrans-v2/getPaths.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/index.js +16 -14
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +3 -3
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -1
- package/lib/payment/paypal-checkout.js +6 -8
- package/lib/payment/paypal-checkout.js.map +1 -1
- package/lib/payment/payrexx/api/index.d.ts +2 -2
- package/lib/payment/payrexx/api/index.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
- package/lib/payment/payrexx/index.js +4 -4
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/payrexx/payrexx.js +2 -2
- package/lib/payment/payrexx/payrexx.js.map +1 -1
- package/lib/payment/postfinance-checkout/api-client.d.ts +16 -0
- package/lib/payment/postfinance-checkout/api-client.d.ts.map +1 -0
- package/lib/payment/postfinance-checkout/api-client.js +75 -0
- package/lib/payment/postfinance-checkout/api-client.js.map +1 -0
- package/lib/payment/postfinance-checkout/api-types.d.ts +98 -0
- package/lib/payment/postfinance-checkout/api-types.d.ts.map +1 -0
- package/lib/payment/postfinance-checkout/api-types.js +51 -0
- package/lib/payment/postfinance-checkout/api-types.js.map +1 -0
- package/lib/payment/postfinance-checkout/api.d.ts +5 -5
- package/lib/payment/postfinance-checkout/api.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/api.js +38 -62
- package/lib/payment/postfinance-checkout/api.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.js +5 -5
- package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.js +6 -6
- package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.d.ts +2 -1
- package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/index.js +27 -30
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/types.d.ts +4 -4
- package/lib/payment/postfinance-checkout/types.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/utils.d.ts +3 -3
- package/lib/payment/postfinance-checkout/utils.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/utils.js +5 -6
- package/lib/payment/postfinance-checkout/utils.js.map +1 -1
- package/lib/payment/saferpay/adapter.d.ts.map +1 -1
- package/lib/payment/saferpay/adapter.js +4 -6
- package/lib/payment/saferpay/adapter.js.map +1 -1
- package/lib/payment/saferpay/api/models/Transaction.d.ts +2 -2
- package/lib/payment/saferpay/api/models/Transaction.d.ts.map +1 -1
- package/lib/payment/saferpay/module.d.ts +2 -2
- package/lib/payment/saferpay/module.d.ts.map +1 -1
- package/lib/payment/stripe/index.js +5 -5
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/stripe.js +3 -3
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/lib/presets/all.d.ts +15 -13
- package/lib/presets/all.d.ts.map +1 -1
- package/lib/presets/all.js +3 -1
- package/lib/presets/all.js.map +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +2 -2
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/order-delivery.js +1 -1
- package/lib/pricing/order-delivery.js.map +1 -1
- package/lib/pricing/order-discount.js +3 -3
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-items-discount.js +1 -1
- package/lib/pricing/order-items-discount.js.map +1 -1
- package/lib/pricing/order-items.js +1 -1
- package/lib/pricing/order-items.js.map +1 -1
- package/lib/pricing/order-payment.js +1 -1
- package/lib/pricing/order-payment.js.map +1 -1
- package/lib/pricing/order-round.d.ts +1 -1
- package/lib/pricing/order-round.d.ts.map +1 -1
- package/lib/pricing/order-round.js +8 -8
- package/lib/pricing/order-round.js.map +1 -1
- package/lib/pricing/product-catalog-price.d.ts +0 -1
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +6 -18
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +2 -2
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/pricing/product-round.d.ts +1 -1
- package/lib/pricing/product-round.d.ts.map +1 -1
- package/lib/pricing/product-round.js +2 -2
- package/lib/pricing/product-round.js.map +1 -1
- package/lib/pricing/product-swiss-tax.d.ts +1 -1
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +2 -2
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/warehousing/eth-minter.js +2 -2
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/budgetsms.d.ts +10 -0
- package/lib/worker/budgetsms.d.ts.map +1 -0
- package/lib/worker/budgetsms.js +217 -0
- package/lib/worker/budgetsms.js.map +1 -0
- package/lib/worker/bulk-import.js +1 -1
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/bulkgate.d.ts +2 -0
- package/lib/worker/bulkgate.d.ts.map +1 -0
- package/lib/worker/bulkgate.js +104 -0
- package/lib/worker/bulkgate.js.map +1 -0
- package/lib/worker/enrollment-order-generator.js +1 -1
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/error-notifications.d.ts +4 -4
- package/lib/worker/error-notifications.d.ts.map +1 -1
- package/lib/worker/heartbeat.js +2 -8
- package/lib/worker/heartbeat.js.map +1 -1
- package/lib/worker/message.d.ts +1 -1
- package/lib/worker/message.d.ts.map +1 -1
- package/lib/worker/sms.js +16 -16
- package/lib/worker/sms.js.map +1 -1
- package/lib/worker/twilio.d.ts +2 -0
- package/lib/worker/twilio.d.ts.map +1 -0
- package/lib/worker/twilio.js +56 -0
- package/lib/worker/twilio.js.map +1 -0
- package/lib/worker/update-coinbase-rates.js +1 -1
- package/lib/worker/update-coinbase-rates.js.map +1 -1
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/package.json +32 -53
- package/src/delivery/pick-mup.ts +0 -2
- package/src/files/gridfs/adapter.ts +7 -2
- package/src/files/gridfs/handler-express.ts +9 -2
- package/src/files/gridfs/handler-fastify.ts +8 -2
- package/src/files/gridfs/module.ts +2 -2
- package/src/filters/local-search.ts +11 -2
- package/src/filters/strict-equal.ts +21 -0
- package/src/payment/apple-iap/adapter.ts +7 -14
- package/src/payment/apple-iap/fix-periods.ts +4 -7
- package/src/payment/apple-iap/handler-express.ts +4 -4
- package/src/payment/apple-iap/handler-fastify.ts +4 -4
- package/src/payment/apple-iap/module.ts +2 -2
- package/src/payment/braintree.ts +3 -4
- package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -2
- package/src/payment/cryptopay/denote-amount.test.ts +28 -0
- package/src/payment/cryptopay/denote-amount.ts +29 -0
- package/src/payment/cryptopay/derive-btc-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-btc-address.ts +48 -0
- package/src/payment/cryptopay/derive-eth-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-eth-address.ts +38 -0
- package/src/payment/cryptopay/handle-webhook.ts +103 -0
- package/src/payment/cryptopay/handler-express.ts +4 -70
- package/src/payment/cryptopay/handler-fastify.ts +6 -71
- package/src/payment/cryptopay/module.ts +44 -40
- package/src/payment/cryptopay/plugin.ts +50 -87
- package/src/payment/cryptopay/readme.md +23 -1
- package/src/payment/datatrans-v2/api/types.ts +41 -41
- package/src/payment/datatrans-v2/getPaths.ts +2 -2
- package/src/payment/datatrans-v2/index.ts +17 -15
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +4 -4
- package/src/payment/paypal-checkout.ts +6 -11
- package/src/payment/payrexx/api/index.ts +2 -2
- package/src/payment/payrexx/api/makeFetcher.ts +1 -1
- package/src/payment/payrexx/index.ts +4 -4
- package/src/payment/payrexx/payrexx.ts +2 -2
- package/src/payment/postfinance-checkout/api-client.ts +106 -0
- package/src/payment/postfinance-checkout/api-types.ts +111 -0
- package/src/payment/postfinance-checkout/api.ts +58 -85
- package/src/payment/postfinance-checkout/handler-express.ts +5 -7
- package/src/payment/postfinance-checkout/handler-fastify.ts +6 -8
- package/src/payment/postfinance-checkout/index.ts +43 -35
- package/src/payment/postfinance-checkout/types.ts +6 -6
- package/src/payment/postfinance-checkout/utils.ts +7 -12
- package/src/payment/saferpay/adapter.ts +4 -6
- package/src/payment/saferpay/api/models/Transaction.ts +2 -2
- package/src/payment/saferpay/module.ts +2 -2
- package/src/payment/stripe/index.ts +5 -5
- package/src/payment/stripe/stripe.ts +3 -3
- package/src/presets/all.ts +3 -1
- package/src/pricing/delivery-swiss-tax.ts +6 -2
- package/src/pricing/order-delivery.ts +1 -1
- package/src/pricing/order-discount.ts +3 -3
- package/src/pricing/order-items-discount.ts +1 -1
- package/src/pricing/order-items.ts +1 -1
- package/src/pricing/order-payment.ts +1 -1
- package/src/pricing/order-round.ts +9 -9
- package/src/pricing/product-catalog-price.ts +6 -25
- package/src/pricing/product-price-rateconversion.ts +2 -2
- package/src/pricing/product-round.ts +3 -3
- package/src/pricing/product-swiss-tax.test.ts +6 -6
- package/src/pricing/product-swiss-tax.ts +2 -2
- package/src/warehousing/eth-minter.ts +2 -2
- package/src/worker/budgetsms.ts +268 -0
- package/src/worker/bulk-import.ts +1 -1
- package/src/worker/bulkgate.ts +138 -0
- package/src/worker/enrollment-order-generator.ts +3 -3
- package/src/worker/error-notifications.ts +4 -4
- package/src/worker/heartbeat.ts +4 -11
- package/src/worker/message.ts +1 -1
- package/src/worker/push-notification.ts +2 -2
- package/src/worker/twilio.ts +71 -0
- package/src/worker/update-coinbase-rates.ts +3 -6
- package/src/worker/update-ecb-rates.ts +3 -3
- package/lib/accounts/google-oauth.d.ts +0 -4
- package/lib/accounts/google-oauth.d.ts.map +0 -1
- package/lib/accounts/google-oauth.js +0 -145
- package/lib/accounts/google-oauth.js.map +0 -1
- package/lib/accounts/linkedin-oauth.d.ts +0 -4
- package/lib/accounts/linkedin-oauth.d.ts.map +0 -1
- package/lib/accounts/linkedin-oauth.js +0 -82
- package/lib/accounts/linkedin-oauth.js.map +0 -1
- package/lib/files/gridfs/gridfs-adapter.d.ts +0 -3
- package/lib/files/gridfs/gridfs-adapter.d.ts.map +0 -1
- package/lib/files/gridfs/gridfs-adapter.js +0 -97
- package/lib/files/gridfs/gridfs-adapter.js.map +0 -1
- package/lib/files/gridfs/gridfs-webhook.d.ts +0 -11
- package/lib/files/gridfs/gridfs-webhook.d.ts.map +0 -1
- package/lib/files/gridfs/gridfs-webhook.js +0 -84
- package/lib/files/gridfs/gridfs-webhook.js.map +0 -1
- package/lib/files/minio/minio-adapter.d.ts +0 -6
- package/lib/files/minio/minio-adapter.d.ts.map +0 -1
- package/lib/files/minio/minio-adapter.js +0 -181
- package/lib/files/minio/minio-adapter.js.map +0 -1
- package/lib/files/minio/minio-webhook.d.ts +0 -2
- package/lib/files/minio/minio-webhook.d.ts.map +0 -1
- package/lib/files/minio/minio-webhook.js +0 -33
- package/lib/files/minio/minio-webhook.js.map +0 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +0 -9
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +0 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +0 -17
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +0 -1
- package/lib/payment/cryptopay/middleware.d.ts +0 -2
- package/lib/payment/cryptopay/middleware.d.ts.map +0 -1
- package/lib/payment/cryptopay/middleware.js +0 -75
- package/lib/payment/cryptopay/middleware.js.map +0 -1
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +0 -25
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +0 -1
- package/lib/payment/cryptopay/module/configureCryptopayModule.js +0 -75
- package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +0 -1
- package/lib/payment/datatrans-v2/middleware.d.ts +0 -2
- package/lib/payment/datatrans-v2/middleware.d.ts.map +0 -1
- package/lib/payment/datatrans-v2/middleware.js +0 -68
- package/lib/payment/datatrans-v2/middleware.js.map +0 -1
- package/lib/payment/payrexx/middleware.d.ts +0 -2
- package/lib/payment/payrexx/middleware.d.ts.map +0 -1
- package/lib/payment/payrexx/middleware.js +0 -86
- package/lib/payment/payrexx/middleware.js.map +0 -1
- package/lib/payment/postfinance-checkout/middleware.d.ts +0 -2
- package/lib/payment/postfinance-checkout/middleware.d.ts.map +0 -1
- package/lib/payment/postfinance-checkout/middleware.js +0 -38
- package/lib/payment/postfinance-checkout/middleware.js.map +0 -1
- package/lib/payment/saferpay/middleware.d.ts +0 -2
- package/lib/payment/saferpay/middleware.d.ts.map +0 -1
- package/lib/payment/saferpay/middleware.js +0 -57
- package/lib/payment/saferpay/middleware.js.map +0 -1
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +0 -10
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +0 -1
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +0 -24
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +0 -1
- package/lib/payment/stripe/middleware.d.ts +0 -6
- package/lib/payment/stripe/middleware.d.ts.map +0 -1
- package/lib/payment/stripe/middleware.js +0 -114
- package/lib/payment/stripe/middleware.js.map +0 -1
- package/lib/plugins-index.d.ts +0 -48
- package/lib/plugins-index.d.ts.map +0 -1
- package/lib/plugins-index.js +0 -107
- package/lib/plugins-index.js.map +0 -1
- package/lib/worker/BaseWorker.d.ts +0 -30
- package/lib/worker/BaseWorker.d.ts.map +0 -1
- package/lib/worker/BaseWorker.js +0 -79
- package/lib/worker/BaseWorker.js.map +0 -1
- package/lib/worker/EventListenerWorker.d.ts +0 -6
- package/lib/worker/EventListenerWorker.d.ts.map +0 -1
- package/lib/worker/EventListenerWorker.js +0 -46
- package/lib/worker/EventListenerWorker.js.map +0 -1
- package/lib/worker/FailedRescheduler.d.ts +0 -15
- package/lib/worker/FailedRescheduler.d.ts.map +0 -1
- package/lib/worker/FailedRescheduler.js +0 -45
- package/lib/worker/FailedRescheduler.js.map +0 -1
- package/lib/worker/IntervalWorker.d.ts +0 -10
- package/lib/worker/IntervalWorker.d.ts.map +0 -1
- package/lib/worker/IntervalWorker.js +0 -37
- package/lib/worker/IntervalWorker.js.map +0 -1
- package/src/worker/BaseWorker.ts +0 -116
- package/src/worker/EventListenerWorker.ts +0 -61
- package/src/worker/FailedRescheduler.ts +0 -80
- package/src/worker/IntervalWorker.ts +0 -54
- package/src/worker/sms.ts +0 -87
|
@@ -89,11 +89,11 @@ const Datatrans: IPaymentAdapter = {
|
|
|
89
89
|
|
|
90
90
|
const pricingForOrderPayment = PaymentPricingSheet({
|
|
91
91
|
calculation: orderPayment.calculation,
|
|
92
|
-
|
|
92
|
+
currencyCode: order.currencyCode,
|
|
93
93
|
});
|
|
94
94
|
const pricing = OrderPricingSheet({
|
|
95
95
|
calculation: order.calculation,
|
|
96
|
-
|
|
96
|
+
currencyCode: order.currencyCode,
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
const { amount: total } = pricing.total({ useNetPrice: false });
|
|
@@ -128,12 +128,12 @@ const Datatrans: IPaymentAdapter = {
|
|
|
128
128
|
const refno = Buffer.from(orderPayment._id, 'hex').toString('base64');
|
|
129
129
|
const userId = order?.userId || context?.userId;
|
|
130
130
|
const refno2 = userId;
|
|
131
|
-
const {
|
|
131
|
+
const { currencyCode, amount } = roundedAmountFromOrder(order);
|
|
132
132
|
const splits = await getMarketplaceSplits();
|
|
133
133
|
const result = await api().authorize({
|
|
134
134
|
...arbitraryFields,
|
|
135
135
|
amount,
|
|
136
|
-
currency,
|
|
136
|
+
currency: currencyCode,
|
|
137
137
|
refno,
|
|
138
138
|
refno2,
|
|
139
139
|
autoSettle: false,
|
|
@@ -158,12 +158,12 @@ const Datatrans: IPaymentAdapter = {
|
|
|
158
158
|
...arbitraryFields
|
|
159
159
|
}): Promise<string> => {
|
|
160
160
|
const { order } = context;
|
|
161
|
-
const {
|
|
161
|
+
const { currencyCode, amount } = roundedAmountFromOrder(order);
|
|
162
162
|
const result = await api().authorizeAuthenticated({
|
|
163
163
|
...arbitraryFields,
|
|
164
164
|
transactionId,
|
|
165
165
|
amount,
|
|
166
|
-
currency,
|
|
166
|
+
currency: currencyCode,
|
|
167
167
|
refno,
|
|
168
168
|
refno2,
|
|
169
169
|
autoSettle: false,
|
|
@@ -174,14 +174,14 @@ const Datatrans: IPaymentAdapter = {
|
|
|
174
174
|
|
|
175
175
|
const isTransactionAmountValid = (transaction: StatusResponseSuccess): boolean => {
|
|
176
176
|
const { order } = context;
|
|
177
|
-
const {
|
|
177
|
+
const { currencyCode, amount } = roundedAmountFromOrder(order);
|
|
178
178
|
if (
|
|
179
|
-
transaction.currency !==
|
|
179
|
+
transaction.currency !== currencyCode ||
|
|
180
180
|
(transaction.detail.authorize as any)?.amount !== amount
|
|
181
181
|
) {
|
|
182
182
|
logger.info(
|
|
183
|
-
`currency: ${transaction.currency} === ${
|
|
184
|
-
transaction.currency ===
|
|
183
|
+
`currency: ${transaction.currency} === ${currencyCode} => ${
|
|
184
|
+
transaction.currency === currencyCode
|
|
185
185
|
}, amount: ${(transaction.detail.authorize as any)?.amount} === ${amount} => ${
|
|
186
186
|
(transaction.detail.authorize as any)?.amount === amount
|
|
187
187
|
}`,
|
|
@@ -208,14 +208,14 @@ const Datatrans: IPaymentAdapter = {
|
|
|
208
208
|
|
|
209
209
|
const settle = async ({ transactionId, refno, refno2, extensions }): Promise<boolean> => {
|
|
210
210
|
const { order } = context;
|
|
211
|
-
const {
|
|
211
|
+
const { currencyCode, amount } = roundedAmountFromOrder(order);
|
|
212
212
|
const splits = await getMarketplaceSplits();
|
|
213
213
|
const result = await api().settle({
|
|
214
214
|
transactionId,
|
|
215
215
|
amount,
|
|
216
216
|
refno,
|
|
217
217
|
refno2,
|
|
218
|
-
currency,
|
|
218
|
+
currency: currencyCode,
|
|
219
219
|
marketplace: splits.length
|
|
220
220
|
? {
|
|
221
221
|
splits,
|
|
@@ -263,12 +263,14 @@ const Datatrans: IPaymentAdapter = {
|
|
|
263
263
|
);
|
|
264
264
|
const userId = order?.userId || context?.userId;
|
|
265
265
|
const refno2 = userId;
|
|
266
|
-
const price: { amount?: number;
|
|
266
|
+
const price: { amount?: number; currencyCode?: string } = order
|
|
267
|
+
? roundedAmountFromOrder(order)
|
|
268
|
+
: {};
|
|
267
269
|
|
|
268
270
|
if (useSecureFields) {
|
|
269
271
|
const result = await api().secureFields({
|
|
270
272
|
...arbitraryFields,
|
|
271
|
-
currency: price.
|
|
273
|
+
currency: price.currencyCode || 'CHF',
|
|
272
274
|
refno,
|
|
273
275
|
refno2,
|
|
274
276
|
customer: {
|
|
@@ -281,7 +283,7 @@ const Datatrans: IPaymentAdapter = {
|
|
|
281
283
|
}
|
|
282
284
|
const result = await api().init({
|
|
283
285
|
...arbitraryFields,
|
|
284
|
-
currency: price.
|
|
286
|
+
currency: price.currencyCode || 'CHF',
|
|
285
287
|
refno,
|
|
286
288
|
refno2,
|
|
287
289
|
customer: {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { OrderPricingSheet } from '@unchainedshop/core';
|
|
2
2
|
import { Order } from '@unchainedshop/core-orders';
|
|
3
3
|
|
|
4
|
-
const roundedAmountFromOrder = (order: Order): {
|
|
4
|
+
const roundedAmountFromOrder = (order: Order): { currencyCode: string; amount: number } => {
|
|
5
5
|
const pricing = OrderPricingSheet({
|
|
6
6
|
calculation: order.calculation,
|
|
7
|
-
|
|
7
|
+
currencyCode: order.currencyCode,
|
|
8
8
|
});
|
|
9
|
-
const {
|
|
9
|
+
const { currencyCode, amount } = pricing.total({ useNetPrice: false });
|
|
10
10
|
return {
|
|
11
|
-
|
|
11
|
+
currencyCode,
|
|
12
12
|
amount: Math.round(amount),
|
|
13
13
|
};
|
|
14
14
|
};
|
|
@@ -17,7 +17,7 @@ try {
|
|
|
17
17
|
/* */
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const logger = createLogger('unchained:core-payment');
|
|
20
|
+
const logger = createLogger('unchained:core-payment:paypal-checkout');
|
|
21
21
|
|
|
22
22
|
const { PAYPAL_CLIENT_ID, PAYPAL_SECRET, PAYPAL_ENVIRONMENT = 'sandbox' } = process.env;
|
|
23
23
|
|
|
@@ -79,7 +79,6 @@ const PaypalCheckout: IPaymentAdapter = {
|
|
|
79
79
|
const { order } = context;
|
|
80
80
|
|
|
81
81
|
if (!orderID) {
|
|
82
|
-
logger.warn('Paypal Native Plugin: PRICE MATCH');
|
|
83
82
|
throw new Error('You have to provide orderID in paymentContext');
|
|
84
83
|
}
|
|
85
84
|
|
|
@@ -90,27 +89,23 @@ const PaypalCheckout: IPaymentAdapter = {
|
|
|
90
89
|
|
|
91
90
|
const pricing = OrderPricingSheet({
|
|
92
91
|
calculation: order.calculation,
|
|
93
|
-
|
|
92
|
+
currencyCode: order.currencyCode,
|
|
94
93
|
});
|
|
95
94
|
const ourTotal = (pricing.total({ useNetPrice: false }).amount / 100).toFixed(2);
|
|
96
95
|
const paypalTotal = paypalOrder.result.purchase_units[0].amount.value;
|
|
97
96
|
|
|
98
97
|
if (ourTotal === paypalTotal) {
|
|
99
|
-
logger.info('Paypal Native Plugin: PRICE MATCH');
|
|
100
98
|
return order;
|
|
101
99
|
}
|
|
102
100
|
|
|
103
|
-
logger.warn(
|
|
104
|
-
'Paypal Native Plugin: Missmatch PAYPAL ORDER',
|
|
105
|
-
JSON.stringify(paypalOrder.result, null, 2),
|
|
106
|
-
);
|
|
101
|
+
logger.warn('Missmatch PAYPAL ORDER', JSON.stringify(paypalOrder.result, null, 2));
|
|
107
102
|
|
|
108
|
-
logger.debug('
|
|
109
|
-
logger.debug('
|
|
103
|
+
logger.debug('OUR ORDER', order);
|
|
104
|
+
logger.debug('OUR PRICE', pricing);
|
|
110
105
|
|
|
111
106
|
throw new Error(`Payment mismatch`);
|
|
112
107
|
} catch (e) {
|
|
113
|
-
logger.warn(
|
|
108
|
+
logger.warn(e);
|
|
114
109
|
throw new Error(e);
|
|
115
110
|
}
|
|
116
111
|
},
|
|
@@ -17,7 +17,7 @@ export enum GatewayObjectStatus {
|
|
|
17
17
|
uncaptured = '_',
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export
|
|
20
|
+
export interface GatewayObject {
|
|
21
21
|
status: GatewayObjectStatus;
|
|
22
22
|
currency: string;
|
|
23
23
|
amount: number;
|
|
@@ -27,7 +27,7 @@ export type GatewayObject = {
|
|
|
27
27
|
id: string;
|
|
28
28
|
}[];
|
|
29
29
|
}[];
|
|
30
|
-
}
|
|
30
|
+
}
|
|
31
31
|
|
|
32
32
|
export type TransactionObject = any;
|
|
33
33
|
|
|
@@ -5,7 +5,7 @@ const { MOCK_APIS } = process.env;
|
|
|
5
5
|
const logger = createLogger('unchained:payrexx');
|
|
6
6
|
|
|
7
7
|
export default (
|
|
8
|
-
baseUrl
|
|
8
|
+
baseUrl = 'https://api.payrexx.com/v1.0/',
|
|
9
9
|
instance: string = null,
|
|
10
10
|
secret: string = null,
|
|
11
11
|
): ((path: string, method: 'GET' | 'DELETE' | 'PUT' | 'POST', data?: any) => Promise<Response>) => {
|
|
@@ -59,7 +59,7 @@ const Payrexx: IPaymentAdapter = {
|
|
|
59
59
|
// Order Checkout signing (One-time payment)
|
|
60
60
|
const pricing = OrderPricingSheet({
|
|
61
61
|
calculation: order.calculation,
|
|
62
|
-
|
|
62
|
+
currencyCode: order.currencyCode,
|
|
63
63
|
});
|
|
64
64
|
const gatewayObject = mapOrderDataToGatewayObject(
|
|
65
65
|
{ order, orderPayment, pricing },
|
|
@@ -183,9 +183,9 @@ const Payrexx: IPaymentAdapter = {
|
|
|
183
183
|
|
|
184
184
|
const pricing = OrderPricingSheet({
|
|
185
185
|
calculation: order.calculation,
|
|
186
|
-
|
|
186
|
+
currencyCode: order.currencyCode,
|
|
187
187
|
});
|
|
188
|
-
const {
|
|
188
|
+
const { currencyCode, amount } = pricing.total({ useNetPrice: false });
|
|
189
189
|
|
|
190
190
|
if (
|
|
191
191
|
// gatewayObject.status === 'authorized' || // authorized is only used for tokenization!
|
|
@@ -194,7 +194,7 @@ const Payrexx: IPaymentAdapter = {
|
|
|
194
194
|
) {
|
|
195
195
|
try {
|
|
196
196
|
if (
|
|
197
|
-
gatewayObject.currency !==
|
|
197
|
+
gatewayObject.currency !== currencyCode.toUpperCase() ||
|
|
198
198
|
gatewayObject.amount !== Math.round(amount)
|
|
199
199
|
) {
|
|
200
200
|
throw new Error('The price has changed since the intent has been created');
|
|
@@ -14,7 +14,7 @@ const getRedirects = () => {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export const mapOrderDataToGatewayObject = ({ order, orderPayment, pricing }, options = {}) => {
|
|
17
|
-
const {
|
|
17
|
+
const { currencyCode, amount } = pricing.total({ useNetPrice: false });
|
|
18
18
|
|
|
19
19
|
const customerData = {};
|
|
20
20
|
if (order.contact?.emailAddress) {
|
|
@@ -29,7 +29,7 @@ export const mapOrderDataToGatewayObject = ({ order, orderPayment, pricing }, op
|
|
|
29
29
|
|
|
30
30
|
const gatewayObject = {
|
|
31
31
|
amount: Math.round(amount),
|
|
32
|
-
currency:
|
|
32
|
+
currency: currencyCode.toUpperCase(),
|
|
33
33
|
purpose: encodeURIComponent(`${process.env.EMAIL_WEBSITE_NAME || 'Unchained'} #${order._id}`),
|
|
34
34
|
reservation: true,
|
|
35
35
|
skipResultPage: true,
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
const API_BASE_URL = 'https://checkout.postfinance.ch/api';
|
|
4
|
+
|
|
5
|
+
interface ApiConfig {
|
|
6
|
+
spaceId: number;
|
|
7
|
+
userId: number;
|
|
8
|
+
apiSecret: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface MacHeaders {
|
|
12
|
+
'x-mac-version': string;
|
|
13
|
+
'x-mac-userid': string;
|
|
14
|
+
'x-mac-timestamp': string;
|
|
15
|
+
'x-mac-value': string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class PostFinanceApiClient {
|
|
19
|
+
private config: ApiConfig;
|
|
20
|
+
|
|
21
|
+
constructor(config: ApiConfig) {
|
|
22
|
+
this.config = config;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private generateMacHeaders(method: string, path: string): MacHeaders {
|
|
26
|
+
const version = '1';
|
|
27
|
+
const timestamp = Math.floor(Date.now() / 1000).toString();
|
|
28
|
+
const userId = this.config.userId.toString();
|
|
29
|
+
|
|
30
|
+
// Use path as-is since it already includes /api from the URL
|
|
31
|
+
const resourcePath = path;
|
|
32
|
+
|
|
33
|
+
const dataToSign = [version, userId, timestamp, method, resourcePath].join('|');
|
|
34
|
+
|
|
35
|
+
const macValue = crypto
|
|
36
|
+
.createHmac('sha512', Buffer.from(this.config.apiSecret, 'base64'))
|
|
37
|
+
.update(dataToSign, 'utf8')
|
|
38
|
+
.digest('base64');
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
'x-mac-version': version,
|
|
42
|
+
'x-mac-userid': userId,
|
|
43
|
+
'x-mac-timestamp': timestamp,
|
|
44
|
+
'x-mac-value': macValue,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async request<T>(method: string, endpoint: string, body?: any): Promise<T> {
|
|
49
|
+
const url = `${API_BASE_URL}${endpoint}`;
|
|
50
|
+
const urlObj = new URL(url);
|
|
51
|
+
// Include both pathname and search (query parameters) for MAC signature
|
|
52
|
+
const pathWithQuery = urlObj.pathname + urlObj.search;
|
|
53
|
+
const macHeaders = this.generateMacHeaders(method, pathWithQuery);
|
|
54
|
+
|
|
55
|
+
const headers: Record<string, string> = {
|
|
56
|
+
...macHeaders,
|
|
57
|
+
'Content-Type': 'application/json',
|
|
58
|
+
Accept: 'application/json',
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const options: RequestInit = {
|
|
62
|
+
method,
|
|
63
|
+
headers,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
if (body && method !== 'GET') {
|
|
67
|
+
options.body = JSON.stringify(body);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const response = await fetch(url, options);
|
|
71
|
+
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
const errorData = await response.json().catch(() => ({}));
|
|
74
|
+
throw new Error(
|
|
75
|
+
`PostFinance API error: ${response.status} ${response.statusText} ${JSON.stringify(errorData)}`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const responseText = await response.text();
|
|
80
|
+
const contentType = response.headers.get('content-type');
|
|
81
|
+
|
|
82
|
+
if (contentType && contentType.includes('application/json')) {
|
|
83
|
+
try {
|
|
84
|
+
return JSON.parse(responseText);
|
|
85
|
+
} catch {
|
|
86
|
+
// If JSON parsing fails but content-type is json, return as text
|
|
87
|
+
// This handles PostFinance's payment-page-url endpoint that returns plain text with json content-type
|
|
88
|
+
return responseText as any;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
return responseText as any;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get<T>(endpoint: string): Promise<T> {
|
|
96
|
+
return this.request<T>('GET', endpoint);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
post<T>(endpoint: string, body: any): Promise<T> {
|
|
100
|
+
return this.request<T>('POST', endpoint, body);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
patch<T>(endpoint: string, body: any): Promise<T> {
|
|
104
|
+
return this.request<T>('PATCH', endpoint, body);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// PostFinance Checkout API Types
|
|
2
|
+
|
|
3
|
+
export enum TransactionState {
|
|
4
|
+
CREATE = 'CREATE',
|
|
5
|
+
PENDING = 'PENDING',
|
|
6
|
+
CONFIRMED = 'CONFIRMED',
|
|
7
|
+
PROCESSING = 'PROCESSING',
|
|
8
|
+
FAILED = 'FAILED',
|
|
9
|
+
AUTHORIZED = 'AUTHORIZED',
|
|
10
|
+
VOIDED = 'VOIDED',
|
|
11
|
+
COMPLETED = 'COMPLETED',
|
|
12
|
+
FULFILL = 'FULFILL',
|
|
13
|
+
DECLINE = 'DECLINE',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export enum TokenizationMode {
|
|
17
|
+
FORCE_UPDATE = 'FORCE_UPDATE',
|
|
18
|
+
ALLOW = 'ALLOW',
|
|
19
|
+
ALLOW_ONE_CLICK_PAYMENT = 'ALLOW_ONE_CLICK_PAYMENT',
|
|
20
|
+
DENY = 'DENY',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export enum TransactionCompletionBehavior {
|
|
24
|
+
COMPLETE_IMMEDIATELY = 'COMPLETE_IMMEDIATELY',
|
|
25
|
+
COMPLETE_DEFERRED = 'COMPLETE_DEFERRED',
|
|
26
|
+
USE_CONFIGURATION = 'USE_CONFIGURATION',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export enum LineItemType {
|
|
30
|
+
SHIPPING = 'SHIPPING',
|
|
31
|
+
DISCOUNT = 'DISCOUNT',
|
|
32
|
+
FEE = 'FEE',
|
|
33
|
+
PRODUCT = 'PRODUCT',
|
|
34
|
+
TIP = 'TIP',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export enum RefundType {
|
|
38
|
+
MERCHANT_INITIATED_ONLINE = 'MERCHANT_INITIATED_ONLINE',
|
|
39
|
+
MERCHANT_INITIATED_OFFLINE = 'MERCHANT_INITIATED_OFFLINE',
|
|
40
|
+
CUSTOMER_INITIATED_AUTOMATIC = 'CUSTOMER_INITIATED_AUTOMATIC',
|
|
41
|
+
CUSTOMER_INITIATED_MANUAL = 'CUSTOMER_INITIATED_MANUAL',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export enum CreationEntityState {
|
|
45
|
+
CREATE = 'CREATE',
|
|
46
|
+
ACTIVE = 'ACTIVE',
|
|
47
|
+
INACTIVE = 'INACTIVE',
|
|
48
|
+
DELETING = 'DELETING',
|
|
49
|
+
DELETED = 'DELETED',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface LineItem {
|
|
53
|
+
name: string;
|
|
54
|
+
type: LineItemType;
|
|
55
|
+
quantity: number;
|
|
56
|
+
uniqueId: string;
|
|
57
|
+
amountIncludingTax: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface TransactionCreate {
|
|
61
|
+
currency: string;
|
|
62
|
+
customerId?: string;
|
|
63
|
+
tokenizationMode?: TokenizationMode;
|
|
64
|
+
completionBehavior?: TransactionCompletionBehavior;
|
|
65
|
+
lineItems?: LineItem[];
|
|
66
|
+
successUrl?: string;
|
|
67
|
+
failedUrl?: string;
|
|
68
|
+
metaData?: Record<string, any>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface Transaction {
|
|
72
|
+
id: number;
|
|
73
|
+
state: TransactionState;
|
|
74
|
+
currency: string;
|
|
75
|
+
completedAmount?: number;
|
|
76
|
+
authorizationAmount?: number;
|
|
77
|
+
metaData?: Record<string, any>;
|
|
78
|
+
token?: {
|
|
79
|
+
id: number;
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface TransactionCompletion {
|
|
85
|
+
id: number;
|
|
86
|
+
state: string;
|
|
87
|
+
transaction: number;
|
|
88
|
+
linkedTransaction?: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface Token {
|
|
92
|
+
id: number;
|
|
93
|
+
state: CreationEntityState;
|
|
94
|
+
name?: string;
|
|
95
|
+
customerId?: string;
|
|
96
|
+
enabledForOneClickPayment?: boolean;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface RefundCreate {
|
|
100
|
+
transaction: number;
|
|
101
|
+
externalId: string;
|
|
102
|
+
amount: number;
|
|
103
|
+
type: RefundType;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface Refund {
|
|
107
|
+
id: number;
|
|
108
|
+
state: string;
|
|
109
|
+
amount: number;
|
|
110
|
+
transaction: number;
|
|
111
|
+
}
|
|
@@ -1,91 +1,55 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PostFinanceApiClient } from './api-client.js';
|
|
2
|
+
import {
|
|
3
|
+
Transaction,
|
|
4
|
+
TransactionCreate,
|
|
5
|
+
TransactionCompletion,
|
|
6
|
+
Token,
|
|
7
|
+
RefundCreate,
|
|
8
|
+
RefundType,
|
|
9
|
+
} from './api-types.js';
|
|
2
10
|
|
|
3
|
-
const { PostFinanceCheckout } = pf;
|
|
4
11
|
const { PFCHECKOUT_SPACE_ID, PFCHECKOUT_USER_ID, PFCHECKOUT_SECRET } = process.env;
|
|
5
12
|
const SPACE_ID = parseInt(PFCHECKOUT_SPACE_ID as string, 10);
|
|
6
13
|
const USER_ID = parseInt(PFCHECKOUT_USER_ID as string, 10);
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
space_id: SPACE_ID,
|
|
11
|
-
user_id: USER_ID,
|
|
12
|
-
api_secret: PFCHECKOUT_SECRET,
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const getTransactionService = () => {
|
|
17
|
-
return new PostFinanceCheckout.api.TransactionService(getConfig());
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const getTransactionCompletionService = () => {
|
|
21
|
-
return new PostFinanceCheckout.api.TransactionCompletionService(getConfig());
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const getTransactionVoidService = () => {
|
|
25
|
-
return new PostFinanceCheckout.api.TransactionVoidService(getConfig());
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const getRefundService = () => {
|
|
29
|
-
return new PostFinanceCheckout.api.RefundService(getConfig());
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const getTransactionPaymentPageService = () => {
|
|
33
|
-
return new PostFinanceCheckout.api.TransactionPaymentPageService(getConfig());
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const getTransactionIframeService = () => {
|
|
37
|
-
return new PostFinanceCheckout.api.TransactionIframeService(getConfig());
|
|
38
|
-
};
|
|
15
|
+
let apiClient: PostFinanceApiClient;
|
|
39
16
|
|
|
40
|
-
const
|
|
41
|
-
|
|
17
|
+
const getApiClient = () => {
|
|
18
|
+
if (!apiClient) {
|
|
19
|
+
apiClient = new PostFinanceApiClient({
|
|
20
|
+
spaceId: SPACE_ID,
|
|
21
|
+
userId: USER_ID,
|
|
22
|
+
apiSecret: PFCHECKOUT_SECRET as string,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return apiClient;
|
|
42
26
|
};
|
|
43
27
|
|
|
44
|
-
const
|
|
45
|
-
|
|
28
|
+
export const getTransaction = async (transactionId: string): Promise<Transaction> => {
|
|
29
|
+
const client = getApiClient();
|
|
30
|
+
return client.get<Transaction>(`/transaction/read?spaceId=${SPACE_ID}&id=${transactionId}`);
|
|
46
31
|
};
|
|
47
32
|
|
|
48
|
-
export const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const transactionService = getTransactionService();
|
|
52
|
-
const transaction = await transactionService.read(SPACE_ID, parseInt(transactionId, 10));
|
|
53
|
-
return transaction.body;
|
|
33
|
+
export const getTransactionCompletion = async (id: string): Promise<TransactionCompletion> => {
|
|
34
|
+
const client = getApiClient();
|
|
35
|
+
return client.get<TransactionCompletion>(`/transaction-completion/read?spaceId=${SPACE_ID}&id=${id}`);
|
|
54
36
|
};
|
|
55
37
|
|
|
56
|
-
export const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const transactionCompletionService = getTransactionCompletionService();
|
|
60
|
-
const transactionCompletion = await transactionCompletionService.read(
|
|
61
|
-
SPACE_ID,
|
|
62
|
-
parseInt(entityId, 10),
|
|
63
|
-
);
|
|
64
|
-
return transactionCompletion.body;
|
|
38
|
+
export const getToken = async (spaceId: number, tokenId: number): Promise<Token> => {
|
|
39
|
+
const client = getApiClient();
|
|
40
|
+
return client.get<Token>(`/token/read?spaceId=${spaceId || SPACE_ID}&id=${tokenId}`);
|
|
65
41
|
};
|
|
66
42
|
|
|
67
|
-
export const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const tokenService = getTokenService();
|
|
72
|
-
const token = await tokenService.read(spaceId || SPACE_ID, tokenId);
|
|
73
|
-
return token.body;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const createTransaction = async (
|
|
77
|
-
transaction: pf.PostFinanceCheckout.model.TransactionCreate,
|
|
78
|
-
): Promise<number | null> => {
|
|
79
|
-
const transactionService = getTransactionService();
|
|
80
|
-
const transactionCreateRes = await transactionService.create(SPACE_ID, transaction);
|
|
81
|
-
const transactionCreate = transactionCreateRes.body;
|
|
82
|
-
return transactionCreate.id || null;
|
|
43
|
+
export const createTransaction = async (transaction: TransactionCreate): Promise<number | null> => {
|
|
44
|
+
const client = getApiClient();
|
|
45
|
+
const result = await client.post<Transaction>(`/transaction/create?spaceId=${SPACE_ID}`, transaction);
|
|
46
|
+
return result.id || null;
|
|
83
47
|
};
|
|
84
48
|
|
|
85
49
|
export const voidTransaction = async (transactionId: string): Promise<boolean> => {
|
|
86
|
-
const
|
|
50
|
+
const client = getApiClient();
|
|
87
51
|
try {
|
|
88
|
-
await
|
|
52
|
+
await client.post(`/transaction-void/voidOnline?spaceId=${SPACE_ID}&id=${transactionId}`, {});
|
|
89
53
|
return true;
|
|
90
54
|
} catch {
|
|
91
55
|
return false;
|
|
@@ -97,15 +61,15 @@ export const refundTransaction = async (
|
|
|
97
61
|
orderId: string,
|
|
98
62
|
amount: number,
|
|
99
63
|
): Promise<boolean> => {
|
|
100
|
-
const
|
|
101
|
-
const refund:
|
|
64
|
+
const client = getApiClient();
|
|
65
|
+
const refund: RefundCreate = {
|
|
102
66
|
transaction: parseInt(transactionId, 10),
|
|
103
67
|
externalId: orderId,
|
|
104
68
|
amount,
|
|
105
|
-
type:
|
|
69
|
+
type: RefundType.MERCHANT_INITIATED_ONLINE,
|
|
106
70
|
};
|
|
107
71
|
try {
|
|
108
|
-
await
|
|
72
|
+
await client.post(`/refund/refund?spaceId=${SPACE_ID}`, refund);
|
|
109
73
|
return true;
|
|
110
74
|
} catch {
|
|
111
75
|
return false;
|
|
@@ -113,9 +77,12 @@ export const refundTransaction = async (
|
|
|
113
77
|
};
|
|
114
78
|
|
|
115
79
|
export const confirmDeferredTransaction = async (transactionId: string): Promise<boolean> => {
|
|
116
|
-
const
|
|
80
|
+
const client = getApiClient();
|
|
117
81
|
try {
|
|
118
|
-
await
|
|
82
|
+
await client.post(
|
|
83
|
+
`/transaction-completion/completeOnline?spaceId=${SPACE_ID}&transactionId=${transactionId}`,
|
|
84
|
+
{},
|
|
85
|
+
);
|
|
119
86
|
return true;
|
|
120
87
|
} catch {
|
|
121
88
|
return false;
|
|
@@ -123,19 +90,25 @@ export const confirmDeferredTransaction = async (transactionId: string): Promise
|
|
|
123
90
|
};
|
|
124
91
|
|
|
125
92
|
export const getPaymentPageUrl = async (transactionId: number): Promise<string> => {
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
|
|
93
|
+
const client = getApiClient();
|
|
94
|
+
const result = await client.get<string>(
|
|
95
|
+
`/transaction-payment-page/payment-page-url?spaceId=${SPACE_ID}&id=${transactionId}`,
|
|
96
|
+
);
|
|
97
|
+
return result;
|
|
129
98
|
};
|
|
130
99
|
|
|
131
100
|
export const getLightboxJavascriptUrl = async (transactionId: number): Promise<string> => {
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
|
|
101
|
+
const client = getApiClient();
|
|
102
|
+
const result = await client.get<string>(
|
|
103
|
+
`/transaction-lightbox/javascript-url?spaceId=${SPACE_ID}&id=${transactionId}`,
|
|
104
|
+
);
|
|
105
|
+
return result;
|
|
135
106
|
};
|
|
136
107
|
|
|
137
108
|
export const getIframeJavascriptUrl = async (transactionId: number): Promise<string> => {
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
|
|
109
|
+
const client = getApiClient();
|
|
110
|
+
const result = await client.get<string>(
|
|
111
|
+
`/transaction-iframe/javascript-url?spaceId=${SPACE_ID}&id=${transactionId}`,
|
|
112
|
+
);
|
|
113
|
+
return result;
|
|
141
114
|
};
|