@unchainedshop/plugins 4.6.2 → 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/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/index.d.ts +5 -4
- package/lib/files/gridfs/index.js +30 -3
- package/lib/files/minio/index.d.ts +4 -5
- package/lib/files/minio/index.js +18 -157
- package/lib/payment/apple-iap/adapter.d.ts +2 -1
- package/lib/payment/apple-iap/adapter.js +2 -3
- package/lib/payment/apple-iap/index.d.ts +6 -4
- package/lib/payment/apple-iap/index.js +28 -3
- package/lib/payment/cryptopay/index.d.ts +5 -4
- package/lib/payment/cryptopay/index.js +31 -3
- package/lib/payment/datatrans-v2/index.d.ts +4 -1
- package/lib/payment/datatrans-v2/index.js +17 -400
- package/lib/payment/payrexx/index.d.ts +4 -1
- package/lib/payment/payrexx/index.js +19 -158
- package/lib/payment/postfinance-checkout/index.d.ts +5 -0
- package/lib/payment/postfinance-checkout/index.js +25 -186
- 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/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/package.json +15 -10
- package/lib/delivery/post.d.ts +0 -1
- package/lib/delivery/post.js +0 -23
- package/lib/delivery/send-message.d.ts +0 -1
- package/lib/delivery/send-message.js +0 -40
- package/lib/delivery/stores.d.ts +0 -1
- package/lib/delivery/stores.js +0 -43
- package/lib/enrollments/licensed.d.ts +0 -4
- package/lib/enrollments/licensed.js +0 -52
- 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/local-search.js +0 -66
- package/lib/filters/strict-equal.d.ts +0 -1
- package/lib/filters/strict-equal.js +0 -24
- 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/apple-iap/handler-fastify.js +0 -102
- 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/cryptopay/plugin.js +0 -159
- 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-prepaid.js +0 -30
- package/lib/payment/invoice.d.ts +0 -1
- package/lib/payment/invoice.js +0 -27
- 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/delivery-swiss-tax.d.ts +0 -2
- package/lib/pricing/delivery-swiss-tax.js +0 -62
- package/lib/pricing/discount-100-off.d.ts +0 -2
- package/lib/pricing/discount-100-off.js +0 -30
- package/lib/pricing/discount-half-price-manual.d.ts +0 -2
- package/lib/pricing/discount-half-price-manual.js +0 -30
- package/lib/pricing/discount-half-price.d.ts +0 -2
- package/lib/pricing/discount-half-price.js +0 -33
- package/lib/pricing/free-delivery.d.ts +0 -2
- package/lib/pricing/free-delivery.js +0 -27
- package/lib/pricing/free-payment.d.ts +0 -2
- package/lib/pricing/free-payment.js +0 -27
- package/lib/pricing/order-delivery.d.ts +0 -2
- package/lib/pricing/order-delivery.js +0 -33
- package/lib/pricing/order-discount.d.ts +0 -2
- package/lib/pricing/order-discount.js +0 -74
- package/lib/pricing/order-items-discount.d.ts +0 -2
- package/lib/pricing/order-items-discount.js +0 -50
- package/lib/pricing/order-items.d.ts +0 -2
- package/lib/pricing/order-items.js +0 -43
- package/lib/pricing/order-payment.d.ts +0 -2
- package/lib/pricing/order-payment.js +0 -33
- 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-catalog-price.d.ts +0 -2
- package/lib/pricing/product-catalog-price.js +0 -60
- package/lib/pricing/product-discount.d.ts +0 -2
- package/lib/pricing/product-discount.js +0 -69
- package/lib/pricing/product-price-rateconversion.d.ts +0 -2
- package/lib/pricing/product-price-rateconversion.js +0 -53
- package/lib/pricing/product-round.d.ts +0 -10
- package/lib/pricing/product-round.js +0 -44
- package/lib/pricing/product-swiss-tax.d.ts +0 -2
- package/lib/pricing/product-swiss-tax.js +0 -76
- package/lib/quotations/manual.d.ts +0 -1
- package/lib/quotations/manual.js +0 -20
- package/lib/warehousing/eth-minter.d.ts +0 -1
- package/lib/warehousing/eth-minter.js +0 -120
- package/lib/warehousing/store.d.ts +0 -1
- package/lib/warehousing/store.js +0 -34
- package/lib/worker/budgetsms.d.ts +0 -9
- package/lib/worker/budgetsms.js +0 -169
- package/lib/worker/bulk-export.d.ts +0 -2
- package/lib/worker/bulk-export.js +0 -64
- package/lib/worker/bulk-import.d.ts +0 -2
- package/lib/worker/bulk-import.js +0 -65
- package/lib/worker/bulkgate.d.ts +0 -1
- package/lib/worker/bulkgate.js +0 -91
- package/lib/worker/email.d.ts +0 -1
- package/lib/worker/email.js +0 -136
- package/lib/worker/enrollment-order-generator.d.ts +0 -1
- package/lib/worker/enrollment-order-generator.js +0 -77
- package/lib/worker/error-notifications.d.ts +0 -9
- package/lib/worker/error-notifications.js +0 -61
- package/lib/worker/export-token.d.ts +0 -4
- package/lib/worker/export-token.js +0 -26
- package/lib/worker/external.d.ts +0 -2
- package/lib/worker/external.js +0 -13
- package/lib/worker/heartbeat.d.ts +0 -1
- package/lib/worker/heartbeat.js +0 -26
- package/lib/worker/http-request.d.ts +0 -8
- package/lib/worker/http-request.js +0 -56
- package/lib/worker/message.d.ts +0 -10
- package/lib/worker/message.js +0 -42
- package/lib/worker/push-notification.d.ts +0 -1
- package/lib/worker/push-notification.js +0 -87
- package/lib/worker/twilio.d.ts +0 -1
- package/lib/worker/twilio.js +0 -59
- package/lib/worker/update-coinbase-rates.d.ts +0 -1
- package/lib/worker/update-coinbase-rates.js +0 -59
- package/lib/worker/update-ecb-rates.d.ts +0 -1
- package/lib/worker/update-ecb-rates.js +0 -92
- package/lib/worker/update-token-ownership.d.ts +0 -3
- package/lib/worker/update-token-ownership.js +0 -57
- package/lib/worker/zombie-killer.d.ts +0 -13
- package/lib/worker/zombie-killer.js +0 -91
|
@@ -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
|
-
};
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { stripe } from "./stripe.js";
|
|
3
|
-
const logger = createLogger('unchained:stripe:handler');
|
|
4
|
-
export const WebhookEventTypes = {
|
|
5
|
-
PAYMENT_INTENT_SUCCEEDED: 'payment_intent.succeeded',
|
|
6
|
-
SETUP_INTENT_SUCCEEDED: 'setup_intent.succeeded',
|
|
7
|
-
};
|
|
8
|
-
export const stripeHandler = async (request, response) => {
|
|
9
|
-
const resolvedContext = request.unchainedContext;
|
|
10
|
-
const { modules, services } = resolvedContext;
|
|
11
|
-
let event;
|
|
12
|
-
try {
|
|
13
|
-
const sig = request.headers['stripe-signature'];
|
|
14
|
-
if (!sig) {
|
|
15
|
-
throw new Error('stripe-signature header was not provided for webhook');
|
|
16
|
-
}
|
|
17
|
-
if (!process.env.STRIPE_ENDPOINT_SECRET) {
|
|
18
|
-
throw new Error('env STRIPE_ENDPOINT_SECRET is required for webhook handling');
|
|
19
|
-
}
|
|
20
|
-
event = stripe.webhooks.constructEvent(request.body, sig, process.env.STRIPE_ENDPOINT_SECRET);
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
logger.error(`Error constructing event: ${err.message}`);
|
|
24
|
-
response.status(400).send({
|
|
25
|
-
message: err.message,
|
|
26
|
-
name: err.name,
|
|
27
|
-
});
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (!Object.values(WebhookEventTypes).includes(event.type)) {
|
|
31
|
-
logger.info(`unhandled event type`, {
|
|
32
|
-
type: event.type,
|
|
33
|
-
});
|
|
34
|
-
response.status(200).send({
|
|
35
|
-
ignored: true,
|
|
36
|
-
message: `Unhandled event type: ${event.type}. Supported types: ${Object.values(WebhookEventTypes).join(', ')}`,
|
|
37
|
-
});
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const environmentInMetadata = event.data?.object?.metadata?.environment || '';
|
|
41
|
-
const environmentInEnv = process.env.STRIPE_WEBHOOK_ENVIRONMENT || '';
|
|
42
|
-
if (environmentInMetadata !== environmentInEnv) {
|
|
43
|
-
logger.info(`unhandled event environment`, {
|
|
44
|
-
type: event.type,
|
|
45
|
-
environment: environmentInMetadata,
|
|
46
|
-
});
|
|
47
|
-
response.status(200).send({
|
|
48
|
-
ignored: true,
|
|
49
|
-
message: `Unhandled event environment: ${environmentInMetadata}. Supported environment: ${environmentInEnv}`,
|
|
50
|
-
});
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
logger.info(`Processing event`, {
|
|
54
|
-
type: event.type,
|
|
55
|
-
});
|
|
56
|
-
try {
|
|
57
|
-
if (event.type === WebhookEventTypes.PAYMENT_INTENT_SUCCEEDED) {
|
|
58
|
-
const paymentIntent = event.data.object;
|
|
59
|
-
const { orderPaymentId } = paymentIntent.metadata || {};
|
|
60
|
-
logger.info(`checkout with orderPaymentId: ${orderPaymentId}`, {
|
|
61
|
-
type: event.type,
|
|
62
|
-
});
|
|
63
|
-
await modules.orders.payments.logEvent(orderPaymentId, event);
|
|
64
|
-
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
65
|
-
orderPaymentId,
|
|
66
|
-
});
|
|
67
|
-
if (!orderPayment) {
|
|
68
|
-
throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
69
|
-
}
|
|
70
|
-
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
71
|
-
paymentContext: {
|
|
72
|
-
paymentIntentId: paymentIntent.id,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
if (!order)
|
|
76
|
-
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
77
|
-
logger.info(`checkout successful`, {
|
|
78
|
-
orderPaymentId,
|
|
79
|
-
orderId: order._id,
|
|
80
|
-
type: event.type,
|
|
81
|
-
});
|
|
82
|
-
response.status(200).send({
|
|
83
|
-
message: 'checkout successful',
|
|
84
|
-
orderId: order._id,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
else if (event.type === WebhookEventTypes.SETUP_INTENT_SUCCEEDED) {
|
|
88
|
-
const setupIntent = event.data.object;
|
|
89
|
-
const { paymentProviderId, userId } = setupIntent.metadata || {};
|
|
90
|
-
logger.info(`registered payment credential with paymentProviderId: ${paymentProviderId}`, {
|
|
91
|
-
type: event.type,
|
|
92
|
-
userId,
|
|
93
|
-
});
|
|
94
|
-
const paymentCredentials = await services.orders.registerPaymentCredentials(paymentProviderId, {
|
|
95
|
-
transactionContext: {
|
|
96
|
-
setupIntentId: setupIntent.id,
|
|
97
|
-
},
|
|
98
|
-
userId,
|
|
99
|
-
});
|
|
100
|
-
logger.info(`payment credentials registration successful`, {
|
|
101
|
-
userId,
|
|
102
|
-
paymentProviderId,
|
|
103
|
-
paymentCredentialsId: paymentCredentials?._id,
|
|
104
|
-
type: event.type,
|
|
105
|
-
});
|
|
106
|
-
response.status(200).send({
|
|
107
|
-
message: 'payment credentials registration successful',
|
|
108
|
-
paymentCredentialsId: paymentCredentials?._id,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
logger.error(error, {
|
|
114
|
-
type: event.type,
|
|
115
|
-
});
|
|
116
|
-
response.status(500).send({
|
|
117
|
-
message: error.message,
|
|
118
|
-
name: error.name,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
};
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { stripe } from "./stripe.js";
|
|
3
|
-
const logger = createLogger('unchained:stripe:handler');
|
|
4
|
-
export const WebhookEventTypes = {
|
|
5
|
-
PAYMENT_INTENT_SUCCEEDED: 'payment_intent.succeeded',
|
|
6
|
-
SETUP_INTENT_SUCCEEDED: 'setup_intent.succeeded',
|
|
7
|
-
};
|
|
8
|
-
export const stripeHandler = async (req, reply) => {
|
|
9
|
-
const resolvedContext = req.unchainedContext;
|
|
10
|
-
const { modules, services } = resolvedContext;
|
|
11
|
-
let event;
|
|
12
|
-
try {
|
|
13
|
-
const sig = req.headers['stripe-signature'];
|
|
14
|
-
if (!process.env.STRIPE_ENDPOINT_SECRET) {
|
|
15
|
-
throw new Error('env STRIPE_ENDPOINT_SECRET is required for webhook handling');
|
|
16
|
-
}
|
|
17
|
-
if (!sig) {
|
|
18
|
-
throw new Error('stripe-signature header was not provided for webhook');
|
|
19
|
-
}
|
|
20
|
-
event = stripe.webhooks.constructEvent(req.body, sig, process.env.STRIPE_ENDPOINT_SECRET);
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
logger.error(`Error constructing event: ${err.message}`);
|
|
24
|
-
reply.status(400);
|
|
25
|
-
return reply.send({
|
|
26
|
-
success: false,
|
|
27
|
-
message: err.message,
|
|
28
|
-
name: err.name,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (!Object.values(WebhookEventTypes).includes(event.type)) {
|
|
32
|
-
logger.info(`unhandled event type`, {
|
|
33
|
-
type: event.type,
|
|
34
|
-
});
|
|
35
|
-
reply.status(200);
|
|
36
|
-
return reply.send({
|
|
37
|
-
success: false,
|
|
38
|
-
ignored: true,
|
|
39
|
-
name: 'UNHANDLED_EVENT_TYPE',
|
|
40
|
-
message: `Unhandled event type: ${event.type}. Supported types: ${Object.values(WebhookEventTypes).join(', ')}`,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
const environmentInMetadata = event.data?.object?.metadata?.environment || '';
|
|
44
|
-
const environmentInEnv = process.env.STRIPE_WEBHOOK_ENVIRONMENT || '';
|
|
45
|
-
if (environmentInMetadata !== environmentInEnv) {
|
|
46
|
-
logger.info(`unhandled event environment`, {
|
|
47
|
-
type: event.type,
|
|
48
|
-
environment: environmentInMetadata,
|
|
49
|
-
});
|
|
50
|
-
reply.status(200);
|
|
51
|
-
return reply.send({
|
|
52
|
-
success: false,
|
|
53
|
-
ignored: true,
|
|
54
|
-
name: 'UNHANDLED_EVENT_ENVIRONMENT',
|
|
55
|
-
message: `Unhandled event environment: ${environmentInMetadata}. Supported environment: ${environmentInEnv}`,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
logger.info(`Processing event`, {
|
|
59
|
-
type: event.type,
|
|
60
|
-
});
|
|
61
|
-
try {
|
|
62
|
-
if (event.type === WebhookEventTypes.PAYMENT_INTENT_SUCCEEDED) {
|
|
63
|
-
const paymentIntent = event.data.object;
|
|
64
|
-
const { orderPaymentId } = paymentIntent.metadata || {};
|
|
65
|
-
logger.info(`checkout with orderPaymentId: ${orderPaymentId}`, {
|
|
66
|
-
type: event.type,
|
|
67
|
-
});
|
|
68
|
-
await modules.orders.payments.logEvent(orderPaymentId, event);
|
|
69
|
-
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
70
|
-
orderPaymentId,
|
|
71
|
-
});
|
|
72
|
-
if (!orderPayment) {
|
|
73
|
-
throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
74
|
-
}
|
|
75
|
-
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
76
|
-
paymentContext: {
|
|
77
|
-
paymentIntentId: paymentIntent.id,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
if (!order)
|
|
81
|
-
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
82
|
-
logger.info(`checkout successful`, {
|
|
83
|
-
orderPaymentId,
|
|
84
|
-
orderId: order._id,
|
|
85
|
-
type: event.type,
|
|
86
|
-
});
|
|
87
|
-
reply.status(200);
|
|
88
|
-
return reply.send({
|
|
89
|
-
success: true,
|
|
90
|
-
orderId: order._id,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
else if (event.type === WebhookEventTypes.SETUP_INTENT_SUCCEEDED) {
|
|
94
|
-
const setupIntent = event.data.object;
|
|
95
|
-
const { paymentProviderId, userId } = setupIntent.metadata || {};
|
|
96
|
-
logger.info(`registered payment credential with paymentProviderId: ${paymentProviderId}`, {
|
|
97
|
-
type: event.type,
|
|
98
|
-
userId,
|
|
99
|
-
});
|
|
100
|
-
const paymentCredentials = await services.orders.registerPaymentCredentials(paymentProviderId, {
|
|
101
|
-
transactionContext: {
|
|
102
|
-
setupIntentId: setupIntent.id,
|
|
103
|
-
},
|
|
104
|
-
userId,
|
|
105
|
-
});
|
|
106
|
-
logger.info(`payment credentials registration successful`, {
|
|
107
|
-
userId,
|
|
108
|
-
paymentProviderId,
|
|
109
|
-
paymentCredentialsId: paymentCredentials?._id,
|
|
110
|
-
type: event.type,
|
|
111
|
-
});
|
|
112
|
-
reply.status(200);
|
|
113
|
-
return reply.send({
|
|
114
|
-
success: true,
|
|
115
|
-
message: 'payment credentials registration successful',
|
|
116
|
-
paymentCredentialsId: paymentCredentials?._id,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
logger.error(error, {
|
|
122
|
-
type: event.type,
|
|
123
|
-
});
|
|
124
|
-
reply.status(500);
|
|
125
|
-
return reply.send({
|
|
126
|
-
success: false,
|
|
127
|
-
message: error.message,
|
|
128
|
-
name: error.name,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import connectCryptoToExpress from "./crypto-express.js";
|
|
3
|
-
import connectBaseToExpress from "./base-express.js";
|
|
4
|
-
import { datatransHandler } from "../payment/datatrans-v2/handler-express.js";
|
|
5
|
-
import { stripeHandler } from "../payment/stripe/handler-express.js";
|
|
6
|
-
import { postfinanceCheckoutHandler } from "../payment/postfinance-checkout/handler-express.js";
|
|
7
|
-
import { appleIAPHandler } from "../payment/apple-iap/handler-express.js";
|
|
8
|
-
import { payrexxHandler } from "../payment/payrexx/handler-express.js";
|
|
9
|
-
import { saferpayHandler } from "../payment/saferpay/handler-express.js";
|
|
10
|
-
import { configureGenerateOrderAutoscheduling } from "../worker/enrollment-order-generator.js";
|
|
11
|
-
const { STRIPE_WEBHOOK_PATH = '/payment/stripe', PAYREXX_WEBHOOK_PATH = '/payment/payrexx', PFCHECKOUT_WEBHOOK_PATH = '/payment/postfinance-checkout', DATATRANS_WEBHOOK_PATH = '/payment/datatrans/webhook', APPLE_IAP_WEBHOOK_PATH = '/payment/apple-iap', SAFERPAY_WEBHOOK_PATH = '/payment/saferpay/webhook', } = process.env;
|
|
12
|
-
export default (app, { unchainedAPI }) => {
|
|
13
|
-
connectBaseToExpress(app);
|
|
14
|
-
connectCryptoToExpress(app, unchainedAPI);
|
|
15
|
-
app.use(STRIPE_WEBHOOK_PATH, express.raw({ type: 'application/json' }), stripeHandler);
|
|
16
|
-
app.use(PFCHECKOUT_WEBHOOK_PATH, express.json(), postfinanceCheckoutHandler);
|
|
17
|
-
app.use(DATATRANS_WEBHOOK_PATH, express.text({
|
|
18
|
-
type: 'application/json',
|
|
19
|
-
}), datatransHandler);
|
|
20
|
-
app.use(APPLE_IAP_WEBHOOK_PATH, express.json({
|
|
21
|
-
strict: false,
|
|
22
|
-
}), appleIAPHandler);
|
|
23
|
-
app.use(PAYREXX_WEBHOOK_PATH, express.json({ type: 'application/json' }), payrexxHandler);
|
|
24
|
-
app.use(SAFERPAY_WEBHOOK_PATH, saferpayHandler);
|
|
25
|
-
configureGenerateOrderAutoscheduling();
|
|
26
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import connectCryptoToFastify from "./crypto-fastify.js";
|
|
2
|
-
import connectBaseToFastify from "./base-fastify.js";
|
|
3
|
-
import { stripeHandler } from "../payment/stripe/handler-fastify.js";
|
|
4
|
-
import { postfinanceCheckoutHandler } from "../payment/postfinance-checkout/handler-fastify.js";
|
|
5
|
-
import { datatransHandler } from "../payment/datatrans-v2/handler-fastify.js";
|
|
6
|
-
import { appleIAPHandler } from "../payment/apple-iap/handler-fastify.js";
|
|
7
|
-
import { payrexxHandler } from "../payment/payrexx/handler-fastify.js";
|
|
8
|
-
import { saferpayHandler } from "../payment/saferpay/handler-fastify.js";
|
|
9
|
-
import { configureGenerateOrderAutoscheduling } from "../worker/enrollment-order-generator.js";
|
|
10
|
-
const { STRIPE_WEBHOOK_PATH = '/payment/stripe', PAYREXX_WEBHOOK_PATH = '/payment/payrexx', PFCHECKOUT_WEBHOOK_PATH = '/payment/postfinance-checkout', DATATRANS_WEBHOOK_PATH = '/payment/datatrans/webhook', APPLE_IAP_WEBHOOK_PATH = '/payment/apple-iap', SAFERPAY_WEBHOOK_PATH = '/payment/saferpay/webhook', } = process.env;
|
|
11
|
-
export default (fastify, { unchainedAPI }) => {
|
|
12
|
-
connectBaseToFastify(fastify);
|
|
13
|
-
connectCryptoToFastify(fastify, unchainedAPI);
|
|
14
|
-
fastify.register((s, opts, registered) => {
|
|
15
|
-
s.addContentTypeParser('application/json', { parseAs: 'string', bodyLimit: 1024 * 1024 }, s.defaultTextParser);
|
|
16
|
-
s.route({
|
|
17
|
-
url: STRIPE_WEBHOOK_PATH,
|
|
18
|
-
method: 'POST',
|
|
19
|
-
handler: stripeHandler,
|
|
20
|
-
});
|
|
21
|
-
s.route({
|
|
22
|
-
url: DATATRANS_WEBHOOK_PATH,
|
|
23
|
-
method: 'POST',
|
|
24
|
-
handler: datatransHandler,
|
|
25
|
-
});
|
|
26
|
-
registered();
|
|
27
|
-
});
|
|
28
|
-
fastify.route({
|
|
29
|
-
url: PFCHECKOUT_WEBHOOK_PATH,
|
|
30
|
-
method: 'POST',
|
|
31
|
-
handler: postfinanceCheckoutHandler,
|
|
32
|
-
});
|
|
33
|
-
fastify.route({
|
|
34
|
-
url: APPLE_IAP_WEBHOOK_PATH,
|
|
35
|
-
method: 'POST',
|
|
36
|
-
handler: appleIAPHandler,
|
|
37
|
-
});
|
|
38
|
-
fastify.route({
|
|
39
|
-
url: PAYREXX_WEBHOOK_PATH,
|
|
40
|
-
method: 'POST',
|
|
41
|
-
handler: payrexxHandler,
|
|
42
|
-
});
|
|
43
|
-
fastify.route({
|
|
44
|
-
url: SAFERPAY_WEBHOOK_PATH,
|
|
45
|
-
method: 'GET',
|
|
46
|
-
handler: saferpayHandler,
|
|
47
|
-
});
|
|
48
|
-
configureGenerateOrderAutoscheduling();
|
|
49
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import handler from "../files/gridfs/handler-fastify.js";
|
|
2
|
-
const { GRIDFS_PUT_SERVER_PATH = '/gridfs' } = process.env;
|
|
3
|
-
export default (fastify) => {
|
|
4
|
-
fastify.register((s, opts, registered) => {
|
|
5
|
-
s.removeAllContentTypeParsers();
|
|
6
|
-
s.addContentTypeParser('*', function (req, payload, done) {
|
|
7
|
-
done(null);
|
|
8
|
-
});
|
|
9
|
-
s.route({
|
|
10
|
-
url: GRIDFS_PUT_SERVER_PATH + '/:directoryName/:fileName',
|
|
11
|
-
method: ['GET', 'PUT', 'OPTIONS'],
|
|
12
|
-
handler,
|
|
13
|
-
});
|
|
14
|
-
registered();
|
|
15
|
-
});
|
|
16
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import handler from "../payment/cryptopay/handler-express.js";
|
|
3
|
-
import { configureExportToken } from "../worker/export-token.js";
|
|
4
|
-
const { CRYPTOPAY_WEBHOOK_PATH = '/payment/cryptopay' } = process.env;
|
|
5
|
-
export default (app, unchainedAPI) => {
|
|
6
|
-
app.use(CRYPTOPAY_WEBHOOK_PATH, express.json(), handler);
|
|
7
|
-
configureExportToken(unchainedAPI);
|
|
8
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import handler from "../payment/cryptopay/handler-fastify.js";
|
|
2
|
-
import { configureExportToken } from "../worker/export-token.js";
|
|
3
|
-
const { CRYPTOPAY_WEBHOOK_PATH = '/payment/cryptopay' } = process.env;
|
|
4
|
-
export default (fastify, unchainedAPI) => {
|
|
5
|
-
fastify.route({
|
|
6
|
-
url: CRYPTOPAY_WEBHOOK_PATH,
|
|
7
|
-
method: 'POST',
|
|
8
|
-
handler,
|
|
9
|
-
});
|
|
10
|
-
configureExportToken(unchainedAPI);
|
|
11
|
-
};
|