@unchainedshop/plugins 2.8.8 → 2.8.11
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/payment/datatrans-v2/api/makeFetcher.d.ts +1 -1
- package/lib/payment/datatrans-v2/middleware.js +1 -1
- package/lib/payment/datatrans-v2/middleware.js.map +1 -1
- package/lib/payment/payrexx/api/index.d.ts +0 -2
- package/lib/payment/payrexx/api/index.js +35 -71
- package/lib/payment/payrexx/api/index.js.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts +3 -0
- package/lib/payment/payrexx/api/makeFetcher.js +72 -0
- package/lib/payment/payrexx/api/makeFetcher.js.map +1 -0
- package/lib/payment/payrexx/index.js +72 -36
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/payrexx/middleware.js +46 -29
- package/lib/payment/payrexx/middleware.js.map +1 -1
- package/lib/payment/payrexx/payrexx.d.ts +16 -1
- package/lib/payment/payrexx/payrexx.js +29 -6
- package/lib/payment/payrexx/payrexx.js.map +1 -1
- package/lib/payment/postfinance-checkout/api.d.ts +0 -2
- package/lib/payment/postfinance-checkout/utils.d.ts +0 -2
- package/package.json +24 -24
- package/src/payment/datatrans-v2/middleware.ts +1 -1
- package/src/payment/payrexx/api/index.ts +39 -87
- package/src/payment/payrexx/api/makeFetcher.ts +87 -0
- package/src/payment/payrexx/index.ts +81 -37
- package/src/payment/payrexx/middleware.ts +57 -34
- package/src/payment/payrexx/payrexx.ts +34 -7
|
@@ -22,17 +22,15 @@ export const payrexxHandler = async (request, response) => {
|
|
|
22
22
|
);
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
if (transaction.status === '
|
|
25
|
+
if (transaction.referenceId === '__IGNORE_WEBHOOK__' || transaction.status === 'waiting') {
|
|
26
26
|
// Ignore confirmed transactions, because those hooks are generated through calling the confirm()
|
|
27
27
|
// method in the payment adapter and could lead to double bookings.
|
|
28
|
-
logger.verbose(`unhandled
|
|
29
|
-
type: Object.keys(request.body).join(','),
|
|
30
|
-
});
|
|
28
|
+
logger.verbose(`unhandled transaction state: ${transaction.status}`);
|
|
31
29
|
response.writeHead(200);
|
|
32
30
|
response.end(
|
|
33
31
|
JSON.stringify({
|
|
34
32
|
ignored: true,
|
|
35
|
-
message: `Unhandled
|
|
33
|
+
message: `Unhandled transaction state: ${transaction.status}`,
|
|
36
34
|
}),
|
|
37
35
|
);
|
|
38
36
|
return;
|
|
@@ -42,37 +40,62 @@ export const payrexxHandler = async (request, response) => {
|
|
|
42
40
|
transactionId: transaction.id,
|
|
43
41
|
});
|
|
44
42
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
43
|
+
if (transaction.preAuthorizationId) {
|
|
44
|
+
// Pre-Authorization Flow, referenceId is a userId
|
|
45
|
+
const { referenceId: paymentProviderId, invoice } = transaction;
|
|
46
|
+
const userId = '';
|
|
47
|
+
logger.verbose(`register credentials for: ${userId}`);
|
|
48
|
+
await modules.payment.registerCredentials(
|
|
49
|
+
paymentProviderId,
|
|
50
|
+
{ userId, transactionContext: { gatewayId: invoice.paymentRequestId } },
|
|
51
|
+
resolvedContext,
|
|
52
|
+
);
|
|
53
|
+
logger.info(`registration successful`, {
|
|
54
|
+
paymentProviderId,
|
|
55
|
+
userId,
|
|
56
|
+
});
|
|
57
|
+
response.writeHead(200);
|
|
58
|
+
response.end(
|
|
59
|
+
JSON.stringify({
|
|
60
|
+
message: 'registration successful',
|
|
61
|
+
paymentProviderId,
|
|
62
|
+
userId,
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
} else {
|
|
66
|
+
const { referenceId: orderPaymentId, invoice } = transaction;
|
|
67
|
+
logger.verbose(`checkout with orderPaymentId: ${orderPaymentId}`);
|
|
68
|
+
await modules.orders.payments.logEvent(orderPaymentId, {
|
|
69
|
+
transactionId: transaction.id,
|
|
70
|
+
});
|
|
71
|
+
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
72
|
+
orderPaymentId,
|
|
73
|
+
});
|
|
74
|
+
if (!orderPayment) {
|
|
75
|
+
throw new Error(`order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const order = await modules.orders.checkout(
|
|
79
|
+
orderPayment.orderId,
|
|
80
|
+
{
|
|
81
|
+
paymentContext: {
|
|
82
|
+
gatewayId: invoice.paymentRequestId,
|
|
83
|
+
},
|
|
61
84
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
orderPaymentId,
|
|
67
|
-
orderId: order._id,
|
|
68
|
-
});
|
|
69
|
-
response.writeHead(200);
|
|
70
|
-
response.end(
|
|
71
|
-
JSON.stringify({
|
|
72
|
-
message: 'checkout successful',
|
|
85
|
+
resolvedContext,
|
|
86
|
+
);
|
|
87
|
+
logger.info(`checkout successful`, {
|
|
88
|
+
orderPaymentId,
|
|
73
89
|
orderId: order._id,
|
|
74
|
-
})
|
|
75
|
-
|
|
90
|
+
});
|
|
91
|
+
response.writeHead(200);
|
|
92
|
+
response.end(
|
|
93
|
+
JSON.stringify({
|
|
94
|
+
message: 'checkout successful',
|
|
95
|
+
orderId: order._id,
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
76
99
|
} catch (error) {
|
|
77
100
|
logger.error(error, {
|
|
78
101
|
transactionId: transaction.id,
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
const getRedirects = () => {
|
|
2
2
|
const {
|
|
3
|
-
EMAIL_WEBSITE_NAME = 'Unchained',
|
|
4
3
|
EMAIL_WEBSITE_URL,
|
|
5
4
|
DATATRANS_SUCCESS_PATH = '/payrexx/success',
|
|
6
5
|
DATATRANS_ERROR_PATH = '/payrexx/error',
|
|
7
6
|
DATATRANS_CANCEL_PATH = '/payrexx/cancel',
|
|
8
7
|
} = process.env;
|
|
9
8
|
|
|
9
|
+
return {
|
|
10
|
+
successRedirectUrl: `${EMAIL_WEBSITE_URL}${DATATRANS_SUCCESS_PATH}`,
|
|
11
|
+
failedRedirectUrl: `${EMAIL_WEBSITE_URL}${DATATRANS_ERROR_PATH}`,
|
|
12
|
+
cancelRedirectUrl: `${EMAIL_WEBSITE_URL}${DATATRANS_CANCEL_PATH}`,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const mapOrderDataToGatewayObject = ({ order, orderPayment, pricing }, options = {}) => {
|
|
10
17
|
const { currency, amount } = pricing.total({ useNetPrice: false });
|
|
11
18
|
|
|
12
19
|
const customerData = {};
|
|
@@ -23,16 +30,36 @@ export const mapOrderDataToGatewayObject = ({ order, orderPayment, pricing }, op
|
|
|
23
30
|
const gatewayObject = {
|
|
24
31
|
amount: Math.round(amount),
|
|
25
32
|
currency: currency.toUpperCase(),
|
|
26
|
-
purpose: encodeURIComponent(`${EMAIL_WEBSITE_NAME} #${order._id}`),
|
|
27
|
-
// preAuthorization: true -> tokenization!
|
|
33
|
+
purpose: encodeURIComponent(`${process.env.EMAIL_WEBSITE_NAME || 'Unchained'} #${order._id}`),
|
|
28
34
|
reservation: true,
|
|
29
35
|
skipResultPage: true,
|
|
30
|
-
|
|
31
|
-
failedRedirectUrl: `${EMAIL_WEBSITE_URL}${DATATRANS_ERROR_PATH}`,
|
|
32
|
-
cancelRedirectUrl: `${EMAIL_WEBSITE_URL}${DATATRANS_CANCEL_PATH}`,
|
|
36
|
+
...getRedirects(),
|
|
33
37
|
referenceId: orderPayment._id,
|
|
34
38
|
...customerData,
|
|
35
39
|
...options,
|
|
36
40
|
};
|
|
37
41
|
return gatewayObject;
|
|
38
42
|
};
|
|
43
|
+
|
|
44
|
+
export const mapUserToGatewayObject = ({ userId, emailAddress, currencyCode }, options = {}) => {
|
|
45
|
+
const customerData = {};
|
|
46
|
+
|
|
47
|
+
if (emailAddress) {
|
|
48
|
+
customerData['fields[email][value]'] = emailAddress;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
customerData['fields[custom_field_1][name][0]'] = 'userId';
|
|
52
|
+
customerData['fields[custom_field_1][value]'] = userId;
|
|
53
|
+
|
|
54
|
+
const gatewayObject = {
|
|
55
|
+
amount: Math.round(0),
|
|
56
|
+
currency: currencyCode,
|
|
57
|
+
purpose: encodeURIComponent(`${process.env.EMAIL_WEBSITE_NAME || 'Unchained'} ${userId}`),
|
|
58
|
+
preAuthorization: true,
|
|
59
|
+
skipResultPage: true,
|
|
60
|
+
...getRedirects(),
|
|
61
|
+
referenceId: userId,
|
|
62
|
+
...options,
|
|
63
|
+
};
|
|
64
|
+
return gatewayObject;
|
|
65
|
+
};
|