@unchainedshop/plugins 4.0.0-rc.16 → 4.0.0-rc.17
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.js +1 -1
- 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 +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 +11 -2
- package/lib/files/gridfs/handler-fastify.js.map +1 -1
- package/lib/files/gridfs/module.d.ts +2 -2
- package/lib/files/minio/handler-express.js +1 -1
- package/lib/files/minio/handler-express.js.map +1 -1
- package/lib/files/minio/handler-fastify.js +1 -1
- 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 +3 -3
- 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 +11 -4
- 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 +13 -6
- 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 +2 -0
- 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.js +1 -1
- package/lib/payment/cryptopay/handler-express.js.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 +8 -1
- 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 +7 -1
- 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 +4 -2
- 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 +3 -1
- package/lib/payment/payrexx/handler-express.js.map +1 -1
- package/lib/payment/payrexx/handler-fastify.d.ts.map +1 -1
- package/lib/payment/payrexx/handler-fastify.js +3 -1
- 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/handler-express.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.js +4 -2
- 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 +4 -2
- package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/index.js +20 -7
- 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/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 +3 -1
- 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 +3 -1
- 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.d.ts.map +1 -1
- package/lib/payment/stripe/handler-express.js +9 -1
- 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 +9 -1
- 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 +5 -5
- package/lib/presets/all.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +13 -11
- 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.js +4 -4
- 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 -4
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +9 -15
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/pricing/tax/ch.d.ts +6 -0
- package/lib/pricing/tax/ch.d.ts.map +1 -1
- package/lib/pricing/tax/ch.js +10 -0
- package/lib/pricing/tax/ch.js.map +1 -1
- package/lib/warehousing/eth-minter.js +23 -11
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/BaseWorker.d.ts +30 -0
- package/lib/worker/BaseWorker.d.ts.map +1 -0
- package/lib/worker/BaseWorker.js +79 -0
- package/lib/worker/BaseWorker.js.map +1 -0
- package/lib/worker/EventListenerWorker.d.ts +6 -0
- package/lib/worker/EventListenerWorker.d.ts.map +1 -0
- package/lib/worker/EventListenerWorker.js +46 -0
- package/lib/worker/EventListenerWorker.js.map +1 -0
- package/lib/worker/FailedRescheduler.d.ts +15 -0
- package/lib/worker/FailedRescheduler.d.ts.map +1 -0
- package/lib/worker/FailedRescheduler.js +45 -0
- package/lib/worker/FailedRescheduler.js.map +1 -0
- package/lib/worker/IntervalWorker.d.ts +10 -0
- package/lib/worker/IntervalWorker.d.ts.map +1 -0
- package/lib/worker/IntervalWorker.js +37 -0
- package/lib/worker/IntervalWorker.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 +5 -4
- package/lib/worker/bulk-import.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/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.d.ts +2 -0
- package/lib/worker/sms.d.ts.map +1 -0
- package/lib/worker/sms.js +73 -0
- package/lib/worker/sms.js.map +1 -0
- package/lib/worker/twilio.js +4 -0
- package/lib/worker/twilio.js.map +1 -1
- package/package.json +15 -15
- package/src/delivery/send-message.ts +1 -1
- package/src/enrollments/licensed.ts +15 -2
- package/src/files/gridfs/adapter.ts +1 -1
- package/src/files/gridfs/handler-express.ts +8 -2
- package/src/files/gridfs/handler-fastify.ts +13 -2
- package/src/files/minio/handler-express.ts +1 -1
- package/src/files/minio/handler-fastify.ts +1 -1
- package/src/files/minio/index.ts +12 -12
- 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 +14 -5
- package/src/payment/apple-iap/handler-fastify.ts +17 -7
- 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 +2 -0
- package/src/payment/cryptopay/handle-webhook.ts +6 -6
- package/src/payment/cryptopay/handler-express.ts +1 -1
- package/src/payment/cryptopay/handler-fastify.ts +1 -1
- package/src/payment/cryptopay/module.ts +8 -5
- package/src/payment/cryptopay/plugin.ts +21 -4
- package/src/payment/datatrans-v2/handler-express.ts +12 -2
- package/src/payment/datatrans-v2/handler-fastify.ts +11 -2
- package/src/payment/datatrans-v2/index.ts +82 -50
- package/src/payment/paypal-checkout.ts +4 -2
- 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 +3 -1
- package/src/payment/payrexx/handler-fastify.ts +5 -4
- package/src/payment/payrexx/index.ts +26 -16
- package/src/payment/postfinance-checkout/handler-express.ts +5 -2
- package/src/payment/postfinance-checkout/handler-fastify.ts +5 -2
- package/src/payment/postfinance-checkout/index.ts +20 -8
- package/src/payment/saferpay/adapter.ts +14 -2
- package/src/payment/saferpay/handler-express.ts +4 -1
- package/src/payment/saferpay/handler-fastify.ts +4 -1
- package/src/payment/stripe/handler-express.ts +9 -1
- package/src/payment/stripe/handler-fastify.ts +9 -1
- package/src/payment/stripe/index.ts +17 -13
- package/src/payment/stripe/stripe.ts +17 -12
- package/src/pricing/delivery-swiss-tax.ts +11 -19
- package/src/pricing/order-discount.ts +6 -4
- package/src/pricing/order-round.ts +5 -4
- package/src/pricing/product-catalog-price.ts +4 -4
- package/src/pricing/product-price-rateconversion.ts +3 -3
- package/src/pricing/product-swiss-tax.test.ts +1 -86
- package/src/pricing/product-swiss-tax.ts +11 -24
- package/src/pricing/tax/ch.test.ts +86 -1
- package/src/pricing/tax/ch.ts +23 -0
- package/src/warehousing/eth-minter.ts +30 -11
- package/src/worker/budgetsms.ts +1 -1
- package/src/worker/bulk-import.ts +6 -7
- 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/message.ts +5 -3
- package/src/worker/twilio.ts +10 -3
|
@@ -9,12 +9,19 @@ const {
|
|
|
9
9
|
DATATRANS_SECURITY = Security.DYNAMIC_SIGN,
|
|
10
10
|
} = process.env;
|
|
11
11
|
|
|
12
|
-
const logger = createLogger('unchained:
|
|
12
|
+
const logger = createLogger('unchained:datatrans:handler');
|
|
13
13
|
|
|
14
14
|
export const datatransHandler = async (req, res) => {
|
|
15
15
|
const resolvedContext = req.unchainedContext as Context;
|
|
16
16
|
const { modules, services } = resolvedContext;
|
|
17
17
|
const signature = req.headers['datatrans-signature'];
|
|
18
|
+
|
|
19
|
+
if (!DATATRANS_SIGN_KEY && !DATATRANS_SIGN2_KEY) {
|
|
20
|
+
logger.warn('No sign key configured');
|
|
21
|
+
res.status(404).end();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
if (req.method === 'POST' && signature) {
|
|
19
26
|
const [rawTimestamp, rawHash] = signature.split(',');
|
|
20
27
|
const [, hash] = rawHash.split('=');
|
|
@@ -22,7 +29,7 @@ export const datatransHandler = async (req, res) => {
|
|
|
22
29
|
|
|
23
30
|
const comparableSignature = await generateSignature({
|
|
24
31
|
security: DATATRANS_SECURITY as any,
|
|
25
|
-
signKey: DATATRANS_SIGN2_KEY || DATATRANS_SIGN_KEY
|
|
32
|
+
signKey: DATATRANS_SIGN2_KEY! || DATATRANS_SIGN_KEY!,
|
|
26
33
|
})(timestamp, req.body);
|
|
27
34
|
|
|
28
35
|
if (hash !== comparableSignature) {
|
|
@@ -64,6 +71,9 @@ export const datatransHandler = async (req, res) => {
|
|
|
64
71
|
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
65
72
|
paymentContext: { userId, transactionId: transaction.transactionId },
|
|
66
73
|
});
|
|
74
|
+
|
|
75
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
76
|
+
|
|
67
77
|
logger.info(`confirmed checkout for order ${order.orderNumber}`, {
|
|
68
78
|
orderId: order._id,
|
|
69
79
|
});
|
|
@@ -10,7 +10,7 @@ const {
|
|
|
10
10
|
DATATRANS_SECURITY = Security.DYNAMIC_SIGN,
|
|
11
11
|
} = process.env;
|
|
12
12
|
|
|
13
|
-
const logger = createLogger('unchained:
|
|
13
|
+
const logger = createLogger('unchained:datatrans:handler');
|
|
14
14
|
|
|
15
15
|
export const datatransHandler: RouteHandlerMethod = async (
|
|
16
16
|
req: FastifyRequest & {
|
|
@@ -21,6 +21,12 @@ export const datatransHandler: RouteHandlerMethod = async (
|
|
|
21
21
|
const resolvedContext = req.unchainedContext as Context;
|
|
22
22
|
const { modules, services } = resolvedContext;
|
|
23
23
|
const signature = req.headers['datatrans-signature'] as string;
|
|
24
|
+
|
|
25
|
+
if (!DATATRANS_SIGN_KEY && !DATATRANS_SIGN2_KEY) {
|
|
26
|
+
logger.warn('No sign key configured');
|
|
27
|
+
return reply.send({ success: false, message: 'No sign key configured', name: 'NO_SIGN_KEY' });
|
|
28
|
+
}
|
|
29
|
+
|
|
24
30
|
if (signature) {
|
|
25
31
|
const [rawTimestamp, rawHash] = signature.split(',');
|
|
26
32
|
const [, hash] = rawHash.split('=');
|
|
@@ -28,7 +34,7 @@ export const datatransHandler: RouteHandlerMethod = async (
|
|
|
28
34
|
|
|
29
35
|
const comparableSignature = await generateSignature({
|
|
30
36
|
security: DATATRANS_SECURITY as any,
|
|
31
|
-
signKey: DATATRANS_SIGN2_KEY || DATATRANS_SIGN_KEY
|
|
37
|
+
signKey: DATATRANS_SIGN2_KEY! || DATATRANS_SIGN_KEY!,
|
|
32
38
|
})(timestamp, req.body as string);
|
|
33
39
|
|
|
34
40
|
if (hash !== comparableSignature) {
|
|
@@ -70,6 +76,9 @@ export const datatransHandler: RouteHandlerMethod = async (
|
|
|
70
76
|
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
71
77
|
paymentContext: { userId, transactionId: transaction.transactionId },
|
|
72
78
|
});
|
|
79
|
+
|
|
80
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
81
|
+
|
|
73
82
|
reply.status(200);
|
|
74
83
|
logger.info(`confirmed checkout for order ${order.orderNumber}`, {
|
|
75
84
|
orderId: order._id,
|
|
@@ -19,8 +19,10 @@ import {
|
|
|
19
19
|
PaymentPricingSheet,
|
|
20
20
|
OrderPricingSheet,
|
|
21
21
|
} from '@unchainedshop/core';
|
|
22
|
+
import { Order, OrderPayment } from '@unchainedshop/core-orders';
|
|
23
|
+
import { PaymentConfiguration } from '@unchainedshop/core-payment';
|
|
22
24
|
|
|
23
|
-
const logger = createLogger('unchained:
|
|
25
|
+
const logger = createLogger('unchained:datatrans');
|
|
24
26
|
|
|
25
27
|
// v2
|
|
26
28
|
const {
|
|
@@ -43,6 +45,56 @@ const throwIfResponseError = (result) => {
|
|
|
43
45
|
}
|
|
44
46
|
};
|
|
45
47
|
|
|
48
|
+
const getMarketplaceSplits = async ({
|
|
49
|
+
order,
|
|
50
|
+
orderPayment,
|
|
51
|
+
config,
|
|
52
|
+
}: {
|
|
53
|
+
order: Order;
|
|
54
|
+
orderPayment: OrderPayment;
|
|
55
|
+
config: PaymentConfiguration;
|
|
56
|
+
}): Promise<
|
|
57
|
+
{
|
|
58
|
+
subMerchantId: string;
|
|
59
|
+
amount: number;
|
|
60
|
+
commission: number;
|
|
61
|
+
}[]
|
|
62
|
+
> => {
|
|
63
|
+
const pricingForOrderPayment = PaymentPricingSheet({
|
|
64
|
+
calculation: orderPayment.calculation,
|
|
65
|
+
currencyCode: order.currencyCode,
|
|
66
|
+
});
|
|
67
|
+
const pricing = OrderPricingSheet({
|
|
68
|
+
calculation: order.calculation,
|
|
69
|
+
currencyCode: order.currencyCode,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const { amount: total } = pricing.total({ useNetPrice: false });
|
|
73
|
+
|
|
74
|
+
return Promise.all(
|
|
75
|
+
config
|
|
76
|
+
.filter((item) => item.key === 'marketplaceSplit')
|
|
77
|
+
.map((item) => {
|
|
78
|
+
const [subMerchantId, staticDiscountId, sharePercentage] =
|
|
79
|
+
item.value || ''.split(';').map((f) => f.trim());
|
|
80
|
+
|
|
81
|
+
const { amount: discountSum } = pricingForOrderPayment.total({
|
|
82
|
+
category: PaymentPricingRowCategory.Discount,
|
|
83
|
+
discountId: staticDiscountId,
|
|
84
|
+
});
|
|
85
|
+
const shareFactor = sharePercentage ? parseInt(sharePercentage, 10) / 100 : 1;
|
|
86
|
+
const amount = Math.round(total * shareFactor);
|
|
87
|
+
const commission = Math.round(discountSum * -1 * shareFactor);
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
subMerchantId,
|
|
91
|
+
amount,
|
|
92
|
+
commission,
|
|
93
|
+
};
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
46
98
|
const Datatrans: IPaymentAdapter = {
|
|
47
99
|
...PaymentAdapter,
|
|
48
100
|
|
|
@@ -67,8 +119,11 @@ const Datatrans: IPaymentAdapter = {
|
|
|
67
119
|
};
|
|
68
120
|
|
|
69
121
|
const api = () => {
|
|
70
|
-
|
|
71
|
-
|
|
122
|
+
const merchantId = getMerchantId();
|
|
123
|
+
if (!DATATRANS_SECRET) throw new Error('Credential DATATRANS_SECRET not Set');
|
|
124
|
+
if (!merchantId) throw new Error('Credential Merchant ID not configured');
|
|
125
|
+
if (!DATATRANS_API_ENDPOINT) throw new Error('Credential DATATRANS_API_ENDPOINT not Set');
|
|
126
|
+
return createDatatransAPI(DATATRANS_API_ENDPOINT, merchantId!, DATATRANS_SECRET);
|
|
72
127
|
};
|
|
73
128
|
|
|
74
129
|
const shouldSettleInUnchained = () => {
|
|
@@ -78,58 +133,21 @@ const Datatrans: IPaymentAdapter = {
|
|
|
78
133
|
}, true);
|
|
79
134
|
};
|
|
80
135
|
|
|
81
|
-
const
|
|
82
|
-
{
|
|
83
|
-
subMerchantId: string;
|
|
84
|
-
amount: number;
|
|
85
|
-
commission: number;
|
|
86
|
-
}[]
|
|
87
|
-
> => {
|
|
136
|
+
const authorize = async ({ paymentCredentials, ...arbitraryFields }): Promise<string> => {
|
|
88
137
|
const { order, orderPayment } = context;
|
|
89
138
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
currencyCode: order.currencyCode,
|
|
93
|
-
});
|
|
94
|
-
const pricing = OrderPricingSheet({
|
|
95
|
-
calculation: order.calculation,
|
|
96
|
-
currencyCode: order.currencyCode,
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
const { amount: total } = pricing.total({ useNetPrice: false });
|
|
100
|
-
|
|
101
|
-
return Promise.all(
|
|
102
|
-
config
|
|
103
|
-
.filter((item) => item.key === 'marketplaceSplit')
|
|
104
|
-
.map((item) => {
|
|
105
|
-
const [subMerchantId, staticDiscountId, sharePercentage] = item.value
|
|
106
|
-
.split(';')
|
|
107
|
-
.map((f) => f.trim());
|
|
108
|
-
|
|
109
|
-
const { amount: discountSum } = pricingForOrderPayment.total({
|
|
110
|
-
category: PaymentPricingRowCategory.Discount,
|
|
111
|
-
discountId: staticDiscountId,
|
|
112
|
-
});
|
|
113
|
-
const shareFactor = sharePercentage ? parseInt(sharePercentage, 10) / 100 : 1;
|
|
114
|
-
const amount = Math.round(total * shareFactor);
|
|
115
|
-
const commission = Math.round(discountSum * -1 * shareFactor);
|
|
116
|
-
|
|
117
|
-
return {
|
|
118
|
-
subMerchantId,
|
|
119
|
-
amount,
|
|
120
|
-
commission,
|
|
121
|
-
};
|
|
122
|
-
}),
|
|
123
|
-
);
|
|
124
|
-
};
|
|
139
|
+
if (!orderPayment) throw new Error('Order Payment missing in context');
|
|
140
|
+
if (!order) throw new Error('Order missing in context');
|
|
125
141
|
|
|
126
|
-
const authorize = async ({ paymentCredentials, ...arbitraryFields }): Promise<string> => {
|
|
127
|
-
const { order, orderPayment } = context;
|
|
128
142
|
const refno = Buffer.from(orderPayment._id, 'hex').toString('base64');
|
|
129
143
|
const userId = order?.userId || context?.userId;
|
|
130
144
|
const refno2 = userId;
|
|
131
145
|
const { currencyCode, amount } = roundedAmountFromOrder(order);
|
|
132
|
-
const splits = await getMarketplaceSplits(
|
|
146
|
+
const splits = await getMarketplaceSplits({
|
|
147
|
+
orderPayment,
|
|
148
|
+
order,
|
|
149
|
+
config,
|
|
150
|
+
});
|
|
133
151
|
const result = await api().authorize({
|
|
134
152
|
...arbitraryFields,
|
|
135
153
|
amount,
|
|
@@ -158,6 +176,7 @@ const Datatrans: IPaymentAdapter = {
|
|
|
158
176
|
...arbitraryFields
|
|
159
177
|
}): Promise<string> => {
|
|
160
178
|
const { order } = context;
|
|
179
|
+
if (!order) throw new Error('Order missing in context');
|
|
161
180
|
const { currencyCode, amount } = roundedAmountFromOrder(order);
|
|
162
181
|
const result = await api().authorizeAuthenticated({
|
|
163
182
|
...arbitraryFields,
|
|
@@ -174,6 +193,7 @@ const Datatrans: IPaymentAdapter = {
|
|
|
174
193
|
|
|
175
194
|
const isTransactionAmountValid = (transaction: StatusResponseSuccess): boolean => {
|
|
176
195
|
const { order } = context;
|
|
196
|
+
if (!order) throw new Error('Order missing in context');
|
|
177
197
|
const { currencyCode, amount } = roundedAmountFromOrder(order);
|
|
178
198
|
if (
|
|
179
199
|
transaction.currency !== currencyCode ||
|
|
@@ -207,9 +227,15 @@ const Datatrans: IPaymentAdapter = {
|
|
|
207
227
|
};
|
|
208
228
|
|
|
209
229
|
const settle = async ({ transactionId, refno, refno2, extensions }): Promise<boolean> => {
|
|
210
|
-
const { order } = context;
|
|
230
|
+
const { order, orderPayment } = context;
|
|
231
|
+
if (!orderPayment) throw new Error('Order Payment missing in context');
|
|
232
|
+
if (!order) throw new Error('Order missing in context');
|
|
211
233
|
const { currencyCode, amount } = roundedAmountFromOrder(order);
|
|
212
|
-
const splits = await getMarketplaceSplits(
|
|
234
|
+
const splits = await getMarketplaceSplits({
|
|
235
|
+
orderPayment,
|
|
236
|
+
order,
|
|
237
|
+
config,
|
|
238
|
+
});
|
|
213
239
|
const result = await api().settle({
|
|
214
240
|
transactionId,
|
|
215
241
|
amount,
|
|
@@ -320,6 +346,9 @@ const Datatrans: IPaymentAdapter = {
|
|
|
320
346
|
async confirm() {
|
|
321
347
|
if (!shouldSettleInUnchained()) return false;
|
|
322
348
|
const { orderPayment, transactionContext } = context;
|
|
349
|
+
|
|
350
|
+
if (!orderPayment) throw new Error('Order Payment missing in context');
|
|
351
|
+
|
|
323
352
|
const { transactionId } = orderPayment;
|
|
324
353
|
|
|
325
354
|
const { extensions } = transactionContext || {};
|
|
@@ -350,6 +379,9 @@ const Datatrans: IPaymentAdapter = {
|
|
|
350
379
|
async cancel() {
|
|
351
380
|
if (!shouldSettleInUnchained()) return false;
|
|
352
381
|
const { orderPayment } = context;
|
|
382
|
+
|
|
383
|
+
if (!orderPayment) throw new Error('Order Payment missing in context');
|
|
384
|
+
|
|
353
385
|
const { transactionId } = orderPayment;
|
|
354
386
|
if (!transactionId) {
|
|
355
387
|
return false;
|
|
@@ -17,7 +17,7 @@ try {
|
|
|
17
17
|
/* */
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const logger = createLogger('unchained:
|
|
20
|
+
const logger = createLogger('unchained:paypal-checkout');
|
|
21
21
|
|
|
22
22
|
const { PAYPAL_CLIENT_ID, PAYPAL_SECRET, PAYPAL_ENVIRONMENT = 'sandbox' } = process.env;
|
|
23
23
|
|
|
@@ -72,12 +72,14 @@ const PaypalCheckout: IPaymentAdapter = {
|
|
|
72
72
|
},
|
|
73
73
|
|
|
74
74
|
sign: async () => {
|
|
75
|
-
return PAYPAL_CLIENT_ID;
|
|
75
|
+
return PAYPAL_CLIENT_ID || null;
|
|
76
76
|
},
|
|
77
77
|
|
|
78
78
|
charge: async ({ orderID }) => {
|
|
79
79
|
const { order } = context;
|
|
80
80
|
|
|
81
|
+
if (!order) throw new Error('Order missing in payment context');
|
|
82
|
+
|
|
81
83
|
if (!orderID) {
|
|
82
84
|
throw new Error('You have to provide orderID in paymentContext');
|
|
83
85
|
}
|
|
@@ -51,7 +51,7 @@ const createPayrexxAPI = (instance: string, secret: string) => {
|
|
|
51
51
|
throw new Error(await result.text());
|
|
52
52
|
},
|
|
53
53
|
|
|
54
|
-
async getGateway(id): Promise<GatewayObject> {
|
|
54
|
+
async getGateway(id): Promise<GatewayObject | null> {
|
|
55
55
|
const result = await fetchPayrexx(`Gateway/${id}`, 'GET');
|
|
56
56
|
if (!result.ok) throw new Error(await result.text());
|
|
57
57
|
const { status, data } = await result.json();
|
|
@@ -6,8 +6,8 @@ const logger = createLogger('unchained:payrexx');
|
|
|
6
6
|
|
|
7
7
|
export default (
|
|
8
8
|
baseUrl = 'https://api.payrexx.com/v1.0/',
|
|
9
|
-
instance: string
|
|
10
|
-
secret: string
|
|
9
|
+
instance: string,
|
|
10
|
+
secret: string,
|
|
11
11
|
): ((path: string, method: 'GET' | 'DELETE' | 'PUT' | 'POST', data?: any) => Promise<Response>) => {
|
|
12
12
|
if (MOCK_APIS) {
|
|
13
13
|
return async (path): Promise<Response> => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from '@unchainedshop/api';
|
|
2
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
3
|
|
|
4
|
-
const logger = createLogger('unchained:
|
|
4
|
+
const logger = createLogger('unchained:payrexx:handler');
|
|
5
5
|
|
|
6
6
|
export const payrexxHandler = async (request, response) => {
|
|
7
7
|
const resolvedContext = request.unchainedContext as Context;
|
|
@@ -70,6 +70,8 @@ export const payrexxHandler = async (request, response) => {
|
|
|
70
70
|
gatewayId: invoice.paymentRequestId,
|
|
71
71
|
},
|
|
72
72
|
});
|
|
73
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
74
|
+
|
|
73
75
|
logger.info(`checkout successful`, {
|
|
74
76
|
orderPaymentId,
|
|
75
77
|
orderId: order._id,
|
|
@@ -2,19 +2,18 @@ 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(','),
|
|
@@ -80,6 +79,8 @@ export const payrexxHandler: RouteHandlerMethod = async (
|
|
|
80
79
|
gatewayId: invoice.paymentRequestId,
|
|
81
80
|
},
|
|
82
81
|
});
|
|
82
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
83
|
+
|
|
83
84
|
logger.info(`checkout successful`, {
|
|
84
85
|
orderPaymentId,
|
|
85
86
|
orderId: order._id,
|
|
@@ -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
|
|
|
@@ -3,7 +3,7 @@ import { createLogger } from '@unchainedshop/logger';
|
|
|
3
3
|
import { WebhookData } from './types.js';
|
|
4
4
|
import { getTransaction, getTransactionCompletion } from './api.js';
|
|
5
5
|
|
|
6
|
-
const logger = createLogger('unchained:
|
|
6
|
+
const logger = createLogger('unchained:postfinance-checkout:handler');
|
|
7
7
|
|
|
8
8
|
export const postfinanceCheckoutHandler = async (req, res) => {
|
|
9
9
|
const context = req.unchainedContext as Context;
|
|
@@ -26,8 +26,11 @@ export const postfinanceCheckoutHandler = async (req, res) => {
|
|
|
26
26
|
transactionId: transactionCompletion.linkedTransaction,
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
|
+
|
|
30
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
31
|
+
|
|
29
32
|
logger.info(
|
|
30
|
-
`Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData
|
|
33
|
+
`Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData?.orderPaymentId} as paid`,
|
|
31
34
|
);
|
|
32
35
|
res.status(200).send(`Order marked as paid: ${order.orderNumber}`);
|
|
33
36
|
} catch (e) {
|
|
@@ -4,7 +4,7 @@ import { WebhookData } from './types.js';
|
|
|
4
4
|
import { getTransaction, getTransactionCompletion } from './api.js';
|
|
5
5
|
import { FastifyRequest, RouteHandlerMethod } from 'fastify';
|
|
6
6
|
|
|
7
|
-
const logger = createLogger('unchained:
|
|
7
|
+
const logger = createLogger('unchained:postfinance-checkout:handler');
|
|
8
8
|
|
|
9
9
|
export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
|
|
10
10
|
req: FastifyRequest & {
|
|
@@ -32,8 +32,11 @@ export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
|
|
|
32
32
|
transactionId: transaction.id,
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
|
+
|
|
36
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
37
|
+
|
|
35
38
|
logger.info(
|
|
36
|
-
`Transaction ${transaction.id} marked order payment ID ${transaction.metaData
|
|
39
|
+
`Transaction ${transaction.id} marked order payment ID ${transaction.metaData?.orderPaymentId} as paid`,
|
|
37
40
|
);
|
|
38
41
|
reply.status(200);
|
|
39
42
|
return reply.send({ success: true, orderNumber: order.orderNumber });
|
|
@@ -40,7 +40,7 @@ const {
|
|
|
40
40
|
PFCHECKOUT_FAILED_URL,
|
|
41
41
|
} = process.env;
|
|
42
42
|
|
|
43
|
-
const logger = createLogger('unchained:
|
|
43
|
+
const logger = createLogger('unchained:postfinance-checkout');
|
|
44
44
|
|
|
45
45
|
const newError = ({ code, message }: { code: string; message: string }) => {
|
|
46
46
|
const error = new Error(message);
|
|
@@ -104,6 +104,10 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
104
104
|
sign: async (transactionContext: any = {}) => {
|
|
105
105
|
const { orderPayment, order } = context;
|
|
106
106
|
|
|
107
|
+
if (!order) throw new Error('No order in context, can only sign with order context');
|
|
108
|
+
if (!orderPayment)
|
|
109
|
+
throw new Error('No order payment in context, can only sign with order payment context');
|
|
110
|
+
|
|
107
111
|
const { integrationMode = IntegrationModes.PaymentPage }: { integrationMode: IntegrationModes } =
|
|
108
112
|
transactionContext;
|
|
109
113
|
const completionMode = adapter.getCompletionMode();
|
|
@@ -146,7 +150,10 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
const transactionId = await createTransaction(transaction);
|
|
149
|
-
|
|
153
|
+
|
|
154
|
+
if (!transactionId) throw new Error('Could not create transaction');
|
|
155
|
+
|
|
156
|
+
let location: string | null = null;
|
|
150
157
|
if (integrationMode === IntegrationModes.PaymentPage) {
|
|
151
158
|
location = await getPaymentPageUrl(transactionId);
|
|
152
159
|
} else if (integrationMode === IntegrationModes.Lightbox) {
|
|
@@ -185,7 +192,11 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
185
192
|
});
|
|
186
193
|
}
|
|
187
194
|
|
|
188
|
-
const
|
|
195
|
+
const { order, orderPayment } = context;
|
|
196
|
+
if (!orderPayment) throw new Error('No order payment in context, cannot charge payment');
|
|
197
|
+
if (!order) throw new Error('No order in context, can only sign with order context');
|
|
198
|
+
|
|
199
|
+
const isPaid = await orderIsPaid(order, transaction);
|
|
189
200
|
if (!isPaid) {
|
|
190
201
|
logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
|
|
191
202
|
throw newError({
|
|
@@ -194,7 +205,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
194
205
|
});
|
|
195
206
|
}
|
|
196
207
|
|
|
197
|
-
if (transaction.metaData
|
|
208
|
+
if (transaction.metaData?.orderPaymentId !== orderPayment._id) {
|
|
198
209
|
logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
|
|
199
210
|
throw newError({
|
|
200
211
|
code: `TRANSACTION_ALREADY_USED`,
|
|
@@ -216,10 +227,11 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
216
227
|
|
|
217
228
|
cancel: async () => {
|
|
218
229
|
const { orderPayment, order } = context;
|
|
219
|
-
|
|
220
|
-
if (!transactionId) {
|
|
230
|
+
if (!order) throw new Error('No order in context, can only cancel with order context');
|
|
231
|
+
if (!orderPayment?.transactionId) {
|
|
221
232
|
return false;
|
|
222
233
|
}
|
|
234
|
+
const { transactionId } = orderPayment;
|
|
223
235
|
const transaction = await getTransaction(transactionId);
|
|
224
236
|
const refund = transaction.state === TransactionState.FULFILL;
|
|
225
237
|
const pricing = OrderPricingSheet({
|
|
@@ -237,10 +249,10 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
237
249
|
|
|
238
250
|
confirm: async () => {
|
|
239
251
|
const { orderPayment } = context;
|
|
240
|
-
|
|
241
|
-
if (!transactionId) {
|
|
252
|
+
if (!orderPayment?.transactionId) {
|
|
242
253
|
return false;
|
|
243
254
|
}
|
|
255
|
+
const { transactionId } = orderPayment;
|
|
244
256
|
const transaction = await getTransaction(transactionId);
|
|
245
257
|
if (transaction.state === TransactionState.AUTHORIZED) {
|
|
246
258
|
return confirmDeferredTransaction(transactionId);
|
|
@@ -133,8 +133,8 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
133
133
|
saferpayTransactionId,
|
|
134
134
|
);
|
|
135
135
|
|
|
136
|
-
paymentPageInitInput.Notification
|
|
137
|
-
paymentPageInitInput.Notification
|
|
136
|
+
paymentPageInitInput.Notification!.SuccessNotifyUrl = addTransactionId(
|
|
137
|
+
paymentPageInitInput.Notification!.SuccessNotifyUrl,
|
|
138
138
|
saferpayTransactionId,
|
|
139
139
|
);
|
|
140
140
|
|
|
@@ -166,6 +166,10 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
166
166
|
mongodb.ObjectId.createFromHexString(transactionId),
|
|
167
167
|
);
|
|
168
168
|
|
|
169
|
+
if (!saferpayTransaction?.token) {
|
|
170
|
+
throw new Error('No initialized transaction Token');
|
|
171
|
+
}
|
|
172
|
+
|
|
169
173
|
const api = createSaferPayClient();
|
|
170
174
|
const paymentPageAssert = await api.paymentPageAssert(orderPayment, {
|
|
171
175
|
Token: saferpayTransaction.token,
|
|
@@ -205,6 +209,10 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
205
209
|
mongodb.ObjectId.createFromHexString(transactionId),
|
|
206
210
|
);
|
|
207
211
|
|
|
212
|
+
if (!saferpayTransaction?.token) {
|
|
213
|
+
throw new Error('No initialized transaction Token');
|
|
214
|
+
}
|
|
215
|
+
|
|
208
216
|
const api = createSaferPayClient();
|
|
209
217
|
const paymentPageAssert = await api.paymentPageAssert(orderPayment, {
|
|
210
218
|
Token: saferpayTransaction.token,
|
|
@@ -236,6 +244,10 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
236
244
|
mongodb.ObjectId.createFromHexString(transactionId),
|
|
237
245
|
);
|
|
238
246
|
|
|
247
|
+
if (!saferpayTransaction?.token) {
|
|
248
|
+
throw new Error('No initialized transaction Token');
|
|
249
|
+
}
|
|
250
|
+
|
|
239
251
|
const api = createSaferPayClient();
|
|
240
252
|
const paymentPageAssert = await api.paymentPageAssert(orderPayment, {
|
|
241
253
|
Token: saferpayTransaction.token,
|
|
@@ -3,7 +3,7 @@ import { createLogger } from '@unchainedshop/logger';
|
|
|
3
3
|
import { buildSignature } from './buildSignature.js';
|
|
4
4
|
import { SaferpayTransactionsModule } from './module.js';
|
|
5
5
|
|
|
6
|
-
const logger = createLogger('unchained:
|
|
6
|
+
const logger = createLogger('unchained:saferpay:handler');
|
|
7
7
|
|
|
8
8
|
export const saferpayHandler = async (request, response) => {
|
|
9
9
|
const resolvedContext = request.unchainedContext as Context & {
|
|
@@ -46,6 +46,9 @@ export const saferpayHandler = async (request, response) => {
|
|
|
46
46
|
transactionId,
|
|
47
47
|
},
|
|
48
48
|
});
|
|
49
|
+
|
|
50
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
51
|
+
|
|
49
52
|
logger.info(`checkout successful`, {
|
|
50
53
|
orderPaymentId,
|
|
51
54
|
orderId: order._id,
|