@unchainedshop/plugins 4.6.1 → 4.7.2
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/README.md +0 -2
- package/lib/delivery/post/adapter.d.ts +2 -0
- package/lib/delivery/{post.js → post/adapter.js} +2 -3
- package/lib/delivery/post/index.d.ts +4 -0
- package/lib/delivery/post/index.js +10 -0
- package/lib/delivery/send-message/adapter.d.ts +2 -0
- package/lib/delivery/{send-message.js → send-message/adapter.js} +2 -3
- package/lib/delivery/send-message/index.d.ts +4 -0
- package/lib/delivery/send-message/index.js +10 -0
- package/lib/delivery/stores/adapter.d.ts +2 -0
- package/lib/delivery/{stores.js → stores/adapter.js} +2 -3
- package/lib/delivery/stores/index.d.ts +4 -0
- package/lib/delivery/stores/index.js +10 -0
- package/lib/enrollments/licensed/adapter.d.ts +6 -0
- package/lib/enrollments/{licensed.js → licensed/adapter.js} +2 -3
- package/lib/enrollments/licensed/index.d.ts +4 -0
- package/lib/enrollments/licensed/index.js +10 -0
- package/lib/events/node-event-emitter.d.ts +3 -1
- package/lib/events/node-event-emitter.js +3 -3
- package/lib/files/gridfs/adapter.d.ts +2 -2
- package/lib/files/gridfs/adapter.js +2 -5
- package/lib/files/gridfs/api.d.ts +7 -0
- package/lib/files/gridfs/api.js +163 -0
- package/lib/files/gridfs/index.d.ts +5 -4
- package/lib/files/gridfs/index.js +30 -3
- package/lib/files/minio/adapter.d.ts +4 -0
- package/lib/files/minio/adapter.js +160 -0
- package/lib/files/minio/api.d.ts +2 -0
- package/lib/files/minio/api.js +41 -0
- package/lib/files/minio/index.d.ts +4 -5
- package/lib/files/minio/index.js +18 -157
- package/lib/files/temp-upload/api.d.ts +6 -0
- package/lib/files/temp-upload/api.js +49 -0
- package/lib/files/temp-upload/index.d.ts +3 -0
- package/lib/files/temp-upload/index.js +15 -0
- package/lib/filters/local-search/adapter.d.ts +2 -0
- package/lib/filters/{local-search.js → local-search/adapter.js} +2 -12
- package/lib/filters/local-search/index.d.ts +4 -0
- package/lib/filters/local-search/index.js +16 -0
- package/lib/filters/strict-equal/adapter.d.ts +2 -0
- package/lib/filters/{strict-equal.js → strict-equal/adapter.js} +2 -3
- package/lib/filters/strict-equal/index.d.ts +4 -0
- package/lib/filters/strict-equal/index.js +10 -0
- package/lib/payment/apple-iap/adapter.d.ts +2 -1
- package/lib/payment/apple-iap/adapter.js +2 -3
- package/lib/payment/apple-iap/api.d.ts +2 -0
- package/lib/payment/apple-iap/{handler-fastify.js → api.js} +47 -30
- package/lib/payment/apple-iap/index.d.ts +6 -4
- package/lib/payment/apple-iap/index.js +28 -3
- package/lib/payment/cryptopay/adapter.d.ts +2 -0
- package/lib/payment/cryptopay/{plugin.js → adapter.js} +2 -4
- package/lib/payment/cryptopay/api.d.ts +2 -0
- package/lib/payment/cryptopay/api.js +23 -0
- package/lib/payment/cryptopay/index.d.ts +5 -4
- package/lib/payment/cryptopay/index.js +31 -3
- package/lib/payment/datatrans-v2/adapter.d.ts +2 -0
- package/lib/payment/datatrans-v2/adapter.js +406 -0
- package/lib/payment/datatrans-v2/api.d.ts +2 -0
- package/lib/payment/datatrans-v2/api.js +108 -0
- package/lib/payment/datatrans-v2/index.d.ts +4 -1
- package/lib/payment/datatrans-v2/index.js +17 -400
- package/lib/payment/invoice/adapter.d.ts +2 -0
- package/lib/payment/{invoice.js → invoice/adapter.js} +2 -3
- package/lib/payment/invoice/index.d.ts +4 -0
- package/lib/payment/invoice/index.js +10 -0
- package/lib/payment/invoice-prepaid/adapter.d.ts +2 -0
- package/lib/payment/{invoice-prepaid.js → invoice-prepaid/adapter.js} +2 -3
- package/lib/payment/invoice-prepaid/index.d.ts +4 -0
- package/lib/payment/invoice-prepaid/index.js +10 -0
- package/lib/payment/payrexx/adapter.d.ts +2 -0
- package/lib/payment/payrexx/adapter.js +161 -0
- package/lib/payment/payrexx/api.d.ts +2 -0
- package/lib/payment/payrexx/api.js +97 -0
- package/lib/payment/payrexx/index.d.ts +4 -1
- package/lib/payment/payrexx/index.js +19 -158
- package/lib/payment/postfinance-checkout/adapter.d.ts +2 -0
- package/lib/payment/postfinance-checkout/adapter.js +189 -0
- package/lib/payment/postfinance-checkout/index.d.ts +5 -0
- package/lib/payment/postfinance-checkout/index.js +25 -186
- package/lib/payment/postfinance-checkout/webhook.d.ts +2 -0
- package/lib/payment/postfinance-checkout/webhook.js +48 -0
- package/lib/payment/saferpay/adapter.js +1 -2
- package/lib/payment/saferpay/index.d.ts +5 -4
- package/lib/payment/saferpay/index.js +29 -3
- package/lib/payment/saferpay/webhook.d.ts +2 -0
- package/lib/payment/saferpay/webhook.js +64 -0
- package/lib/payment/stripe/adapter.d.ts +2 -0
- package/lib/payment/stripe/adapter.js +121 -0
- package/lib/payment/stripe/api.d.ts +6 -0
- package/lib/payment/stripe/api.js +165 -0
- package/lib/payment/stripe/index.d.ts +4 -1
- package/lib/payment/stripe/index.js +22 -116
- package/lib/payment/stripe/stripe.js +2 -5
- package/lib/presets/all.d.ts +1 -70
- package/lib/presets/all.js +41 -27
- package/lib/presets/base.d.ts +1 -25
- package/lib/presets/base.js +56 -25
- package/lib/presets/countries/ch.d.ts +1 -2
- package/lib/presets/countries/ch.js +7 -2
- package/lib/presets/crypto.d.ts +3 -7
- package/lib/presets/crypto.js +18 -7
- package/lib/pricing/{delivery-swiss-tax.d.ts → delivery-swiss-tax/adapter.d.ts} +1 -0
- package/lib/pricing/{delivery-swiss-tax.js → delivery-swiss-tax/adapter.js} +4 -4
- package/lib/pricing/delivery-swiss-tax/index.d.ts +4 -0
- package/lib/pricing/delivery-swiss-tax/index.js +10 -0
- package/lib/pricing/{discount-100-off.d.ts → discount-100-off/adapter.d.ts} +1 -0
- package/lib/pricing/{discount-100-off.js → discount-100-off/adapter.js} +2 -2
- package/lib/pricing/discount-100-off/index.d.ts +4 -0
- package/lib/pricing/discount-100-off/index.js +10 -0
- package/lib/pricing/{discount-half-price-manual.d.ts → discount-half-price-manual/adapter.d.ts} +1 -0
- package/lib/pricing/{discount-half-price-manual.js → discount-half-price-manual/adapter.js} +2 -2
- package/lib/pricing/discount-half-price-manual/index.d.ts +4 -0
- package/lib/pricing/discount-half-price-manual/index.js +10 -0
- package/lib/pricing/{free-delivery.d.ts → free-delivery/adapter.d.ts} +1 -0
- package/lib/pricing/{free-delivery.js → free-delivery/adapter.js} +2 -2
- package/lib/pricing/free-delivery/index.d.ts +4 -0
- package/lib/pricing/free-delivery/index.js +10 -0
- package/lib/pricing/{free-payment.d.ts → free-payment/adapter.d.ts} +1 -0
- package/lib/pricing/{free-payment.js → free-payment/adapter.js} +2 -2
- package/lib/pricing/free-payment/index.d.ts +4 -0
- package/lib/pricing/free-payment/index.js +10 -0
- package/lib/pricing/{order-delivery.d.ts → order-delivery/adapter.d.ts} +1 -0
- package/lib/pricing/{order-delivery.js → order-delivery/adapter.js} +2 -2
- package/lib/pricing/order-delivery/index.d.ts +4 -0
- package/lib/pricing/order-delivery/index.js +10 -0
- package/lib/pricing/{order-discount.d.ts → order-discount/adapter.d.ts} +1 -0
- package/lib/pricing/{order-discount.js → order-discount/adapter.js} +2 -2
- package/lib/pricing/order-discount/index.d.ts +4 -0
- package/lib/pricing/order-discount/index.js +10 -0
- package/lib/pricing/{order-items.d.ts → order-items/adapter.d.ts} +1 -0
- package/lib/pricing/{order-items.js → order-items/adapter.js} +2 -2
- package/lib/pricing/order-items/index.d.ts +4 -0
- package/lib/pricing/order-items/index.js +10 -0
- package/lib/pricing/{order-payment.d.ts → order-payment/adapter.d.ts} +1 -0
- package/lib/pricing/{order-payment.js → order-payment/adapter.js} +2 -2
- package/lib/pricing/order-payment/index.d.ts +4 -0
- package/lib/pricing/order-payment/index.js +10 -0
- package/lib/pricing/{product-catalog-price.d.ts → product-catalog-price/adapter.d.ts} +1 -0
- package/lib/pricing/{product-catalog-price.js → product-catalog-price/adapter.js} +2 -2
- package/lib/pricing/product-catalog-price/index.d.ts +4 -0
- package/lib/pricing/product-catalog-price/index.js +10 -0
- package/lib/pricing/{product-discount.d.ts → product-discount/adapter.d.ts} +1 -0
- package/lib/pricing/{product-discount.js → product-discount/adapter.js} +2 -2
- package/lib/pricing/product-discount/index.d.ts +4 -0
- package/lib/pricing/product-discount/index.js +10 -0
- package/lib/pricing/{product-price-rateconversion.d.ts → product-price-rateconversion/adapter.d.ts} +1 -0
- package/lib/pricing/{product-price-rateconversion.js → product-price-rateconversion/adapter.js} +2 -2
- package/lib/pricing/product-price-rateconversion/index.d.ts +4 -0
- package/lib/pricing/product-price-rateconversion/index.js +10 -0
- package/lib/pricing/{product-swiss-tax.d.ts → product-swiss-tax/adapter.d.ts} +1 -0
- package/lib/pricing/{product-swiss-tax.js → product-swiss-tax/adapter.js} +4 -4
- package/lib/pricing/product-swiss-tax/index.d.ts +4 -0
- package/lib/pricing/product-swiss-tax/index.js +10 -0
- package/lib/quotations/manual/adapter.d.ts +2 -0
- package/lib/quotations/{manual.js → manual/adapter.js} +2 -3
- package/lib/quotations/manual/index.d.ts +4 -0
- package/lib/quotations/manual/index.js +10 -0
- package/lib/warehousing/erc-metadata/api.d.ts +12 -0
- package/lib/warehousing/erc-metadata/api.js +43 -0
- package/lib/warehousing/erc-metadata/index.d.ts +3 -0
- package/lib/warehousing/erc-metadata/index.js +15 -0
- package/lib/warehousing/eth-minter/adapter.d.ts +2 -0
- package/lib/warehousing/{eth-minter.js → eth-minter/adapter.js} +3 -4
- package/lib/warehousing/eth-minter/index.d.ts +4 -0
- package/lib/warehousing/eth-minter/index.js +10 -0
- package/lib/warehousing/store/adapter.d.ts +2 -0
- package/lib/warehousing/{store.js → store/adapter.js} +2 -3
- package/lib/warehousing/store/index.d.ts +4 -0
- package/lib/warehousing/store/index.js +10 -0
- package/lib/worker/budgetsms/adapter.d.ts +22 -0
- package/lib/worker/{budgetsms.js → budgetsms/adapter.js} +3 -3
- package/lib/worker/budgetsms/index.d.ts +4 -0
- package/lib/worker/budgetsms/index.js +10 -0
- package/lib/worker/bulk-export/adapter.d.ts +3 -0
- package/lib/worker/{bulk-export.js → bulk-export/adapter.js} +3 -3
- package/lib/worker/bulk-export/index.d.ts +4 -0
- package/lib/worker/bulk-export/index.js +10 -0
- package/lib/worker/{bulk-import.d.ts → bulk-import/adapter.d.ts} +1 -0
- package/lib/worker/{bulk-import.js → bulk-import/adapter.js} +2 -2
- package/lib/worker/bulk-import/api.d.ts +7 -0
- package/lib/worker/bulk-import/api.js +53 -0
- package/lib/worker/bulk-import/index.d.ts +4 -0
- package/lib/worker/bulk-import/index.js +18 -0
- package/lib/worker/bulkgate/adapter.d.ts +12 -0
- package/lib/worker/{bulkgate.js → bulkgate/adapter.js} +3 -3
- package/lib/worker/bulkgate/index.d.ts +4 -0
- package/lib/worker/bulkgate/index.js +10 -0
- package/lib/worker/email/adapter.d.ts +9 -0
- package/lib/worker/{email.js → email/adapter.js} +27 -13
- package/lib/worker/email/index.d.ts +4 -0
- package/lib/worker/email/index.js +10 -0
- package/lib/worker/enrollment-order-generator/adapter.d.ts +4 -0
- package/lib/worker/{enrollment-order-generator.js → enrollment-order-generator/adapter.js} +2 -2
- package/lib/worker/enrollment-order-generator/index.d.ts +4 -0
- package/lib/worker/enrollment-order-generator/index.js +13 -0
- package/lib/worker/{error-notifications.d.ts → error-notifications/adapter.d.ts} +1 -0
- package/lib/worker/{error-notifications.js → error-notifications/adapter.js} +9 -8
- package/lib/worker/error-notifications/index.d.ts +4 -0
- package/lib/worker/error-notifications/index.js +13 -0
- package/lib/worker/{export-token.d.ts → export-token/adapter.d.ts} +1 -1
- package/lib/worker/{export-token.js → export-token/adapter.js} +2 -3
- package/lib/worker/export-token/index.d.ts +4 -0
- package/lib/worker/export-token/index.js +13 -0
- package/lib/worker/{external.d.ts → external/adapter.d.ts} +1 -0
- package/lib/worker/{external.js → external/adapter.js} +2 -2
- package/lib/worker/external/index.d.ts +4 -0
- package/lib/worker/external/index.js +10 -0
- package/lib/worker/heartbeat/adapter.d.ts +8 -0
- package/lib/worker/{heartbeat.js → heartbeat/adapter.js} +3 -3
- package/lib/worker/heartbeat/index.d.ts +4 -0
- package/lib/worker/heartbeat/index.js +10 -0
- package/lib/worker/{http-request.d.ts → http-request/adapter.d.ts} +1 -1
- package/lib/worker/{http-request.js → http-request/adapter.js} +2 -3
- package/lib/worker/http-request/index.d.ts +4 -0
- package/lib/worker/http-request/index.js +10 -0
- package/lib/worker/{message.d.ts → message/adapter.d.ts} +1 -0
- package/lib/worker/{message.js → message/adapter.js} +2 -2
- package/lib/worker/message/index.d.ts +4 -0
- package/lib/worker/message/index.js +10 -0
- package/lib/worker/push-notification/adapter.d.ts +9 -0
- package/lib/worker/{push-notification.js → push-notification/adapter.js} +3 -3
- package/lib/worker/push-notification/index.d.ts +4 -0
- package/lib/worker/push-notification/index.js +10 -0
- package/lib/worker/twilio/adapter.d.ts +8 -0
- package/lib/worker/{twilio.js → twilio/adapter.js} +3 -3
- package/lib/worker/twilio/index.d.ts +4 -0
- package/lib/worker/twilio/index.js +10 -0
- package/lib/worker/update-coinbase-rates/adapter.d.ts +4 -0
- package/lib/worker/{update-coinbase-rates.js → update-coinbase-rates/adapter.js} +8 -6
- package/lib/worker/update-coinbase-rates/index.d.ts +4 -0
- package/lib/worker/update-coinbase-rates/index.js +13 -0
- package/lib/worker/update-ecb-rates/adapter.d.ts +4 -0
- package/lib/worker/{update-ecb-rates.js → update-ecb-rates/adapter.js} +11 -9
- package/lib/worker/update-ecb-rates/index.d.ts +4 -0
- package/lib/worker/update-ecb-rates/index.js +13 -0
- package/lib/worker/{update-token-ownership.d.ts → update-token-ownership/adapter.d.ts} +2 -0
- package/lib/worker/{update-token-ownership.js → update-token-ownership/adapter.js} +8 -7
- package/lib/worker/update-token-ownership/index.d.ts +4 -0
- package/lib/worker/update-token-ownership/index.js +13 -0
- package/lib/worker/{zombie-killer.js → zombie-killer/adapter.js} +1 -2
- package/lib/worker/zombie-killer/index.d.ts +4 -0
- package/lib/worker/zombie-killer/index.js +10 -0
- package/package.json +15 -10
- package/lib/delivery/post.d.ts +0 -1
- package/lib/delivery/send-message.d.ts +0 -1
- package/lib/delivery/stores.d.ts +0 -1
- package/lib/enrollments/licensed.d.ts +0 -4
- package/lib/files/gridfs/handler-express.d.ts +0 -9
- package/lib/files/gridfs/handler-express.js +0 -110
- package/lib/files/gridfs/handler-fastify.d.ts +0 -3
- package/lib/files/gridfs/handler-fastify.js +0 -138
- package/lib/files/minio/handler-express.d.ts +0 -2
- package/lib/files/minio/handler-express.js +0 -36
- package/lib/files/minio/handler-fastify.d.ts +0 -3
- package/lib/files/minio/handler-fastify.js +0 -40
- package/lib/filters/local-search.d.ts +0 -3
- package/lib/filters/strict-equal.d.ts +0 -1
- package/lib/payment/apple-iap/handler-express.d.ts +0 -2
- package/lib/payment/apple-iap/handler-express.js +0 -103
- package/lib/payment/apple-iap/handler-fastify.d.ts +0 -3
- package/lib/payment/braintree.d.ts +0 -1
- package/lib/payment/braintree.js +0 -138
- package/lib/payment/cryptopay/handler-express.d.ts +0 -2
- package/lib/payment/cryptopay/handler-express.js +0 -19
- package/lib/payment/cryptopay/handler-fastify.d.ts +0 -3
- package/lib/payment/cryptopay/handler-fastify.js +0 -17
- package/lib/payment/cryptopay/plugin.d.ts +0 -3
- package/lib/payment/datatrans-v2/handler-express.d.ts +0 -1
- package/lib/payment/datatrans-v2/handler-express.js +0 -71
- package/lib/payment/datatrans-v2/handler-fastify.d.ts +0 -2
- package/lib/payment/datatrans-v2/handler-fastify.js +0 -71
- package/lib/payment/invoice-prepaid.d.ts +0 -1
- package/lib/payment/invoice.d.ts +0 -1
- package/lib/payment/paypal-checkout.d.ts +0 -1
- package/lib/payment/paypal-checkout.js +0 -87
- package/lib/payment/payrexx/handler-express.d.ts +0 -1
- package/lib/payment/payrexx/handler-express.js +0 -85
- package/lib/payment/payrexx/handler-fastify.d.ts +0 -2
- package/lib/payment/payrexx/handler-fastify.js +0 -91
- package/lib/payment/postfinance-checkout/handler-express.d.ts +0 -1
- package/lib/payment/postfinance-checkout/handler-express.js +0 -37
- package/lib/payment/postfinance-checkout/handler-fastify.d.ts +0 -2
- package/lib/payment/postfinance-checkout/handler-fastify.js +0 -40
- package/lib/payment/saferpay/handler-express.d.ts +0 -1
- package/lib/payment/saferpay/handler-express.js +0 -59
- package/lib/payment/saferpay/handler-fastify.d.ts +0 -2
- package/lib/payment/saferpay/handler-fastify.js +0 -62
- package/lib/payment/stripe/handler-express.d.ts +0 -5
- package/lib/payment/stripe/handler-express.js +0 -121
- package/lib/payment/stripe/handler-fastify.d.ts +0 -6
- package/lib/payment/stripe/handler-fastify.js +0 -131
- package/lib/presets/all-express.d.ts +0 -6
- package/lib/presets/all-express.js +0 -26
- package/lib/presets/all-fastify.d.ts +0 -6
- package/lib/presets/all-fastify.js +0 -49
- package/lib/presets/base-express.d.ts +0 -2
- package/lib/presets/base-express.js +0 -5
- package/lib/presets/base-fastify.d.ts +0 -3
- package/lib/presets/base-fastify.js +0 -16
- package/lib/presets/crypto-express.d.ts +0 -3
- package/lib/presets/crypto-express.js +0 -8
- package/lib/presets/crypto-fastify.d.ts +0 -3
- package/lib/presets/crypto-fastify.js +0 -11
- package/lib/pricing/discount-half-price.d.ts +0 -2
- package/lib/pricing/discount-half-price.js +0 -33
- package/lib/pricing/order-items-discount.d.ts +0 -2
- package/lib/pricing/order-items-discount.js +0 -50
- package/lib/pricing/order-round.d.ts +0 -10
- package/lib/pricing/order-round.js +0 -135
- package/lib/pricing/product-catalog-price-options.d.ts +0 -2
- package/lib/pricing/product-catalog-price-options.js +0 -51
- package/lib/pricing/product-round.d.ts +0 -10
- package/lib/pricing/product-round.js +0 -44
- package/lib/quotations/manual.d.ts +0 -1
- package/lib/warehousing/eth-minter.d.ts +0 -1
- package/lib/warehousing/store.d.ts +0 -1
- package/lib/worker/budgetsms.d.ts +0 -9
- package/lib/worker/bulk-export.d.ts +0 -2
- package/lib/worker/bulkgate.d.ts +0 -1
- package/lib/worker/email.d.ts +0 -1
- package/lib/worker/enrollment-order-generator.d.ts +0 -1
- package/lib/worker/heartbeat.d.ts +0 -1
- package/lib/worker/push-notification.d.ts +0 -1
- package/lib/worker/twilio.d.ts +0 -1
- package/lib/worker/update-coinbase-rates.d.ts +0 -1
- package/lib/worker/update-ecb-rates.d.ts +0 -1
- /package/lib/worker/{zombie-killer.d.ts → zombie-killer/adapter.d.ts} +0 -0
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import generateSignature, { Security } from "./generateSignature.js";
|
|
3
|
-
const { DATATRANS_SIGN_KEY, DATATRANS_SIGN2_KEY, DATATRANS_SECURITY = Security.DYNAMIC_SIGN, } = process.env;
|
|
4
|
-
const logger = createLogger('unchained:datatrans:handler');
|
|
5
|
-
export const datatransHandler = async (req, reply) => {
|
|
6
|
-
const resolvedContext = req.unchainedContext;
|
|
7
|
-
const { modules, services } = resolvedContext;
|
|
8
|
-
const signature = req.headers['datatrans-signature'];
|
|
9
|
-
if (!DATATRANS_SIGN_KEY && !DATATRANS_SIGN2_KEY) {
|
|
10
|
-
logger.warn('No sign key configured');
|
|
11
|
-
return reply.send({ success: false, message: 'No sign key configured', name: 'NO_SIGN_KEY' });
|
|
12
|
-
}
|
|
13
|
-
if (signature) {
|
|
14
|
-
const [rawTimestamp, rawHash] = signature.split(',');
|
|
15
|
-
const [, hash] = rawHash.split('=');
|
|
16
|
-
const [, timestamp] = rawTimestamp.split('=');
|
|
17
|
-
const comparableSignature = await generateSignature({
|
|
18
|
-
security: DATATRANS_SECURITY,
|
|
19
|
-
signKey: DATATRANS_SIGN2_KEY || DATATRANS_SIGN_KEY,
|
|
20
|
-
})(timestamp, req.body);
|
|
21
|
-
if (hash !== comparableSignature) {
|
|
22
|
-
logger.error(`hash mismatch: ${signature} / ${comparableSignature}`);
|
|
23
|
-
reply.status(403);
|
|
24
|
-
return reply.send({ success: false, message: 'Invalid Signature', name: 'HASH_MISMATCH' });
|
|
25
|
-
}
|
|
26
|
-
const transaction = JSON.parse(req.body);
|
|
27
|
-
logger.info(`received request`, {
|
|
28
|
-
type: transaction.type,
|
|
29
|
-
});
|
|
30
|
-
if (transaction.status === 'authorized') {
|
|
31
|
-
const userId = transaction.refno2;
|
|
32
|
-
const referenceId = Buffer.from(transaction.refno, 'base64').toString('hex');
|
|
33
|
-
try {
|
|
34
|
-
if (transaction.type === 'card_check') {
|
|
35
|
-
const paymentProviderId = referenceId;
|
|
36
|
-
const paymentCredentials = await services.orders.registerPaymentCredentials(paymentProviderId, { userId, transactionContext: { transactionId: transaction.transactionId } });
|
|
37
|
-
logger.info(`registered payment credentials for ${userId}`, {
|
|
38
|
-
userId,
|
|
39
|
-
});
|
|
40
|
-
reply.status(200);
|
|
41
|
-
return reply.send(paymentCredentials);
|
|
42
|
-
}
|
|
43
|
-
if (transaction.type === 'payment') {
|
|
44
|
-
const orderPaymentId = referenceId;
|
|
45
|
-
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
46
|
-
orderPaymentId,
|
|
47
|
-
});
|
|
48
|
-
if (!orderPayment)
|
|
49
|
-
throw new Error(`Order Payment with id ${orderPaymentId} not found`);
|
|
50
|
-
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
51
|
-
paymentContext: { userId, transactionId: transaction.transactionId },
|
|
52
|
-
});
|
|
53
|
-
if (!order)
|
|
54
|
-
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
55
|
-
reply.status(200);
|
|
56
|
-
logger.info(`confirmed checkout for order ${order.orderNumber}`, {
|
|
57
|
-
orderId: order._id,
|
|
58
|
-
});
|
|
59
|
-
return reply.send(order);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
logger.error(e);
|
|
64
|
-
reply.status(500);
|
|
65
|
-
return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
reply.status(404);
|
|
70
|
-
return reply.send();
|
|
71
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/payment/invoice.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { OrderPricingSheet, PaymentAdapter, PaymentDirector, PaymentError, } from '@unchainedshop/core';
|
|
2
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
-
const logger = createLogger('unchained:paypal-checkout');
|
|
4
|
-
let checkoutNodeJssdk;
|
|
5
|
-
try {
|
|
6
|
-
checkoutNodeJssdk = await import('@paypal/checkout-server-sdk');
|
|
7
|
-
}
|
|
8
|
-
catch {
|
|
9
|
-
logger.warn("npm dependency '@paypal/checkout-server-sdk' is not installed, paypal adapter will not work");
|
|
10
|
-
}
|
|
11
|
-
const { PAYPAL_CLIENT_ID, PAYPAL_SECRET, PAYPAL_ENVIRONMENT = 'sandbox' } = process.env;
|
|
12
|
-
const environment = () => {
|
|
13
|
-
const clientId = PAYPAL_CLIENT_ID;
|
|
14
|
-
const clientSecret = PAYPAL_SECRET;
|
|
15
|
-
return PAYPAL_ENVIRONMENT !== 'live'
|
|
16
|
-
? new checkoutNodeJssdk.core.SandboxEnvironment(clientId, clientSecret)
|
|
17
|
-
: new checkoutNodeJssdk.core.LiveEnvironment(clientId, clientSecret);
|
|
18
|
-
};
|
|
19
|
-
const roundToDecimals = (number, decimals) => {
|
|
20
|
-
const num = Math.pow(10, decimals);
|
|
21
|
-
return Math.round(number * num) / num;
|
|
22
|
-
};
|
|
23
|
-
const PaypalCheckout = {
|
|
24
|
-
...PaymentAdapter,
|
|
25
|
-
key: 'shop.unchained.payment.paypal',
|
|
26
|
-
label: 'Paypal',
|
|
27
|
-
version: '1.0.1',
|
|
28
|
-
initialConfiguration: [],
|
|
29
|
-
typeSupported: (type) => {
|
|
30
|
-
return type === 'GENERIC';
|
|
31
|
-
},
|
|
32
|
-
actions: (config, context) => {
|
|
33
|
-
const adapter = {
|
|
34
|
-
...PaymentAdapter.actions(config, context),
|
|
35
|
-
configurationError: () => {
|
|
36
|
-
const publicCredentialsValid = PAYPAL_CLIENT_ID && PAYPAL_SECRET;
|
|
37
|
-
if (!publicCredentialsValid) {
|
|
38
|
-
return PaymentError.WRONG_CREDENTIALS;
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
},
|
|
42
|
-
isActive: () => {
|
|
43
|
-
if (adapter.configurationError() === null)
|
|
44
|
-
return true;
|
|
45
|
-
return false;
|
|
46
|
-
},
|
|
47
|
-
isPayLaterAllowed: () => {
|
|
48
|
-
return false;
|
|
49
|
-
},
|
|
50
|
-
sign: async () => {
|
|
51
|
-
return PAYPAL_CLIENT_ID || null;
|
|
52
|
-
},
|
|
53
|
-
charge: async ({ orderID }) => {
|
|
54
|
-
const { order } = context;
|
|
55
|
-
if (!order)
|
|
56
|
-
throw new Error('Order missing in payment context');
|
|
57
|
-
if (!orderID) {
|
|
58
|
-
throw new Error('You have to provide orderID in paymentContext');
|
|
59
|
-
}
|
|
60
|
-
try {
|
|
61
|
-
const request = new checkoutNodeJssdk.orders.OrdersGetRequest(orderID);
|
|
62
|
-
const client = new checkoutNodeJssdk.core.PayPalHttpClient(environment());
|
|
63
|
-
const paypalOrder = await client.execute(request);
|
|
64
|
-
const pricing = OrderPricingSheet({
|
|
65
|
-
calculation: order.calculation,
|
|
66
|
-
currencyCode: order.currencyCode,
|
|
67
|
-
});
|
|
68
|
-
const ourTotal = roundToDecimals(pricing.total({ useNetPrice: false }).amount / 100, 2);
|
|
69
|
-
const paypalTotal = roundToDecimals(paypalOrder.result.purchase_units[0].amount.value, 2);
|
|
70
|
-
if (ourTotal === paypalTotal) {
|
|
71
|
-
return order;
|
|
72
|
-
}
|
|
73
|
-
logger.warn('Missmatch PAYPAL ORDER', JSON.stringify(paypalOrder.result, null, 2));
|
|
74
|
-
logger.debug('OUR ORDER', order);
|
|
75
|
-
logger.debug('OUR PRICE', pricing);
|
|
76
|
-
throw new Error(`Payment mismatch`);
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
logger.warn(e);
|
|
80
|
-
throw new Error(e);
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
return adapter;
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
PaymentDirector.registerAdapter(PaypalCheckout);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const payrexxHandler: (request: any, response: any) => Promise<void>;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
const logger = createLogger('unchained:payrexx:handler');
|
|
3
|
-
export const payrexxHandler = async (request, response) => {
|
|
4
|
-
const resolvedContext = request.unchainedContext;
|
|
5
|
-
const { modules, services } = resolvedContext;
|
|
6
|
-
const { transaction } = request.body;
|
|
7
|
-
if (!transaction) {
|
|
8
|
-
logger.info(`unhandled event type`, {
|
|
9
|
-
type: Object.keys(request.body).join(','),
|
|
10
|
-
});
|
|
11
|
-
response.status(200).send({
|
|
12
|
-
ignored: true,
|
|
13
|
-
message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
|
|
14
|
-
});
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if (transaction.referenceId === '__IGNORE_WEBHOOK__' || transaction.status === 'waiting') {
|
|
18
|
-
logger.info(`unhandled transaction state: ${transaction.status}`);
|
|
19
|
-
response.status(200).send({
|
|
20
|
-
ignored: true,
|
|
21
|
-
message: `Unhandled transaction state: ${transaction.status}`,
|
|
22
|
-
});
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
logger.info(`Processing event`, {
|
|
26
|
-
transactionId: transaction.id,
|
|
27
|
-
});
|
|
28
|
-
try {
|
|
29
|
-
if (transaction.preAuthorizationId) {
|
|
30
|
-
const { referenceId: paymentProviderId, invoice } = transaction;
|
|
31
|
-
const userId = '';
|
|
32
|
-
logger.info(`register credentials for: ${userId}`);
|
|
33
|
-
await services.orders.registerPaymentCredentials(paymentProviderId, {
|
|
34
|
-
userId,
|
|
35
|
-
transactionContext: { gatewayId: invoice.paymentRequestId },
|
|
36
|
-
});
|
|
37
|
-
logger.info(`registration successful`, {
|
|
38
|
-
paymentProviderId,
|
|
39
|
-
userId,
|
|
40
|
-
});
|
|
41
|
-
response.status(200).send({
|
|
42
|
-
message: 'registration successful',
|
|
43
|
-
paymentProviderId,
|
|
44
|
-
userId,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
const { referenceId: orderPaymentId, invoice } = transaction;
|
|
49
|
-
logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
|
|
50
|
-
await modules.orders.payments.logEvent(orderPaymentId, {
|
|
51
|
-
transactionId: transaction.id,
|
|
52
|
-
});
|
|
53
|
-
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
54
|
-
orderPaymentId,
|
|
55
|
-
});
|
|
56
|
-
if (!orderPayment) {
|
|
57
|
-
throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
58
|
-
}
|
|
59
|
-
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
60
|
-
paymentContext: {
|
|
61
|
-
gatewayId: invoice.paymentRequestId,
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
if (!order)
|
|
65
|
-
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
66
|
-
logger.info(`checkout successful`, {
|
|
67
|
-
orderPaymentId,
|
|
68
|
-
orderId: order._id,
|
|
69
|
-
});
|
|
70
|
-
response.status(200).send({
|
|
71
|
-
message: 'checkout successful',
|
|
72
|
-
orderId: order._id,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
logger.error(error, {
|
|
78
|
-
transactionId: transaction.id,
|
|
79
|
-
});
|
|
80
|
-
response.status(500).send({
|
|
81
|
-
message: error.message,
|
|
82
|
-
name: error.name,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
const logger = createLogger('unchained:payrexx:handler');
|
|
3
|
-
export const payrexxHandler = async (request, reply) => {
|
|
4
|
-
const resolvedContext = request.unchainedContext;
|
|
5
|
-
const { modules, services } = resolvedContext;
|
|
6
|
-
const { transaction } = request.body;
|
|
7
|
-
if (!transaction) {
|
|
8
|
-
logger.info(`unhandled event type`, {
|
|
9
|
-
type: Object.keys(request.body).join(','),
|
|
10
|
-
});
|
|
11
|
-
reply.status(200);
|
|
12
|
-
return reply.send({
|
|
13
|
-
success: false,
|
|
14
|
-
ignored: true,
|
|
15
|
-
message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
if (transaction.referenceId === '__IGNORE_WEBHOOK__' || transaction.status === 'waiting') {
|
|
19
|
-
logger.info(`unhandled transaction state: ${transaction.status}`);
|
|
20
|
-
reply.status(200);
|
|
21
|
-
return reply.send({
|
|
22
|
-
success: false,
|
|
23
|
-
ignored: true,
|
|
24
|
-
message: `Unhandled transaction state: ${transaction.status}`,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
logger.info(`Processing event`, {
|
|
28
|
-
transactionId: transaction.id,
|
|
29
|
-
});
|
|
30
|
-
try {
|
|
31
|
-
if (transaction.preAuthorizationId) {
|
|
32
|
-
const { referenceId: paymentProviderId, invoice } = transaction;
|
|
33
|
-
const userId = '';
|
|
34
|
-
logger.info(`register credentials for: ${userId}`);
|
|
35
|
-
await services.orders.registerPaymentCredentials(paymentProviderId, {
|
|
36
|
-
userId,
|
|
37
|
-
transactionContext: { gatewayId: invoice.paymentRequestId },
|
|
38
|
-
});
|
|
39
|
-
logger.info(`registration successful`, {
|
|
40
|
-
paymentProviderId,
|
|
41
|
-
userId,
|
|
42
|
-
});
|
|
43
|
-
reply.status(200);
|
|
44
|
-
return reply.send({
|
|
45
|
-
success: true,
|
|
46
|
-
paymentProviderId,
|
|
47
|
-
userId,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
const { referenceId: orderPaymentId, invoice } = transaction;
|
|
52
|
-
logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
|
|
53
|
-
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
54
|
-
orderPaymentId,
|
|
55
|
-
});
|
|
56
|
-
if (!orderPayment) {
|
|
57
|
-
throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
58
|
-
}
|
|
59
|
-
await modules.orders.payments.logEvent(orderPaymentId, {
|
|
60
|
-
transactionId: transaction.id,
|
|
61
|
-
});
|
|
62
|
-
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
63
|
-
paymentContext: {
|
|
64
|
-
gatewayId: invoice.paymentRequestId,
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
if (!order)
|
|
68
|
-
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
69
|
-
logger.info(`checkout successful`, {
|
|
70
|
-
orderPaymentId,
|
|
71
|
-
orderId: order._id,
|
|
72
|
-
});
|
|
73
|
-
reply.status(200);
|
|
74
|
-
return reply.send({
|
|
75
|
-
success: true,
|
|
76
|
-
orderId: order._id,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
logger.error(error, {
|
|
82
|
-
transactionId: transaction.id,
|
|
83
|
-
});
|
|
84
|
-
reply.status(500);
|
|
85
|
-
return reply.send({
|
|
86
|
-
success: false,
|
|
87
|
-
message: error.message,
|
|
88
|
-
name: error.name,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const postfinanceCheckoutHandler: (req: any, res: any) => Promise<void>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { getTransaction, getTransactionCompletion } from "./api.js";
|
|
3
|
-
const logger = createLogger('unchained:postfinance-checkout:handler');
|
|
4
|
-
export const postfinanceCheckoutHandler = async (req, res) => {
|
|
5
|
-
const context = req.unchainedContext;
|
|
6
|
-
const { services, modules } = context;
|
|
7
|
-
const data = req.body;
|
|
8
|
-
if (data.listenerEntityTechnicalName === 'TransactionCompletion') {
|
|
9
|
-
try {
|
|
10
|
-
const transactionCompletion = await getTransactionCompletion(data.entityId);
|
|
11
|
-
const transaction = await getTransaction(transactionCompletion ? transactionCompletion.linkedTransaction : data.entityId);
|
|
12
|
-
const { orderPaymentId } = transaction.metaData;
|
|
13
|
-
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
14
|
-
orderPaymentId,
|
|
15
|
-
});
|
|
16
|
-
if (!orderPayment)
|
|
17
|
-
throw new Error('Order Payment not found');
|
|
18
|
-
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
19
|
-
paymentContext: {
|
|
20
|
-
transactionId: transactionCompletion.linkedTransaction,
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
if (!order)
|
|
24
|
-
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
25
|
-
logger.info(`Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData?.orderPaymentId} as paid`);
|
|
26
|
-
res.status(200).send(`Order marked as paid: ${order.orderNumber}`);
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
logger.error(e);
|
|
30
|
-
res.status(500).send({ name: e.name, code: e.code, message: e.message });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
logger.error(`Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
|
|
35
|
-
res.status(404).end();
|
|
36
|
-
}
|
|
37
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { getTransaction, getTransactionCompletion } from "./api.js";
|
|
3
|
-
const logger = createLogger('unchained:postfinance-checkout:handler');
|
|
4
|
-
export const postfinanceCheckoutHandler = async (req, reply) => {
|
|
5
|
-
const context = req.unchainedContext;
|
|
6
|
-
const { services, modules } = context;
|
|
7
|
-
const data = req.body;
|
|
8
|
-
if (data.listenerEntityTechnicalName === 'TransactionCompletion') {
|
|
9
|
-
try {
|
|
10
|
-
const transactionCompletion = await getTransactionCompletion(data.entityId);
|
|
11
|
-
const transaction = await getTransaction(transactionCompletion ? transactionCompletion.linkedTransaction : data.entityId);
|
|
12
|
-
const { orderPaymentId } = transaction.metaData;
|
|
13
|
-
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
14
|
-
orderPaymentId,
|
|
15
|
-
});
|
|
16
|
-
if (!orderPayment)
|
|
17
|
-
throw new Error('Order Payment not found');
|
|
18
|
-
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
19
|
-
paymentContext: {
|
|
20
|
-
transactionId: transaction.id,
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
if (!order)
|
|
24
|
-
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
25
|
-
logger.info(`Transaction ${transaction.id} marked order payment ID ${transaction.metaData?.orderPaymentId} as paid`);
|
|
26
|
-
reply.status(200);
|
|
27
|
-
return reply.send({ success: true, orderNumber: order.orderNumber });
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
logger.error(e);
|
|
31
|
-
reply.status(500);
|
|
32
|
-
return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
logger.error(`Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
|
|
37
|
-
reply.status(404);
|
|
38
|
-
return reply.send();
|
|
39
|
-
}
|
|
40
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const saferpayHandler: (request: any, response: any) => Promise<void>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { buildSignature } from "./buildSignature.js";
|
|
3
|
-
import { timingSafeStringEqual } from '@unchainedshop/utils';
|
|
4
|
-
const logger = createLogger('unchained:saferpay:handler');
|
|
5
|
-
export const saferpayHandler = async (request, response) => {
|
|
6
|
-
const resolvedContext = request.unchainedContext;
|
|
7
|
-
const { modules, services } = resolvedContext;
|
|
8
|
-
const { orderPaymentId, signature, transactionId } = request.query;
|
|
9
|
-
const isValidRequest = typeof orderPaymentId === 'string' &&
|
|
10
|
-
typeof signature === 'string' &&
|
|
11
|
-
typeof transactionId === 'string' &&
|
|
12
|
-
orderPaymentId &&
|
|
13
|
-
transactionId &&
|
|
14
|
-
signature;
|
|
15
|
-
if ((request.method !== 'GET' && request.method !== 'HEAD') || !isValidRequest) {
|
|
16
|
-
logger.warn(`unhandled http method ${request.method} or orderPaymentId missing in query`);
|
|
17
|
-
response.status(404).end();
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
|
|
22
|
-
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
23
|
-
orderPaymentId,
|
|
24
|
-
});
|
|
25
|
-
if (!orderPayment) {
|
|
26
|
-
throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
27
|
-
}
|
|
28
|
-
const correctSignature = await buildSignature(transactionId, orderPaymentId);
|
|
29
|
-
if (!(await timingSafeStringEqual(correctSignature, signature))) {
|
|
30
|
-
throw new Error('Invalid signature');
|
|
31
|
-
}
|
|
32
|
-
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
33
|
-
paymentContext: {
|
|
34
|
-
transactionId,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
if (!order)
|
|
38
|
-
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
39
|
-
logger.info(`checkout successful`, {
|
|
40
|
-
orderPaymentId,
|
|
41
|
-
orderId: order._id,
|
|
42
|
-
});
|
|
43
|
-
response.status(200).send({
|
|
44
|
-
message: 'checkout successful',
|
|
45
|
-
orderPaymentId,
|
|
46
|
-
orderId: order._id,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
logger.error(error, {
|
|
51
|
-
orderPaymentId,
|
|
52
|
-
transactionId,
|
|
53
|
-
});
|
|
54
|
-
response.status(500).send({
|
|
55
|
-
message: error.message,
|
|
56
|
-
name: error.name,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { buildSignature } from "./buildSignature.js";
|
|
3
|
-
import { timingSafeStringEqual } from '@unchainedshop/utils';
|
|
4
|
-
const logger = createLogger('unchained:saferpay:handler');
|
|
5
|
-
export const saferpayHandler = async (request, reply) => {
|
|
6
|
-
const resolvedContext = request.unchainedContext;
|
|
7
|
-
const { modules, services } = resolvedContext;
|
|
8
|
-
const { orderPaymentId, signature, transactionId } = request.query;
|
|
9
|
-
const isValidRequest = typeof orderPaymentId === 'string' &&
|
|
10
|
-
typeof signature === 'string' &&
|
|
11
|
-
typeof transactionId === 'string' &&
|
|
12
|
-
orderPaymentId &&
|
|
13
|
-
transactionId &&
|
|
14
|
-
signature;
|
|
15
|
-
if (!isValidRequest) {
|
|
16
|
-
logger.warn(`orderPaymentId missing in query`);
|
|
17
|
-
reply.status(404);
|
|
18
|
-
return reply.send();
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
|
|
22
|
-
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
23
|
-
orderPaymentId,
|
|
24
|
-
});
|
|
25
|
-
if (!orderPayment) {
|
|
26
|
-
throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
27
|
-
}
|
|
28
|
-
const correctSignature = await buildSignature(transactionId, orderPaymentId);
|
|
29
|
-
if (!(await timingSafeStringEqual(correctSignature, signature))) {
|
|
30
|
-
throw new Error('Invalid signature');
|
|
31
|
-
}
|
|
32
|
-
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
33
|
-
paymentContext: {
|
|
34
|
-
transactionId,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
if (!order)
|
|
38
|
-
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
39
|
-
logger.info(`checkout successful`, {
|
|
40
|
-
orderPaymentId,
|
|
41
|
-
orderId: order._id,
|
|
42
|
-
});
|
|
43
|
-
reply.status(200);
|
|
44
|
-
return reply.send({
|
|
45
|
-
success: true,
|
|
46
|
-
orderPaymentId,
|
|
47
|
-
orderId: order._id,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
logger.error(error, {
|
|
52
|
-
orderPaymentId,
|
|
53
|
-
transactionId,
|
|
54
|
-
});
|
|
55
|
-
reply.status(500);
|
|
56
|
-
return reply.send({
|
|
57
|
-
success: false,
|
|
58
|
-
message: error.message,
|
|
59
|
-
name: error.name,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
};
|