@unchainedshop/plugins 4.0.0-rc.15 → 4.0.0-rc.16
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/files/gridfs/handler-express.d.ts.map +1 -1
- package/lib/files/gridfs/handler-express.js +11 -22
- 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 +34 -9
- package/lib/files/gridfs/handler-fastify.js.map +1 -1
- package/lib/files/minio/handler-express.d.ts.map +1 -1
- package/lib/files/minio/handler-express.js +3 -6
- 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/payment/apple-iap/handler-express.d.ts.map +1 -1
- package/lib/payment/apple-iap/handler-express.js +3 -6
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +2 -2
- package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
- package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-express.js +3 -6
- package/lib/payment/cryptopay/handler-express.js.map +1 -1
- package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/handler-express.js +5 -10
- package/lib/payment/datatrans-v2/handler-express.js.map +1 -1
- package/lib/payment/datatrans-v2/handler-fastify.js +4 -4
- package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -1
- package/lib/payment/payrexx/handler-express.d.ts.map +1 -1
- package/lib/payment/payrexx/handler-express.js +12 -14
- 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 +20 -14
- package/lib/payment/payrexx/handler-fastify.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.js +3 -6
- package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.js +2 -2
- package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
- package/lib/payment/saferpay/handler-express.d.ts.map +1 -1
- package/lib/payment/saferpay/handler-express.js +7 -7
- 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 +8 -4
- package/lib/payment/saferpay/handler-fastify.js.map +1 -1
- package/lib/payment/stripe/handler-express.d.ts.map +1 -1
- package/lib/payment/stripe/handler-express.js +16 -16
- 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 +24 -11
- package/lib/payment/stripe/handler-fastify.js.map +1 -1
- package/lib/worker/bulk-import.d.ts.map +1 -1
- package/lib/worker/bulk-import.js +7 -30
- package/lib/worker/bulk-import.js.map +1 -1
- package/package.json +2 -4
- package/src/files/gridfs/handler-express.ts +11 -22
- package/src/files/gridfs/handler-fastify.ts +35 -10
- package/src/files/minio/handler-express.ts +3 -6
- package/src/files/minio/handler-fastify.ts +1 -1
- package/src/payment/apple-iap/handler-express.ts +3 -6
- package/src/payment/apple-iap/handler-fastify.ts +2 -2
- package/src/payment/cryptopay/handler-express.ts +3 -6
- package/src/payment/datatrans-v2/handler-express.ts +5 -10
- package/src/payment/datatrans-v2/handler-fastify.ts +4 -4
- package/src/payment/payrexx/handler-express.ts +21 -31
- package/src/payment/payrexx/handler-fastify.ts +28 -29
- package/src/payment/postfinance-checkout/handler-express.ts +3 -6
- package/src/payment/postfinance-checkout/handler-fastify.ts +2 -2
- package/src/payment/saferpay/handler-express.ts +10 -12
- package/src/payment/saferpay/handler-fastify.ts +10 -8
- package/src/payment/stripe/handler-express.ts +24 -32
- package/src/payment/stripe/handler-fastify.ts +31 -26
- package/src/worker/bulk-import.ts +9 -49
|
@@ -34,8 +34,7 @@ const gridfsHandler = async (
|
|
|
34
34
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
35
35
|
|
|
36
36
|
if (req.method === 'OPTIONS') {
|
|
37
|
-
res.
|
|
38
|
-
res.end();
|
|
37
|
+
res.status(200).end();
|
|
39
38
|
return;
|
|
40
39
|
}
|
|
41
40
|
|
|
@@ -46,8 +45,7 @@ const gridfsHandler = async (
|
|
|
46
45
|
if ((await sign(directoryName, fileId, expiryDate.getTime())) === signature) {
|
|
47
46
|
const file = await modules.files.findFile({ fileId });
|
|
48
47
|
if (file.expires === null) {
|
|
49
|
-
res.
|
|
50
|
-
res.end('File already linked');
|
|
48
|
+
res.status(400).send('File already linked');
|
|
51
49
|
return;
|
|
52
50
|
}
|
|
53
51
|
// If the type is octet-stream, prefer mimetype lookup from the filename
|
|
@@ -77,12 +75,10 @@ const gridfsHandler = async (
|
|
|
77
75
|
const { length } = writeStream;
|
|
78
76
|
await services.files.linkFile({ fileId, size: length, type });
|
|
79
77
|
|
|
80
|
-
res.
|
|
81
|
-
res.end();
|
|
78
|
+
res.status(200).end();
|
|
82
79
|
return;
|
|
83
80
|
}
|
|
84
|
-
res.
|
|
85
|
-
res.end();
|
|
81
|
+
res.status(403).end();
|
|
86
82
|
return;
|
|
87
83
|
}
|
|
88
84
|
|
|
@@ -94,8 +90,7 @@ const gridfsHandler = async (
|
|
|
94
90
|
if (fileDocument?.meta?.isPrivate) {
|
|
95
91
|
const expiry = parseInt(expiryTimestamp as string, 10);
|
|
96
92
|
if (expiry <= Date.now()) {
|
|
97
|
-
res.
|
|
98
|
-
res.end('Access restricted: Expired.');
|
|
93
|
+
res.status(403).send('Access restricted: Expired.');
|
|
99
94
|
return;
|
|
100
95
|
}
|
|
101
96
|
|
|
@@ -103,13 +98,11 @@ const gridfsHandler = async (
|
|
|
103
98
|
const signedUrl = await fileUploadAdapter.createDownloadURL(fileDocument, expiry);
|
|
104
99
|
|
|
105
100
|
if (new URL(signedUrl, 'file://').searchParams.get('s') !== signature) {
|
|
106
|
-
res.
|
|
107
|
-
res.end('Access restricted: Invalid signature.');
|
|
101
|
+
res.status(403).send('Access restricted: Invalid signature.');
|
|
108
102
|
return;
|
|
109
103
|
}
|
|
110
104
|
} else if (!fileDocument) {
|
|
111
|
-
res.
|
|
112
|
-
res.end();
|
|
105
|
+
res.status(404).end();
|
|
113
106
|
return;
|
|
114
107
|
}
|
|
115
108
|
if (file?.metadata?.['content-type']) {
|
|
@@ -122,21 +115,17 @@ const gridfsHandler = async (
|
|
|
122
115
|
const readStream = await modules.gridfsFileUploads.createReadStream(directoryName, fileId);
|
|
123
116
|
readStream.pipe(res, { end: false });
|
|
124
117
|
await finished(readStream);
|
|
125
|
-
res.
|
|
126
|
-
res.end();
|
|
118
|
+
res.status(200).end();
|
|
127
119
|
return;
|
|
128
120
|
}
|
|
129
|
-
res.
|
|
130
|
-
res.end();
|
|
121
|
+
res.status(404).end();
|
|
131
122
|
} catch (e) {
|
|
132
123
|
if (e.code === 'ENOENT') {
|
|
133
124
|
logger.warn(e);
|
|
134
|
-
res.
|
|
135
|
-
res.end(e.message);
|
|
125
|
+
res.status(404).send();
|
|
136
126
|
} else {
|
|
137
127
|
logger.warn(e);
|
|
138
|
-
res.
|
|
139
|
-
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
|
|
128
|
+
res.status(503).send({ name: e.name, code: e.code, message: e.message });
|
|
140
129
|
}
|
|
141
130
|
}
|
|
142
131
|
};
|
|
@@ -41,7 +41,12 @@ const gridfsHandler: RouteHandlerMethod = async (
|
|
|
41
41
|
const file = await modules.files.findFile({ fileId });
|
|
42
42
|
if (file.expires === null) {
|
|
43
43
|
reply.status(400);
|
|
44
|
-
|
|
44
|
+
logger.error('File already linked', { fileId });
|
|
45
|
+
return reply.send({
|
|
46
|
+
success: false,
|
|
47
|
+
message: 'File already linked',
|
|
48
|
+
name: 'FILE_ALREADY_LINKED',
|
|
49
|
+
});
|
|
45
50
|
}
|
|
46
51
|
// If the type is octet-stream, prefer mimetype lookup from the filename
|
|
47
52
|
// Else prefer the content-type header
|
|
@@ -72,11 +77,20 @@ const gridfsHandler: RouteHandlerMethod = async (
|
|
|
72
77
|
await services.files.linkFile({ fileId, size: length, type });
|
|
73
78
|
|
|
74
79
|
reply.status(200);
|
|
75
|
-
return reply.send(
|
|
80
|
+
return reply.send({
|
|
81
|
+
success: true,
|
|
82
|
+
fileId,
|
|
83
|
+
size: length,
|
|
84
|
+
type,
|
|
85
|
+
});
|
|
76
86
|
}
|
|
77
|
-
|
|
87
|
+
logger.error('Invalid signature', { fileId, expiryDate });
|
|
78
88
|
reply.status(403);
|
|
79
|
-
return reply.send(
|
|
89
|
+
return reply.send({
|
|
90
|
+
success: false,
|
|
91
|
+
message: 'Access restricted: Invalid signature.',
|
|
92
|
+
name: 'INVALID_SIGNATURE',
|
|
93
|
+
});
|
|
80
94
|
}
|
|
81
95
|
|
|
82
96
|
if (req.method === 'GET') {
|
|
@@ -87,8 +101,13 @@ const gridfsHandler: RouteHandlerMethod = async (
|
|
|
87
101
|
if (fileDocument?.meta?.isPrivate) {
|
|
88
102
|
const expiry = parseInt(expiryTimestamp as string, 10);
|
|
89
103
|
if (expiry <= Date.now()) {
|
|
104
|
+
logger.error('URL Expired', { fileId, expiry });
|
|
90
105
|
reply.status(403);
|
|
91
|
-
return reply.send(
|
|
106
|
+
return reply.send({
|
|
107
|
+
success: false,
|
|
108
|
+
message: 'Access restricted: URL expired.',
|
|
109
|
+
name: 'URL_EXPIRED',
|
|
110
|
+
});
|
|
92
111
|
}
|
|
93
112
|
|
|
94
113
|
const fileUploadAdapter = getFileAdapter();
|
|
@@ -96,9 +115,15 @@ const gridfsHandler: RouteHandlerMethod = async (
|
|
|
96
115
|
|
|
97
116
|
if (new URL(signedUrl, 'file://').searchParams.get('s') !== signature) {
|
|
98
117
|
reply.status(403);
|
|
99
|
-
|
|
118
|
+
logger.error('Invalid signature', { fileId, expiry });
|
|
119
|
+
return reply.send({
|
|
120
|
+
success: false,
|
|
121
|
+
message: 'Access restricted: Invalid signature.',
|
|
122
|
+
name: 'INVALID_SIGNATURE',
|
|
123
|
+
});
|
|
100
124
|
}
|
|
101
125
|
} else if (!fileDocument) {
|
|
126
|
+
logger.error('File not found', { fileId });
|
|
102
127
|
reply.status(404);
|
|
103
128
|
return reply.send();
|
|
104
129
|
}
|
|
@@ -119,14 +144,14 @@ const gridfsHandler: RouteHandlerMethod = async (
|
|
|
119
144
|
reply.status(404);
|
|
120
145
|
return reply.send();
|
|
121
146
|
} catch (e) {
|
|
147
|
+
logger.error(e);
|
|
148
|
+
|
|
122
149
|
if (e.code === 'ENOENT') {
|
|
123
|
-
logger.warn(e);
|
|
124
150
|
reply.status(404);
|
|
125
|
-
return reply.send(
|
|
151
|
+
return reply.send();
|
|
126
152
|
} else {
|
|
127
|
-
logger.warn(e);
|
|
128
153
|
reply.status(504);
|
|
129
|
-
return reply.send({ name: e.name, code: e.code, message: e.message });
|
|
154
|
+
return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
|
|
130
155
|
}
|
|
131
156
|
}
|
|
132
157
|
};
|
|
@@ -21,17 +21,14 @@ const minioHandler = async (req, res) => {
|
|
|
21
21
|
const [fileId] = object.key.split('.');
|
|
22
22
|
const { services } = req.unchainedContext;
|
|
23
23
|
await services.files.linkFile({ fileId, type, size });
|
|
24
|
-
res.
|
|
25
|
-
res.end();
|
|
24
|
+
res.status(200).end();
|
|
26
25
|
return;
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
|
-
res.
|
|
30
|
-
res.end();
|
|
28
|
+
res.status(404).end();
|
|
31
29
|
} catch (e) {
|
|
32
30
|
logger.error(e);
|
|
33
|
-
res.
|
|
34
|
-
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
|
|
31
|
+
res.status(503).send({ name: e.name, code: e.code, message: e.message });
|
|
35
32
|
}
|
|
36
33
|
};
|
|
37
34
|
|
|
@@ -37,7 +37,7 @@ const minioHandler: RouteHandlerMethod = async (
|
|
|
37
37
|
} catch (e) {
|
|
38
38
|
logger.error(e);
|
|
39
39
|
res.status(503);
|
|
40
|
-
return res.send(
|
|
40
|
+
return res.send({ name: e.name, code: e.code, message: e.message });
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
|
|
@@ -117,18 +117,15 @@ export const appleIAPHandler = async (req, res) => {
|
|
|
117
117
|
logger.info(`Apple IAP Webhook: Updated enrollment from Apple`);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
res.
|
|
121
|
-
res.end();
|
|
120
|
+
res.status(200).end();
|
|
122
121
|
return;
|
|
123
122
|
} catch (e) {
|
|
124
123
|
logger.warn(`Apple IAP Webhook: ${e.message}`, e);
|
|
125
|
-
res.
|
|
126
|
-
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
|
|
124
|
+
res.status(503).send({ name: e.name, code: e.code, message: e.message });
|
|
127
125
|
return;
|
|
128
126
|
}
|
|
129
127
|
}
|
|
130
|
-
res.
|
|
131
|
-
res.end();
|
|
128
|
+
res.status(404).end();
|
|
132
129
|
};
|
|
133
130
|
|
|
134
131
|
export default appleIAPHandler;
|
|
@@ -128,9 +128,9 @@ export const appleIAPHandler: RouteHandlerMethod = async (
|
|
|
128
128
|
reply.status(200);
|
|
129
129
|
return reply.send();
|
|
130
130
|
} catch (e) {
|
|
131
|
-
logger.
|
|
131
|
+
logger.error(e);
|
|
132
132
|
reply.status(503);
|
|
133
|
-
return reply.send({ name: e.name, code: e.code, message: e.message });
|
|
133
|
+
return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
|
|
@@ -7,18 +7,15 @@ const cryptopayHandler = async (req, res) => {
|
|
|
7
7
|
if (req.method === 'POST') {
|
|
8
8
|
try {
|
|
9
9
|
await handleWebhook(req.body, req.unchainedContext);
|
|
10
|
-
res.
|
|
11
|
-
res.end(JSON.stringify({ success: true }));
|
|
10
|
+
res.status(200).send({ success: true });
|
|
12
11
|
return;
|
|
13
12
|
} catch (e) {
|
|
14
13
|
logger.error(e);
|
|
15
|
-
res.
|
|
16
|
-
res.end(JSON.stringify({ success: false, error: e.message }));
|
|
14
|
+
res.status(500).send({ success: false, error: e.message });
|
|
17
15
|
return;
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
|
-
res.
|
|
21
|
-
res.end(JSON.stringify({ success: false }));
|
|
18
|
+
res.status(404).send();
|
|
22
19
|
};
|
|
23
20
|
|
|
24
21
|
export default cryptopayHandler;
|
|
@@ -27,8 +27,7 @@ export const datatransHandler = async (req, res) => {
|
|
|
27
27
|
|
|
28
28
|
if (hash !== comparableSignature) {
|
|
29
29
|
logger.error(`hash mismatch: ${signature} / ${comparableSignature}`, req.body);
|
|
30
|
-
res.
|
|
31
|
-
res.end('Hash mismatch');
|
|
30
|
+
res.status(403).send('Hash mismatch');
|
|
32
31
|
return;
|
|
33
32
|
}
|
|
34
33
|
|
|
@@ -52,8 +51,7 @@ export const datatransHandler = async (req, res) => {
|
|
|
52
51
|
logger.info(`registered payment credentials for ${userId}`, {
|
|
53
52
|
userId,
|
|
54
53
|
});
|
|
55
|
-
res.
|
|
56
|
-
res.end(JSON.stringify(paymentCredentials));
|
|
54
|
+
res.status(200).send(paymentCredentials);
|
|
57
55
|
return;
|
|
58
56
|
}
|
|
59
57
|
if (transaction.type === 'payment') {
|
|
@@ -66,21 +64,18 @@ export const datatransHandler = async (req, res) => {
|
|
|
66
64
|
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
67
65
|
paymentContext: { userId, transactionId: transaction.transactionId },
|
|
68
66
|
});
|
|
69
|
-
res.writeHead(200);
|
|
70
67
|
logger.info(`confirmed checkout for order ${order.orderNumber}`, {
|
|
71
68
|
orderId: order._id,
|
|
72
69
|
});
|
|
73
|
-
res.
|
|
70
|
+
res.status(200).send(order);
|
|
74
71
|
return;
|
|
75
72
|
}
|
|
76
73
|
} catch (e) {
|
|
77
74
|
logger.error(`rejected to checkout with message`, e);
|
|
78
|
-
res.
|
|
79
|
-
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
|
|
75
|
+
res.status(500).send({ name: e.name, code: e.code, message: e.message });
|
|
80
76
|
return;
|
|
81
77
|
}
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
|
-
res.
|
|
85
|
-
res.end();
|
|
80
|
+
res.status(404).end();
|
|
86
81
|
};
|
|
@@ -32,9 +32,9 @@ export const datatransHandler: RouteHandlerMethod = async (
|
|
|
32
32
|
})(timestamp, req.body as string);
|
|
33
33
|
|
|
34
34
|
if (hash !== comparableSignature) {
|
|
35
|
-
logger.error(`hash mismatch: ${signature} / ${comparableSignature}
|
|
35
|
+
logger.error(`hash mismatch: ${signature} / ${comparableSignature}`);
|
|
36
36
|
reply.status(403);
|
|
37
|
-
return reply.send('
|
|
37
|
+
return reply.send({ success: false, message: 'Invalid Signature', name: 'HASH_MISMATCH' });
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const transaction: StatusResponseSuccess = JSON.parse(req.body as string) as StatusResponseSuccess;
|
|
@@ -77,9 +77,9 @@ export const datatransHandler: RouteHandlerMethod = async (
|
|
|
77
77
|
return reply.send(order);
|
|
78
78
|
}
|
|
79
79
|
} catch (e) {
|
|
80
|
-
logger.error(
|
|
80
|
+
logger.error(e);
|
|
81
81
|
reply.status(500);
|
|
82
|
-
return reply.send({ name: e.name, code: e.code, message: e.message });
|
|
82
|
+
return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -13,26 +13,20 @@ export const payrexxHandler = async (request, response) => {
|
|
|
13
13
|
logger.info(`unhandled event type`, {
|
|
14
14
|
type: Object.keys(request.body).join(','),
|
|
15
15
|
});
|
|
16
|
-
response.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
|
|
21
|
-
}),
|
|
22
|
-
);
|
|
16
|
+
response.status(200).send({
|
|
17
|
+
ignored: true,
|
|
18
|
+
message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
|
|
19
|
+
});
|
|
23
20
|
return;
|
|
24
21
|
}
|
|
25
22
|
if (transaction.referenceId === '__IGNORE_WEBHOOK__' || transaction.status === 'waiting') {
|
|
26
23
|
// Ignore confirmed transactions, because those hooks are generated through calling the confirm()
|
|
27
24
|
// method in the payment adapter and could lead to double bookings.
|
|
28
25
|
logger.info(`unhandled transaction state: ${transaction.status}`);
|
|
29
|
-
response.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
message: `Unhandled transaction state: ${transaction.status}`,
|
|
34
|
-
}),
|
|
35
|
-
);
|
|
26
|
+
response.status(200).send({
|
|
27
|
+
ignored: true,
|
|
28
|
+
message: `Unhandled transaction state: ${transaction.status}`,
|
|
29
|
+
});
|
|
36
30
|
return;
|
|
37
31
|
}
|
|
38
32
|
|
|
@@ -53,14 +47,11 @@ export const payrexxHandler = async (request, response) => {
|
|
|
53
47
|
paymentProviderId,
|
|
54
48
|
userId,
|
|
55
49
|
});
|
|
56
|
-
response.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
userId,
|
|
62
|
-
}),
|
|
63
|
-
);
|
|
50
|
+
response.status(200).send({
|
|
51
|
+
message: 'registration successful',
|
|
52
|
+
paymentProviderId,
|
|
53
|
+
userId,
|
|
54
|
+
});
|
|
64
55
|
} else {
|
|
65
56
|
const { referenceId: orderPaymentId, invoice } = transaction;
|
|
66
57
|
logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
|
|
@@ -83,19 +74,18 @@ export const payrexxHandler = async (request, response) => {
|
|
|
83
74
|
orderPaymentId,
|
|
84
75
|
orderId: order._id,
|
|
85
76
|
});
|
|
86
|
-
response.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
orderId: order._id,
|
|
91
|
-
}),
|
|
92
|
-
);
|
|
77
|
+
response.status(200).send({
|
|
78
|
+
message: 'checkout successful',
|
|
79
|
+
orderId: order._id,
|
|
80
|
+
});
|
|
93
81
|
}
|
|
94
82
|
} catch (error) {
|
|
95
83
|
logger.error(error, {
|
|
96
84
|
transactionId: transaction.id,
|
|
97
85
|
});
|
|
98
|
-
response.
|
|
99
|
-
|
|
86
|
+
response.status(500).send({
|
|
87
|
+
message: error.message,
|
|
88
|
+
name: error.name,
|
|
89
|
+
});
|
|
100
90
|
}
|
|
101
91
|
};
|
|
@@ -20,24 +20,22 @@ export const payrexxHandler: RouteHandlerMethod = async (
|
|
|
20
20
|
type: Object.keys(request.body).join(','),
|
|
21
21
|
});
|
|
22
22
|
reply.status(200);
|
|
23
|
-
return reply.send(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
23
|
+
return reply.send({
|
|
24
|
+
success: false,
|
|
25
|
+
ignored: true,
|
|
26
|
+
message: `Unhandled event type: ${Object.keys(request.body).join(',')}. Supported type: transaction`,
|
|
27
|
+
});
|
|
29
28
|
}
|
|
30
29
|
if (transaction.referenceId === '__IGNORE_WEBHOOK__' || transaction.status === 'waiting') {
|
|
31
30
|
// Ignore confirmed transactions, because those hooks are generated through calling the confirm()
|
|
32
31
|
// method in the payment adapter and could lead to double bookings.
|
|
33
32
|
logger.info(`unhandled transaction state: ${transaction.status}`);
|
|
34
33
|
reply.status(200);
|
|
35
|
-
return reply.send(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
);
|
|
34
|
+
return reply.send({
|
|
35
|
+
success: false,
|
|
36
|
+
ignored: true,
|
|
37
|
+
message: `Unhandled transaction state: ${transaction.status}`,
|
|
38
|
+
});
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
logger.info(`Processing event`, {
|
|
@@ -58,19 +56,14 @@ export const payrexxHandler: RouteHandlerMethod = async (
|
|
|
58
56
|
userId,
|
|
59
57
|
});
|
|
60
58
|
reply.status(200);
|
|
61
|
-
return reply.send(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}),
|
|
67
|
-
);
|
|
59
|
+
return reply.send({
|
|
60
|
+
success: true,
|
|
61
|
+
paymentProviderId,
|
|
62
|
+
userId,
|
|
63
|
+
});
|
|
68
64
|
} else {
|
|
69
65
|
const { referenceId: orderPaymentId, invoice } = transaction;
|
|
70
66
|
logger.info(`checkout with orderPaymentId: ${orderPaymentId}`);
|
|
71
|
-
await modules.orders.payments.logEvent(orderPaymentId, {
|
|
72
|
-
transactionId: transaction.id,
|
|
73
|
-
});
|
|
74
67
|
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
75
68
|
orderPaymentId,
|
|
76
69
|
});
|
|
@@ -78,6 +71,10 @@ export const payrexxHandler: RouteHandlerMethod = async (
|
|
|
78
71
|
throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
79
72
|
}
|
|
80
73
|
|
|
74
|
+
await modules.orders.payments.logEvent(orderPaymentId, {
|
|
75
|
+
transactionId: transaction.id,
|
|
76
|
+
});
|
|
77
|
+
|
|
81
78
|
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
82
79
|
paymentContext: {
|
|
83
80
|
gatewayId: invoice.paymentRequestId,
|
|
@@ -88,18 +85,20 @@ export const payrexxHandler: RouteHandlerMethod = async (
|
|
|
88
85
|
orderId: order._id,
|
|
89
86
|
});
|
|
90
87
|
reply.status(200);
|
|
91
|
-
return reply.send(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}),
|
|
96
|
-
);
|
|
88
|
+
return reply.send({
|
|
89
|
+
success: true,
|
|
90
|
+
orderId: order._id,
|
|
91
|
+
});
|
|
97
92
|
}
|
|
98
93
|
} catch (error) {
|
|
99
94
|
logger.error(error, {
|
|
100
95
|
transactionId: transaction.id,
|
|
101
96
|
});
|
|
102
97
|
reply.status(500);
|
|
103
|
-
return reply.send(
|
|
98
|
+
return reply.send({
|
|
99
|
+
success: false,
|
|
100
|
+
message: error.message,
|
|
101
|
+
name: error.name,
|
|
102
|
+
});
|
|
104
103
|
}
|
|
105
104
|
};
|
|
@@ -29,16 +29,13 @@ export const postfinanceCheckoutHandler = async (req, res) => {
|
|
|
29
29
|
logger.info(
|
|
30
30
|
`Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
|
|
31
31
|
);
|
|
32
|
-
res.
|
|
33
|
-
res.end(`Order marked as paid: ${order.orderNumber}`);
|
|
32
|
+
res.status(200).send(`Order marked as paid: ${order.orderNumber}`);
|
|
34
33
|
} catch (e) {
|
|
35
34
|
logger.error(e);
|
|
36
|
-
res.
|
|
37
|
-
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
|
|
35
|
+
res.status(500).send({ name: e.name, code: e.code, message: e.message });
|
|
38
36
|
}
|
|
39
37
|
} else {
|
|
40
38
|
logger.error(`Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
|
|
41
|
-
res.
|
|
42
|
-
res.end();
|
|
39
|
+
res.status(404).end();
|
|
43
40
|
}
|
|
44
41
|
};
|
|
@@ -36,11 +36,11 @@ export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
|
|
|
36
36
|
`Transaction ${transaction.id} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
|
|
37
37
|
);
|
|
38
38
|
reply.status(200);
|
|
39
|
-
return reply.send(
|
|
39
|
+
return reply.send({ success: true, orderNumber: order.orderNumber });
|
|
40
40
|
} catch (e) {
|
|
41
41
|
logger.error(e);
|
|
42
42
|
reply.status(500);
|
|
43
|
-
return reply.send({ name: e.name, code: e.code, message: e.message });
|
|
43
|
+
return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
|
|
44
44
|
}
|
|
45
45
|
} else {
|
|
46
46
|
logger.error(`Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
|
|
@@ -22,8 +22,7 @@ export const saferpayHandler = async (request, response) => {
|
|
|
22
22
|
|
|
23
23
|
if ((request.method !== 'GET' && request.method !== 'HEAD') || !isValidRequest) {
|
|
24
24
|
logger.warn(`unhandled http method ${request.method} or orderPaymentId missing in query`);
|
|
25
|
-
response.
|
|
26
|
-
response.end();
|
|
25
|
+
response.status(404).end();
|
|
27
26
|
return;
|
|
28
27
|
}
|
|
29
28
|
|
|
@@ -51,20 +50,19 @@ export const saferpayHandler = async (request, response) => {
|
|
|
51
50
|
orderPaymentId,
|
|
52
51
|
orderId: order._id,
|
|
53
52
|
});
|
|
54
|
-
response.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
orderId: order._id,
|
|
60
|
-
}),
|
|
61
|
-
);
|
|
53
|
+
response.status(200).send({
|
|
54
|
+
message: 'checkout successful',
|
|
55
|
+
orderPaymentId,
|
|
56
|
+
orderId: order._id,
|
|
57
|
+
});
|
|
62
58
|
} catch (error) {
|
|
63
59
|
logger.error(error, {
|
|
64
60
|
orderPaymentId,
|
|
65
61
|
transactionId,
|
|
66
62
|
});
|
|
67
|
-
response.
|
|
68
|
-
|
|
63
|
+
response.status(500).send({
|
|
64
|
+
message: error.message,
|
|
65
|
+
name: error.name,
|
|
66
|
+
});
|
|
69
67
|
}
|
|
70
68
|
};
|
|
@@ -57,19 +57,21 @@ export const saferpayHandler: RouteHandlerMethod = async (
|
|
|
57
57
|
orderId: order._id,
|
|
58
58
|
});
|
|
59
59
|
reply.status(200);
|
|
60
|
-
return reply.send(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}),
|
|
66
|
-
);
|
|
60
|
+
return reply.send({
|
|
61
|
+
success: true,
|
|
62
|
+
orderPaymentId,
|
|
63
|
+
orderId: order._id,
|
|
64
|
+
});
|
|
67
65
|
} catch (error) {
|
|
68
66
|
logger.error(error, {
|
|
69
67
|
orderPaymentId,
|
|
70
68
|
transactionId,
|
|
71
69
|
});
|
|
72
70
|
reply.status(500);
|
|
73
|
-
return reply.send(
|
|
71
|
+
return reply.send({
|
|
72
|
+
success: false,
|
|
73
|
+
message: error.message,
|
|
74
|
+
name: error.name,
|
|
75
|
+
});
|
|
74
76
|
}
|
|
75
77
|
};
|