@unchainedshop/plugins 4.0.0-rc.2 → 4.0.0-rc.21
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/accounts/google-oauth.d.ts +4 -0
- package/lib/accounts/google-oauth.d.ts.map +1 -0
- package/lib/accounts/google-oauth.js +145 -0
- package/lib/accounts/google-oauth.js.map +1 -0
- package/lib/accounts/linkedin-oauth.d.ts +4 -0
- package/lib/accounts/linkedin-oauth.d.ts.map +1 -0
- package/lib/accounts/linkedin-oauth.js +82 -0
- package/lib/accounts/linkedin-oauth.js.map +1 -0
- package/lib/delivery/send-message.js.map +1 -1
- package/lib/enrollments/licensed.js +15 -2
- package/lib/enrollments/licensed.js.map +1 -1
- package/lib/files/gridfs/adapter.d.ts.map +1 -1
- package/lib/files/gridfs/adapter.js +19 -11
- package/lib/files/gridfs/adapter.js.map +1 -1
- package/lib/files/gridfs/gridfs-adapter.d.ts +3 -0
- package/lib/files/gridfs/gridfs-adapter.d.ts.map +1 -0
- package/lib/files/gridfs/gridfs-adapter.js +97 -0
- package/lib/files/gridfs/gridfs-adapter.js.map +1 -0
- package/lib/files/gridfs/gridfs-webhook.d.ts +11 -0
- package/lib/files/gridfs/gridfs-webhook.d.ts.map +1 -0
- package/lib/files/gridfs/gridfs-webhook.js +84 -0
- package/lib/files/gridfs/gridfs-webhook.js.map +1 -0
- package/lib/files/gridfs/handler-express.d.ts.map +1 -1
- package/lib/files/gridfs/handler-express.js +27 -24
- 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 +57 -14
- package/lib/files/gridfs/handler-fastify.js.map +1 -1
- package/lib/files/gridfs/module.d.ts +4 -4
- package/lib/files/gridfs/module.d.ts.map +1 -1
- package/lib/files/gridfs/module.js +2 -2
- package/lib/files/gridfs/module.js.map +1 -1
- package/lib/files/minio/handler-express.d.ts.map +1 -1
- package/lib/files/minio/handler-express.js +4 -7
- package/lib/files/minio/handler-express.js.map +1 -1
- package/lib/files/minio/handler-fastify.js +2 -2
- package/lib/files/minio/handler-fastify.js.map +1 -1
- package/lib/files/minio/index.d.ts +1 -1
- package/lib/files/minio/index.d.ts.map +1 -1
- package/lib/files/minio/index.js +7 -7
- package/lib/files/minio/index.js.map +1 -1
- package/lib/files/minio/minio-adapter.d.ts +6 -0
- package/lib/files/minio/minio-adapter.d.ts.map +1 -0
- package/lib/files/minio/minio-adapter.js +181 -0
- package/lib/files/minio/minio-adapter.js.map +1 -0
- package/lib/files/minio/minio-webhook.d.ts +2 -0
- package/lib/files/minio/minio-webhook.d.ts.map +1 -0
- package/lib/files/minio/minio-webhook.js +33 -0
- package/lib/files/minio/minio-webhook.js.map +1 -0
- package/lib/filters/local-search.js +1 -1
- package/lib/filters/local-search.js.map +1 -1
- package/lib/payment/apple-iap/adapter.js +12 -10
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +1 -1
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts.map +1 -1
- package/lib/payment/apple-iap/handler-express.d.ts.map +1 -1
- package/lib/payment/apple-iap/handler-express.js +14 -10
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.d.ts.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +15 -8
- package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +1 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +17 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
- package/lib/payment/apple-iap/module.d.ts +4 -4
- package/lib/payment/apple-iap/module.d.ts.map +1 -1
- package/lib/payment/apple-iap/module.js +4 -2
- package/lib/payment/apple-iap/module.js.map +1 -1
- package/lib/payment/braintree.js +3 -1
- package/lib/payment/braintree.js.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
- package/lib/payment/cryptopay/derive-btc-address.d.ts.map +1 -1
- package/lib/payment/cryptopay/derive-btc-address.js +2 -3
- package/lib/payment/cryptopay/derive-btc-address.js.map +1 -1
- package/lib/payment/cryptopay/derive-eth-address.d.ts.map +1 -1
- package/lib/payment/cryptopay/derive-eth-address.js +5 -3
- package/lib/payment/cryptopay/derive-eth-address.js.map +1 -1
- package/lib/payment/cryptopay/handle-webhook.js +2 -2
- 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 -7
- 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 +1 -1
- package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
- package/lib/payment/cryptopay/middleware.d.ts +2 -0
- package/lib/payment/cryptopay/middleware.d.ts.map +1 -0
- package/lib/payment/cryptopay/middleware.js +75 -0
- package/lib/payment/cryptopay/middleware.js.map +1 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +25 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +1 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.js +75 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +1 -0
- package/lib/payment/cryptopay/module.d.ts +2 -2
- package/lib/payment/cryptopay/module.d.ts.map +1 -1
- package/lib/payment/cryptopay/module.js +4 -4
- 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 +18 -4
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/handler-express.js +13 -11
- package/lib/payment/datatrans-v2/handler-express.js.map +1 -1
- package/lib/payment/datatrans-v2/handler-fastify.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/handler-fastify.js +11 -5
- package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -1
- package/lib/payment/datatrans-v2/index.js +63 -37
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/middleware.d.ts +2 -0
- package/lib/payment/datatrans-v2/middleware.d.ts.map +1 -0
- package/lib/payment/datatrans-v2/middleware.js +68 -0
- package/lib/payment/datatrans-v2/middleware.js.map +1 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +1 -1
- package/lib/payment/datatrans-v2/parseRegistrationData.d.ts.map +1 -1
- package/lib/payment/paypal-checkout.js +8 -8
- package/lib/payment/paypal-checkout.js.map +1 -1
- package/lib/payment/payrexx/api/index.d.ts +1 -1
- package/lib/payment/payrexx/api/index.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
- package/lib/payment/payrexx/handler-express.d.ts.map +1 -1
- package/lib/payment/payrexx/handler-express.js +15 -15
- package/lib/payment/payrexx/handler-express.js.map +1 -1
- package/lib/payment/payrexx/handler-fastify.js +23 -15
- package/lib/payment/payrexx/handler-fastify.js.map +1 -1
- package/lib/payment/payrexx/index.js +21 -15
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/payrexx/middleware.d.ts +2 -0
- package/lib/payment/payrexx/middleware.d.ts.map +1 -0
- package/lib/payment/payrexx/middleware.js +86 -0
- package/lib/payment/payrexx/middleware.js.map +1 -0
- 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 +10 -11
- 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 +10 -8
- 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 +44 -32
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/middleware.d.ts +2 -0
- package/lib/payment/postfinance-checkout/middleware.d.ts.map +1 -0
- package/lib/payment/postfinance-checkout/middleware.js +38 -0
- package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
- 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 +3 -4
- 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 +9 -0
- package/lib/payment/saferpay/adapter.js.map +1 -1
- package/lib/payment/saferpay/handler-express.d.ts.map +1 -1
- package/lib/payment/saferpay/handler-express.js +10 -8
- package/lib/payment/saferpay/handler-express.js.map +1 -1
- package/lib/payment/saferpay/handler-fastify.d.ts.map +1 -1
- package/lib/payment/saferpay/handler-fastify.js +11 -5
- package/lib/payment/saferpay/handler-fastify.js.map +1 -1
- package/lib/payment/saferpay/middleware.d.ts +2 -0
- package/lib/payment/saferpay/middleware.d.ts.map +1 -0
- package/lib/payment/saferpay/middleware.js +57 -0
- package/lib/payment/saferpay/middleware.js.map +1 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +10 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +1 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +24 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +1 -0
- package/lib/payment/saferpay/module.d.ts +2 -2
- package/lib/payment/stripe/handler-express.js +25 -17
- package/lib/payment/stripe/handler-express.js.map +1 -1
- package/lib/payment/stripe/handler-fastify.d.ts.map +1 -1
- package/lib/payment/stripe/handler-fastify.js +33 -12
- package/lib/payment/stripe/handler-fastify.js.map +1 -1
- package/lib/payment/stripe/index.js +19 -13
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/middleware.d.ts +6 -0
- package/lib/payment/stripe/middleware.d.ts.map +1 -0
- package/lib/payment/stripe/middleware.js +114 -0
- package/lib/payment/stripe/middleware.js.map +1 -0
- package/lib/payment/stripe/stripe.d.ts +2 -2
- package/lib/payment/stripe/stripe.d.ts.map +1 -1
- package/lib/payment/stripe/stripe.js +14 -11
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/lib/plugins-index.d.ts +48 -0
- package/lib/plugins-index.d.ts.map +1 -0
- package/lib/plugins-index.js +107 -0
- package/lib/plugins-index.js.map +1 -0
- package/lib/presets/all.d.ts +9 -7
- 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 +13 -20
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/order-discount.d.ts.map +1 -1
- package/lib/pricing/order-discount.js +5 -3
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-round.d.ts.map +1 -1
- package/lib/pricing/order-round.js +4 -3
- package/lib/pricing/order-round.js.map +1 -1
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +26 -2
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +3 -3
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/pricing/product-swiss-tax.d.ts +1 -5
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +26 -22
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/pricing/tax/ch.d.ts +7 -2
- package/lib/pricing/tax/ch.d.ts.map +1 -1
- package/lib/pricing/tax/ch.js +16 -1
- package/lib/pricing/tax/ch.js.map +1 -1
- package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts +7 -0
- package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts.map +1 -0
- package/lib/pricing/utils/isDeliveryAddressInCountry.js +13 -0
- package/lib/pricing/utils/isDeliveryAddressInCountry.js.map +1 -0
- package/lib/warehousing/eth-minter.js +23 -11
- 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.d.ts +1 -1
- package/lib/worker/bulk-import.d.ts.map +1 -1
- package/lib/worker/bulk-import.js +11 -33
- 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/email.d.ts.map +1 -1
- package/lib/worker/email.js +25 -7
- package/lib/worker/email.js.map +1 -1
- package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
- package/lib/worker/enrollment-order-generator.js +7 -49
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/error-notifications.js +1 -1
- package/lib/worker/error-notifications.js.map +1 -1
- package/lib/worker/export-token.d.ts.map +1 -1
- package/lib/worker/export-token.js +0 -1
- package/lib/worker/export-token.js.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/message.js +4 -2
- package/lib/worker/message.js.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 +60 -0
- package/lib/worker/twilio.js.map +1 -0
- package/package.json +29 -45
- package/src/delivery/send-message.ts +1 -1
- package/src/enrollments/licensed.ts +15 -2
- package/src/files/gridfs/adapter.ts +24 -10
- package/src/files/gridfs/handler-express.ts +32 -24
- package/src/files/gridfs/handler-fastify.ts +63 -15
- package/src/files/gridfs/module.ts +7 -2
- package/src/files/minio/handler-express.ts +4 -7
- package/src/files/minio/handler-fastify.ts +2 -2
- package/src/files/minio/index.ts +16 -16
- package/src/filters/local-search.ts +1 -1
- package/src/payment/apple-iap/adapter.ts +12 -14
- package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +1 -1
- package/src/payment/apple-iap/handler-express.ts +17 -11
- package/src/payment/apple-iap/handler-fastify.ts +19 -9
- package/src/payment/apple-iap/module.ts +9 -4
- package/src/payment/braintree.ts +4 -1
- package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -1
- package/src/payment/cryptopay/derive-btc-address.ts +1 -3
- package/src/payment/cryptopay/derive-eth-address.ts +5 -3
- package/src/payment/cryptopay/handle-webhook.ts +6 -6
- package/src/payment/cryptopay/handler-express.ts +4 -7
- package/src/payment/cryptopay/handler-fastify.ts +2 -2
- package/src/payment/cryptopay/module.ts +8 -5
- package/src/payment/cryptopay/plugin.ts +21 -4
- package/src/payment/datatrans-v2/handler-express.ts +17 -12
- package/src/payment/datatrans-v2/handler-fastify.ts +15 -6
- package/src/payment/datatrans-v2/index.ts +82 -50
- package/src/payment/paypal-checkout.ts +8 -11
- package/src/payment/payrexx/api/index.ts +1 -1
- package/src/payment/payrexx/api/makeFetcher.ts +2 -2
- package/src/payment/payrexx/handler-express.ts +24 -32
- package/src/payment/payrexx/handler-fastify.ts +33 -33
- package/src/payment/payrexx/index.ts +26 -16
- package/src/payment/postfinance-checkout/api-client.ts +111 -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 +11 -13
- package/src/payment/postfinance-checkout/handler-fastify.ts +11 -10
- package/src/payment/postfinance-checkout/index.ts +60 -38
- package/src/payment/postfinance-checkout/utils.ts +5 -10
- package/src/payment/saferpay/adapter.ts +14 -2
- package/src/payment/saferpay/handler-express.ts +14 -13
- package/src/payment/saferpay/handler-fastify.ts +14 -9
- package/src/payment/stripe/handler-express.ts +33 -33
- package/src/payment/stripe/handler-fastify.ts +40 -27
- package/src/payment/stripe/index.ts +17 -13
- package/src/payment/stripe/stripe.ts +17 -12
- package/src/presets/all.ts +3 -1
- package/src/pricing/delivery-swiss-tax.ts +16 -31
- package/src/pricing/order-discount.ts +6 -4
- package/src/pricing/order-round.ts +5 -4
- package/src/pricing/product-catalog-price.ts +25 -2
- package/src/pricing/product-price-rateconversion.ts +3 -3
- package/src/pricing/product-swiss-tax.ts +39 -40
- package/src/pricing/tax/ch.ts +33 -7
- package/src/pricing/utils/isDeliveryAddressInCountry.test.ts +106 -0
- package/src/pricing/utils/isDeliveryAddressInCountry.ts +26 -0
- package/src/warehousing/eth-minter.ts +30 -11
- package/src/worker/budgetsms.ts +268 -0
- package/src/worker/bulk-import.ts +12 -53
- package/src/worker/bulkgate.ts +138 -0
- package/src/worker/email.ts +30 -8
- package/src/worker/enrollment-order-generator.ts +14 -72
- package/src/worker/error-notifications.ts +2 -2
- package/src/worker/export-token.ts +0 -1
- package/src/worker/heartbeat.ts +2 -9
- package/src/worker/message.ts +5 -3
- package/src/worker/{sms.ts → twilio.ts} +15 -26
- package/lib/payment/cryptopay/de.d.ts +0 -2
- package/lib/payment/cryptopay/de.d.ts.map +0 -1
- package/lib/payment/cryptopay/de.js +0 -10
- package/lib/payment/cryptopay/de.js.map +0 -1
- package/lib/payment/cryptopay/derive-btc-address.test copy.d.ts +0 -2
- package/lib/payment/cryptopay/derive-btc-address.test copy.d.ts.map +0 -1
- package/lib/payment/cryptopay/derive-btc-address.test copy.js +0 -10
- package/lib/payment/cryptopay/derive-btc-address.test copy.js.map +0 -1
- package/src/pricing/product-swiss-tax.test.ts +0 -139
|
@@ -2,42 +2,39 @@ import { Context } from '@unchainedshop/api';
|
|
|
2
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
3
|
import { FastifyRequest, RouteHandlerMethod } from 'fastify';
|
|
4
4
|
|
|
5
|
-
const logger = createLogger('unchained:
|
|
5
|
+
const logger = createLogger('unchained:payrexx:handler');
|
|
6
6
|
|
|
7
7
|
export const payrexxHandler: RouteHandlerMethod = async (
|
|
8
8
|
request: FastifyRequest & {
|
|
9
9
|
unchainedContext: Context;
|
|
10
|
-
},
|
|
10
|
+
} & { body: Record<string, any> },
|
|
11
11
|
reply,
|
|
12
12
|
) => {
|
|
13
13
|
const resolvedContext = request.unchainedContext as Context;
|
|
14
14
|
const { modules, services } = resolvedContext;
|
|
15
15
|
|
|
16
|
-
const { transaction } = request.body
|
|
17
|
-
|
|
16
|
+
const { transaction } = request.body;
|
|
18
17
|
if (!transaction) {
|
|
19
18
|
logger.info(`unhandled event type`, {
|
|
20
19
|
type: Object.keys(request.body).join(','),
|
|
21
20
|
});
|
|
22
21
|
reply.status(200);
|
|
23
|
-
return reply.send(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
22
|
+
return reply.send({
|
|
23
|
+
success: false,
|
|
24
|
+
ignored: true,
|
|
25
|
+
message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
|
|
26
|
+
});
|
|
29
27
|
}
|
|
30
28
|
if (transaction.referenceId === '__IGNORE_WEBHOOK__' || transaction.status === 'waiting') {
|
|
31
29
|
// Ignore confirmed transactions, because those hooks are generated through calling the confirm()
|
|
32
30
|
// method in the payment adapter and could lead to double bookings.
|
|
33
31
|
logger.info(`unhandled transaction state: ${transaction.status}`);
|
|
34
32
|
reply.status(200);
|
|
35
|
-
return reply.send(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
);
|
|
33
|
+
return reply.send({
|
|
34
|
+
success: false,
|
|
35
|
+
ignored: true,
|
|
36
|
+
message: `Unhandled transaction state: ${transaction.status}`,
|
|
37
|
+
});
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
logger.info(`Processing event`, {
|
|
@@ -58,19 +55,14 @@ export const payrexxHandler: RouteHandlerMethod = async (
|
|
|
58
55
|
userId,
|
|
59
56
|
});
|
|
60
57
|
reply.status(200);
|
|
61
|
-
return reply.send(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}),
|
|
67
|
-
);
|
|
58
|
+
return reply.send({
|
|
59
|
+
success: true,
|
|
60
|
+
paymentProviderId,
|
|
61
|
+
userId,
|
|
62
|
+
});
|
|
68
63
|
} else {
|
|
69
64
|
const { referenceId: orderPaymentId, invoice } = transaction;
|
|
70
65
|
logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
|
|
71
|
-
await modules.orders.payments.logEvent(orderPaymentId, {
|
|
72
|
-
transactionId: transaction.id,
|
|
73
|
-
});
|
|
74
66
|
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
75
67
|
orderPaymentId,
|
|
76
68
|
});
|
|
@@ -78,28 +70,36 @@ export const payrexxHandler: RouteHandlerMethod = async (
|
|
|
78
70
|
throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
79
71
|
}
|
|
80
72
|
|
|
73
|
+
await modules.orders.payments.logEvent(orderPaymentId, {
|
|
74
|
+
transactionId: transaction.id,
|
|
75
|
+
});
|
|
76
|
+
|
|
81
77
|
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
82
78
|
paymentContext: {
|
|
83
79
|
gatewayId: invoice.paymentRequestId,
|
|
84
80
|
},
|
|
85
81
|
});
|
|
82
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
83
|
+
|
|
86
84
|
logger.info(`checkout successful`, {
|
|
87
85
|
orderPaymentId,
|
|
88
86
|
orderId: order._id,
|
|
89
87
|
});
|
|
90
88
|
reply.status(200);
|
|
91
|
-
return reply.send(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}),
|
|
96
|
-
);
|
|
89
|
+
return reply.send({
|
|
90
|
+
success: true,
|
|
91
|
+
orderId: order._id,
|
|
92
|
+
});
|
|
97
93
|
}
|
|
98
94
|
} catch (error) {
|
|
99
95
|
logger.error(error, {
|
|
100
96
|
transactionId: transaction.id,
|
|
101
97
|
});
|
|
102
98
|
reply.status(500);
|
|
103
|
-
return reply.send(
|
|
99
|
+
return reply.send({
|
|
100
|
+
success: false,
|
|
101
|
+
message: error.message,
|
|
102
|
+
name: error.name,
|
|
103
|
+
});
|
|
104
104
|
}
|
|
105
105
|
};
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
PaymentError,
|
|
10
10
|
} from '@unchainedshop/core';
|
|
11
11
|
|
|
12
|
-
const logger = createLogger('unchained:
|
|
12
|
+
const logger = createLogger('unchained:payrexx');
|
|
13
13
|
|
|
14
14
|
const Payrexx: IPaymentAdapter = {
|
|
15
15
|
...PaymentAdapter,
|
|
@@ -25,11 +25,7 @@ const Payrexx: IPaymentAdapter = {
|
|
|
25
25
|
actions: (config, context) => {
|
|
26
26
|
const { modules } = context;
|
|
27
27
|
|
|
28
|
-
const
|
|
29
|
-
return config.find((c) => c.key === 'instance')?.value;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const api = createPayrexxAPI(getInstance(), process.env.PAYREXX_SECRET);
|
|
28
|
+
const instance = config.find((c) => c.key === 'instance')?.value;
|
|
33
29
|
|
|
34
30
|
const adapterActions = {
|
|
35
31
|
...PaymentAdapter.actions(config, context),
|
|
@@ -38,7 +34,7 @@ const Payrexx: IPaymentAdapter = {
|
|
|
38
34
|
if (!process.env.PAYREXX_SECRET) {
|
|
39
35
|
return PaymentError.INCOMPLETE_CONFIGURATION;
|
|
40
36
|
}
|
|
41
|
-
if (!
|
|
37
|
+
if (!instance) {
|
|
42
38
|
return PaymentError.INCOMPLETE_CONFIGURATION;
|
|
43
39
|
}
|
|
44
40
|
return null;
|
|
@@ -55,6 +51,11 @@ const Payrexx: IPaymentAdapter = {
|
|
|
55
51
|
|
|
56
52
|
sign: async (transactionContext = {}) => {
|
|
57
53
|
const { orderPayment, userId, order } = context;
|
|
54
|
+
|
|
55
|
+
if (!order) throw new Error('No order in context, can only sign with order context');
|
|
56
|
+
|
|
57
|
+
const api = createPayrexxAPI(instance!, process.env.PAYREXX_SECRET!);
|
|
58
|
+
|
|
58
59
|
if (orderPayment) {
|
|
59
60
|
// Order Checkout signing (One-time payment)
|
|
60
61
|
const pricing = OrderPricingSheet({
|
|
@@ -70,7 +71,10 @@ const Payrexx: IPaymentAdapter = {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
// Payment Credential Registration signing
|
|
73
|
-
|
|
74
|
+
|
|
75
|
+
const user = userId && (await modules.users.findUserById(userId));
|
|
76
|
+
if (!user) throw new Error('User not found, can only sign registrations with user context');
|
|
77
|
+
|
|
74
78
|
const emailAddress = modules.users.primaryEmail(user)?.address;
|
|
75
79
|
const gateway = await api.createGateway(
|
|
76
80
|
mapUserToGatewayObject({
|
|
@@ -107,11 +111,13 @@ const Payrexx: IPaymentAdapter = {
|
|
|
107
111
|
|
|
108
112
|
async confirm() {
|
|
109
113
|
const { orderPayment } = context;
|
|
110
|
-
const { transactionId } = orderPayment;
|
|
111
114
|
|
|
112
|
-
if (!transactionId) {
|
|
115
|
+
if (!orderPayment?.transactionId) {
|
|
113
116
|
return false;
|
|
114
117
|
}
|
|
118
|
+
const { transactionId } = orderPayment;
|
|
119
|
+
|
|
120
|
+
const api = createPayrexxAPI(instance!, process.env.PAYREXX_SECRET!);
|
|
115
121
|
|
|
116
122
|
const gatewayObject = await api.getGateway(transactionId);
|
|
117
123
|
|
|
@@ -140,10 +146,12 @@ const Payrexx: IPaymentAdapter = {
|
|
|
140
146
|
|
|
141
147
|
async cancel() {
|
|
142
148
|
const { orderPayment } = context;
|
|
143
|
-
|
|
144
|
-
if (!transactionId) {
|
|
149
|
+
if (!orderPayment?.transactionId) {
|
|
145
150
|
return false;
|
|
146
151
|
}
|
|
152
|
+
const { transactionId } = orderPayment;
|
|
153
|
+
|
|
154
|
+
const api = createPayrexxAPI(instance!, process.env.PAYREXX_SECRET!);
|
|
147
155
|
|
|
148
156
|
const gatewayObject = await api.getGateway(transactionId);
|
|
149
157
|
|
|
@@ -170,10 +178,12 @@ const Payrexx: IPaymentAdapter = {
|
|
|
170
178
|
throw new Error('You have to provide gatewayId or paymentCredentials');
|
|
171
179
|
}
|
|
172
180
|
|
|
173
|
-
const { order } = context;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
181
|
+
const { order, orderPayment } = context;
|
|
182
|
+
|
|
183
|
+
if (!order) throw new Error('No order in context, can only charge with order context');
|
|
184
|
+
if (!orderPayment) throw new Error('Order payment not found');
|
|
185
|
+
|
|
186
|
+
const api = createPayrexxAPI(instance!, process.env.PAYREXX_SECRET!);
|
|
177
187
|
|
|
178
188
|
const gatewayObject = await api.getGateway(gatewayId);
|
|
179
189
|
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const API_BASE_URL = 'https://checkout.postfinance.ch/api';
|
|
2
|
+
|
|
3
|
+
interface ApiConfig {
|
|
4
|
+
spaceId: number;
|
|
5
|
+
userId: number;
|
|
6
|
+
apiSecret: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface MacHeaders {
|
|
10
|
+
'x-mac-version': string;
|
|
11
|
+
'x-mac-userid': string;
|
|
12
|
+
'x-mac-timestamp': string;
|
|
13
|
+
'x-mac-value': string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class PostFinanceApiClient {
|
|
17
|
+
private config: ApiConfig;
|
|
18
|
+
|
|
19
|
+
constructor(config: ApiConfig) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private async generateMacHeaders(method: string, path: string): Promise<MacHeaders> {
|
|
24
|
+
const version = '1';
|
|
25
|
+
const timestamp = Math.floor(Date.now() / 1000).toString();
|
|
26
|
+
const userId = this.config.userId.toString();
|
|
27
|
+
|
|
28
|
+
// Use path as-is since it already includes /api from the URL
|
|
29
|
+
const resourcePath = path;
|
|
30
|
+
|
|
31
|
+
const dataToSign = [version, userId, timestamp, method, resourcePath].join('|');
|
|
32
|
+
|
|
33
|
+
// Use Web Crypto API instead of crypto.createHmac
|
|
34
|
+
const secretBytes = Uint8Array.from(atob(this.config.apiSecret), (c) => c.charCodeAt(0));
|
|
35
|
+
const key = await crypto.subtle.importKey(
|
|
36
|
+
'raw',
|
|
37
|
+
secretBytes,
|
|
38
|
+
{ name: 'HMAC', hash: 'SHA-512' },
|
|
39
|
+
false,
|
|
40
|
+
['sign'],
|
|
41
|
+
);
|
|
42
|
+
const signature = await crypto.subtle.sign('HMAC', key, new TextEncoder().encode(dataToSign));
|
|
43
|
+
const macValue = btoa(String.fromCharCode(...new Uint8Array(signature)));
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
'x-mac-version': version,
|
|
47
|
+
'x-mac-userid': userId,
|
|
48
|
+
'x-mac-timestamp': timestamp,
|
|
49
|
+
'x-mac-value': macValue,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async request<T>(method: string, endpoint: string, body?: any): Promise<T> {
|
|
54
|
+
const url = `${API_BASE_URL}${endpoint}`;
|
|
55
|
+
const urlObj = new URL(url);
|
|
56
|
+
// Include both pathname and search (query parameters) for MAC signature
|
|
57
|
+
const pathWithQuery = urlObj.pathname + urlObj.search;
|
|
58
|
+
const macHeaders = await this.generateMacHeaders(method, pathWithQuery);
|
|
59
|
+
|
|
60
|
+
const headers: Record<string, string> = {
|
|
61
|
+
...macHeaders,
|
|
62
|
+
'Content-Type': 'application/json',
|
|
63
|
+
Accept: 'application/json',
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const options: RequestInit = {
|
|
67
|
+
method,
|
|
68
|
+
headers,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
if (body && method !== 'GET') {
|
|
72
|
+
options.body = JSON.stringify(body);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const response = await fetch(url, options);
|
|
76
|
+
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
const errorData = await response.json().catch(() => ({}));
|
|
79
|
+
throw new Error(
|
|
80
|
+
`PostFinance API error: ${response.status} ${response.statusText} ${JSON.stringify(errorData)}`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const responseText = await response.text();
|
|
85
|
+
const contentType = response.headers.get('content-type');
|
|
86
|
+
|
|
87
|
+
if (contentType && contentType.includes('application/json')) {
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(responseText);
|
|
90
|
+
} catch {
|
|
91
|
+
// If JSON parsing fails but content-type is json, return as text
|
|
92
|
+
// This handles PostFinance's payment-page-url endpoint that returns plain text with json content-type
|
|
93
|
+
return responseText as any;
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
return responseText as any;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
get<T>(endpoint: string): Promise<T> {
|
|
101
|
+
return this.request<T>('GET', endpoint);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
post<T>(endpoint: string, body: any): Promise<T> {
|
|
105
|
+
return this.request<T>('POST', endpoint, body);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
patch<T>(endpoint: string, body: any): Promise<T> {
|
|
109
|
+
return this.request<T>('PATCH', endpoint, body);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -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
|
};
|