@unchainedshop/plugins 2.0.0-beta7 → 2.0.0-beta9
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/delivery/send-message.js +2 -2
- package/lib/delivery/send-message.js.map +1 -1
- package/lib/payment/apple-iap/adapter.js +10 -8
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +1 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +1 -2
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -1
- package/lib/payment/braintree.js +14 -12
- package/lib/payment/braintree.js.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
- package/lib/payment/cryptopay/middleware.js +1 -1
- package/lib/payment/cryptopay/middleware.js.map +1 -1
- package/lib/payment/datatrans-v2/getPaths.d.ts +1 -1
- package/lib/payment/datatrans-v2/index.js +2 -2
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/middleware.js +3 -3
- package/lib/payment/datatrans-v2/middleware.js.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +2 -2
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.js +4 -9
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/types.d.ts +3 -3
- package/lib/payment/stripe.js +6 -6
- package/lib/payment/stripe.js.map +1 -1
- package/lib/payment/worldline-saferpay/index.js +2 -6
- package/lib/payment/worldline-saferpay/index.js.map +1 -1
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js +3 -2
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js.map +1 -1
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.d.ts +1 -1
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.d.ts +2 -2
- package/lib/plugins-index.d.ts +4 -1
- package/lib/plugins-index.js +11 -11
- package/lib/plugins-index.js.map +1 -1
- package/lib/pricing/utils/cache.d.ts +2 -1
- package/lib/warehousing/eth-minter.js +3 -3
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/bulk-import.js +1 -2
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/enrollment-order-generator.js +13 -12
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/message.js +4 -4
- package/lib/worker/message.js.map +1 -1
- package/lib/worker/update-coinbase-rates.js +3 -3
- package/lib/worker/update-coinbase-rates.js.map +1 -1
- package/lib/worker/update-ecb-rates.js +2 -2
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/lib/worker/update-token-ownership.js +3 -3
- package/lib/worker/update-token-ownership.js.map +1 -1
- package/lib/worker/zombie-killer.js +35 -30
- package/lib/worker/zombie-killer.js.map +1 -1
- package/package.json +27 -23
- package/src/delivery/send-message.ts +10 -13
- package/src/payment/apple-iap/adapter.ts +11 -16
- package/src/payment/apple-iap/module/configureAppleTransactionsModule.ts +1 -2
- package/src/payment/braintree.ts +14 -12
- package/src/payment/cryptopay/middleware.ts +1 -1
- package/src/payment/datatrans-v2/index.ts +2 -4
- package/src/payment/datatrans-v2/middleware.ts +6 -6
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +2 -2
- package/src/payment/postfinance-checkout/index.ts +5 -9
- package/src/payment/stripe.ts +6 -6
- package/src/payment/worldline-saferpay/index.ts +2 -6
- package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.ts +3 -2
- package/src/plugins-index.ts +15 -11
- package/src/warehousing/eth-minter.ts +3 -3
- package/src/worker/bulk-import.ts +1 -6
- package/src/worker/enrollment-order-generator.ts +21 -23
- package/src/worker/message.ts +6 -10
- package/src/worker/update-coinbase-rates.ts +3 -3
- package/src/worker/update-ecb-rates.ts +2 -2
- package/src/worker/update-token-ownership.ts +10 -13
- package/src/worker/zombie-killer.ts +58 -32
- package/tests/plugins-index.test.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/plugins",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta9",
|
|
4
4
|
"main": "lib/plugins-index.js",
|
|
5
5
|
"types": "lib/plugins-index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
"clean": "rm -rf lib",
|
|
54
54
|
"build": "npm run clean && tsc",
|
|
55
55
|
"watch": "tsc -w",
|
|
56
|
-
"test": "jest --
|
|
56
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
|
|
57
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
|
|
57
58
|
},
|
|
58
59
|
"repository": {
|
|
59
60
|
"type": "git",
|
|
@@ -70,40 +71,43 @@
|
|
|
70
71
|
"url": "https://github.com/unchainedshop/unchained/issues"
|
|
71
72
|
},
|
|
72
73
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
74
|
+
"optionalDependencies": {
|
|
75
|
+
"express": "^4.18.2"
|
|
76
|
+
},
|
|
73
77
|
"devDependencies": {
|
|
74
|
-
"@types/node": "^18.11.
|
|
75
|
-
"@unchainedshop/api": "^2.0.0-
|
|
78
|
+
"@types/node": "^18.11.12",
|
|
79
|
+
"@unchainedshop/api": "^2.0.0-beta9",
|
|
76
80
|
"@unchainedshop/client-oauth2": "^4.3.3",
|
|
77
|
-
"@unchainedshop/core-delivery": "^2.0.0-
|
|
78
|
-
"@unchainedshop/core-enrollments": "^2.0.0-
|
|
79
|
-
"@unchainedshop/core-filters": "^2.0.0-
|
|
80
|
-
"@unchainedshop/core-messaging": "^2.0.0-
|
|
81
|
-
"@unchainedshop/core-orders": "^2.0.0-
|
|
82
|
-
"@unchainedshop/core-payment": "^2.0.0-
|
|
83
|
-
"@unchainedshop/core-products": "^2.0.0-
|
|
84
|
-
"@unchainedshop/core-quotations": "^2.0.0-
|
|
85
|
-
"@unchainedshop/core-warehousing": "^2.0.0-
|
|
86
|
-
"@unchainedshop/core-worker": "^2.0.0-
|
|
87
|
-
"@unchainedshop/events": "^2.0.0-
|
|
88
|
-
"@unchainedshop/file-upload": "^2.0.0-
|
|
89
|
-
"@unchainedshop/logger": "^2.0.0-
|
|
90
|
-
"@unchainedshop/types": "^2.0.0-
|
|
91
|
-
"@unchainedshop/utils": "^2.0.0-
|
|
81
|
+
"@unchainedshop/core-delivery": "^2.0.0-beta9",
|
|
82
|
+
"@unchainedshop/core-enrollments": "^2.0.0-beta9",
|
|
83
|
+
"@unchainedshop/core-filters": "^2.0.0-beta9",
|
|
84
|
+
"@unchainedshop/core-messaging": "^2.0.0-beta9",
|
|
85
|
+
"@unchainedshop/core-orders": "^2.0.0-beta9",
|
|
86
|
+
"@unchainedshop/core-payment": "^2.0.0-beta9",
|
|
87
|
+
"@unchainedshop/core-products": "^2.0.0-beta9",
|
|
88
|
+
"@unchainedshop/core-quotations": "^2.0.0-beta9",
|
|
89
|
+
"@unchainedshop/core-warehousing": "^2.0.0-beta9",
|
|
90
|
+
"@unchainedshop/core-worker": "^2.0.0-beta9",
|
|
91
|
+
"@unchainedshop/events": "^2.0.0-beta9",
|
|
92
|
+
"@unchainedshop/file-upload": "^2.0.0-beta9",
|
|
93
|
+
"@unchainedshop/logger": "^2.0.0-beta9",
|
|
94
|
+
"@unchainedshop/types": "^2.0.0-beta9",
|
|
95
|
+
"@unchainedshop/utils": "^2.0.0-beta9",
|
|
92
96
|
"bluebird": "^3.7.2",
|
|
93
|
-
"body-parser": "^1.20.0",
|
|
94
97
|
"event-iterator": "^2.0.0",
|
|
98
|
+
"express": "^4.18.2",
|
|
95
99
|
"jest": "^29.3.1",
|
|
96
100
|
"JSONStream": "^1.3.5",
|
|
97
101
|
"minio": "^7.0.32",
|
|
98
|
-
"mongodb": "^4.
|
|
102
|
+
"mongodb": "^4.12.1",
|
|
99
103
|
"node-sheets": "^1.2.0",
|
|
100
104
|
"nodemailer": "^6.8.0",
|
|
101
105
|
"open": "^8.4.0",
|
|
102
|
-
"redis": "^4.5.
|
|
106
|
+
"redis": "^4.5.1",
|
|
103
107
|
"request": "^2.88.2",
|
|
104
108
|
"stripe": "^10.17.0",
|
|
105
109
|
"ts-jest": "^29.0.3",
|
|
106
|
-
"typescript": "^4.
|
|
110
|
+
"typescript": "^4.9.4",
|
|
107
111
|
"xml-js": "^1.6.11",
|
|
108
112
|
"xml2js": "0.4.23"
|
|
109
113
|
}
|
|
@@ -31,20 +31,17 @@ const SendMessage: IDeliveryAdapter = {
|
|
|
31
31
|
},
|
|
32
32
|
|
|
33
33
|
send: async () => {
|
|
34
|
-
const { modules, order
|
|
35
|
-
|
|
36
|
-
return modules.worker.addWork(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
config,
|
|
44
|
-
},
|
|
34
|
+
const { modules, order } = context;
|
|
35
|
+
|
|
36
|
+
return modules.worker.addWork({
|
|
37
|
+
type: 'MESSAGE',
|
|
38
|
+
retries: 0,
|
|
39
|
+
input: {
|
|
40
|
+
template: 'DELIVERY',
|
|
41
|
+
orderId: order._id,
|
|
42
|
+
config,
|
|
45
43
|
},
|
|
46
|
-
|
|
47
|
-
);
|
|
44
|
+
});
|
|
48
45
|
},
|
|
49
46
|
};
|
|
50
47
|
},
|
|
@@ -4,6 +4,7 @@ import { IPaymentAdapter } from '@unchainedshop/types/payments';
|
|
|
4
4
|
import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
|
|
5
5
|
import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment';
|
|
6
6
|
import { createLogger } from '@unchainedshop/logger';
|
|
7
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
7
8
|
import { AppleTransactionsModule } from './module/configureAppleTransactionsModule';
|
|
8
9
|
|
|
9
10
|
const logger = createLogger('unchained:core-payment:iap');
|
|
@@ -43,7 +44,7 @@ const AppleNotificationTypes = {
|
|
|
43
44
|
|
|
44
45
|
const fixPeriods = async (
|
|
45
46
|
{ transactionId, enrollmentId, orderId, transactions },
|
|
46
|
-
|
|
47
|
+
unchainedAPI: UnchainedCore,
|
|
47
48
|
) => {
|
|
48
49
|
const relevantTransactions = transactions.filter(
|
|
49
50
|
// eslint-disable-next-line
|
|
@@ -65,19 +66,11 @@ const fixPeriods = async (
|
|
|
65
66
|
return left.end.getTime() - right.end.getTime();
|
|
66
67
|
});
|
|
67
68
|
|
|
68
|
-
await
|
|
69
|
-
enrollmentId,
|
|
70
|
-
orderId,
|
|
71
|
-
requestContext.userId,
|
|
72
|
-
);
|
|
69
|
+
await unchainedAPI.modules.enrollments.removeEnrollmentPeriodByOrderId(enrollmentId, orderId);
|
|
73
70
|
|
|
74
71
|
return Promise.all(
|
|
75
72
|
adjustedEnrollmentPeriods.map((period) =>
|
|
76
|
-
|
|
77
|
-
enrollmentId,
|
|
78
|
-
period,
|
|
79
|
-
requestContext.userId,
|
|
80
|
-
),
|
|
73
|
+
unchainedAPI.modules.enrollments.addEnrollmentPeriod(enrollmentId, period),
|
|
81
74
|
),
|
|
82
75
|
);
|
|
83
76
|
};
|
|
@@ -86,7 +79,7 @@ export const appleIAPHandler = async (req, res) => {
|
|
|
86
79
|
if (req.method === 'POST') {
|
|
87
80
|
try {
|
|
88
81
|
const resolvedContext = req.unchainedContext as Context;
|
|
89
|
-
const { modules
|
|
82
|
+
const { modules } = resolvedContext;
|
|
90
83
|
const responseBody = req.body || {};
|
|
91
84
|
if (responseBody.password !== APPLE_IAP_SHARED_SECRET) {
|
|
92
85
|
throw new Error('shared secret not valid');
|
|
@@ -154,12 +147,13 @@ export const appleIAPHandler = async (req, res) => {
|
|
|
154
147
|
orderId: originalOrder._id,
|
|
155
148
|
});
|
|
156
149
|
|
|
157
|
-
await
|
|
150
|
+
await modules.payment.registerCredentials(
|
|
158
151
|
enrollment.payment.paymentProviderId,
|
|
159
152
|
{
|
|
160
153
|
transactionContext: {
|
|
161
154
|
receiptData: responseBody?.unified_receipt?.latest_receipt, // eslint-disable-line
|
|
162
155
|
},
|
|
156
|
+
userId: enrollment.userId,
|
|
163
157
|
},
|
|
164
158
|
resolvedContext,
|
|
165
159
|
);
|
|
@@ -183,7 +177,7 @@ export const appleIAPHandler = async (req, res) => {
|
|
|
183
177
|
enrollment.status !== EnrollmentStatus.TERMINATED &&
|
|
184
178
|
responseBody.auto_renew_status === 'false'
|
|
185
179
|
) {
|
|
186
|
-
await modules.enrollments.terminateEnrollment(enrollment,
|
|
180
|
+
await modules.enrollments.terminateEnrollment(enrollment, resolvedContext);
|
|
187
181
|
}
|
|
188
182
|
}
|
|
189
183
|
|
|
@@ -192,7 +186,7 @@ export const appleIAPHandler = async (req, res) => {
|
|
|
192
186
|
enrollment.status !== EnrollmentStatus.TERMINATED &&
|
|
193
187
|
responseBody.auto_renew_status === 'false'
|
|
194
188
|
) {
|
|
195
|
-
await modules.enrollments.terminateEnrollment(enrollment,
|
|
189
|
+
await modules.enrollments.terminateEnrollment(enrollment, resolvedContext);
|
|
196
190
|
}
|
|
197
191
|
}
|
|
198
192
|
logger.info(`Apple IAP Webhook: Updated enrollment from Apple`);
|
|
@@ -225,7 +219,7 @@ const AppleIAP: IPaymentAdapter = {
|
|
|
225
219
|
},
|
|
226
220
|
|
|
227
221
|
actions: (params) => {
|
|
228
|
-
const { modules
|
|
222
|
+
const { modules } = params.context;
|
|
229
223
|
|
|
230
224
|
const adapterActions = {
|
|
231
225
|
...PaymentAdapter.actions(params),
|
|
@@ -355,6 +349,7 @@ const AppleIAP: IPaymentAdapter = {
|
|
|
355
349
|
throw new Error('Apple IAP Plugin: Transaction already processed');
|
|
356
350
|
|
|
357
351
|
// All good
|
|
352
|
+
const userId = order?.userId || params.paymentContext?.userId;
|
|
358
353
|
await appleTransactions.createTransaction(
|
|
359
354
|
{
|
|
360
355
|
_id: transactionIdentifier,
|
|
@@ -19,11 +19,10 @@ export const configureAppleTransactionsModule = async ({
|
|
|
19
19
|
return AppleTransactions.findOne({ _id: transactionIdentifier });
|
|
20
20
|
},
|
|
21
21
|
|
|
22
|
-
createTransaction: async (doc
|
|
22
|
+
createTransaction: async (doc) => {
|
|
23
23
|
await AppleTransactions.insertOne({
|
|
24
24
|
...doc,
|
|
25
25
|
created: new Date(),
|
|
26
|
-
createdBy: userId,
|
|
27
26
|
});
|
|
28
27
|
return doc._id;
|
|
29
28
|
},
|
package/src/payment/braintree.ts
CHANGED
|
@@ -112,7 +112,7 @@ const BraintreeDirect: IPaymentAdapter = {
|
|
|
112
112
|
// @ts-ignore
|
|
113
113
|
const braintree = (await import('braintree')).default; // eslint-disable-line
|
|
114
114
|
const gateway = getGateway(braintree);
|
|
115
|
-
const address = order.billingAddress
|
|
115
|
+
const address = order.billingAddress;
|
|
116
116
|
const pricing = modules.orders.pricingSheet(order);
|
|
117
117
|
const rounded = Math.round(pricing.total({ useNetPrice: false }).amount / 10 || 0) * 10;
|
|
118
118
|
const saleRequest = {
|
|
@@ -120,17 +120,19 @@ const BraintreeDirect: IPaymentAdapter = {
|
|
|
120
120
|
merchantAccountId: order.currency,
|
|
121
121
|
paymentMethodNonce: paypalPaymentMethodNonce,
|
|
122
122
|
orderId: order.orderNumber || order._id,
|
|
123
|
-
shipping:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
123
|
+
shipping: address
|
|
124
|
+
? {
|
|
125
|
+
firstName: address.firstName,
|
|
126
|
+
lastName: address.lastName,
|
|
127
|
+
company: address.company,
|
|
128
|
+
streetAddress: address.addressLine,
|
|
129
|
+
extendedAddress: address.addressLine2,
|
|
130
|
+
locality: address.city,
|
|
131
|
+
region: address.regionCode,
|
|
132
|
+
postalCode: address.postalCode,
|
|
133
|
+
countryCodeAlpha2: address.countryCode,
|
|
134
|
+
}
|
|
135
|
+
: undefined,
|
|
134
136
|
options: {
|
|
135
137
|
submitForSettlement: true,
|
|
136
138
|
},
|
|
@@ -63,7 +63,7 @@ export const cryptopayHandler = async (req, res) => {
|
|
|
63
63
|
expiresAt,
|
|
64
64
|
timestamp: timestampDate,
|
|
65
65
|
};
|
|
66
|
-
|
|
66
|
+
logger.verbose(`update rate ${JSON.stringify(price)}, ${JSON.stringify(rateData)}`);
|
|
67
67
|
await resolvedContext.modules.products.prices.rates.updateRates([rateData]);
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -116,8 +116,8 @@ const Datatrans: IPaymentAdapter = {
|
|
|
116
116
|
|
|
117
117
|
const authorize = async ({ paymentCredentials, ...arbitraryFields }): Promise<string> => {
|
|
118
118
|
const { order, orderPayment } = params.paymentContext;
|
|
119
|
-
const userId = order?.userId || params.context.userId;
|
|
120
119
|
const refno = Buffer.from(orderPayment._id, 'hex').toString('base64');
|
|
120
|
+
const userId = order?.userId || params.paymentContext?.userId;
|
|
121
121
|
const refno2 = userId;
|
|
122
122
|
const { currency, amount } = roundedAmountFromOrder(order, params.context);
|
|
123
123
|
const splits = await getMarketplaceSplits();
|
|
@@ -249,12 +249,10 @@ const Datatrans: IPaymentAdapter = {
|
|
|
249
249
|
async sign(transactionContext: any = {}) {
|
|
250
250
|
const { useSecureFields = false, ...arbitraryFields } = transactionContext || {};
|
|
251
251
|
const { orderPayment, paymentProviderId, order } = params.paymentContext;
|
|
252
|
-
|
|
253
|
-
const userId = order?.userId || params.context?.userId;
|
|
254
|
-
|
|
255
252
|
const refno = Buffer.from(orderPayment ? orderPayment._id : paymentProviderId, 'hex').toString(
|
|
256
253
|
'base64',
|
|
257
254
|
);
|
|
255
|
+
const userId = order?.userId || params.paymentContext?.userId;
|
|
258
256
|
const refno2 = userId;
|
|
259
257
|
const price: { amount?: number; currency?: string } = order
|
|
260
258
|
? roundedAmountFromOrder(order, params.context)
|
|
@@ -14,7 +14,7 @@ const logger = createLogger('unchained:core-payment:datatrans');
|
|
|
14
14
|
|
|
15
15
|
export const datatransHandler = async (req, res) => {
|
|
16
16
|
const resolvedContext = req.unchainedContext as Context;
|
|
17
|
-
const {
|
|
17
|
+
const { modules } = resolvedContext;
|
|
18
18
|
const signature = req.headers['datatrans-signature'];
|
|
19
19
|
if (req.method === 'POST' && signature) {
|
|
20
20
|
const [rawTimestamp, rawHash] = signature.split(',');
|
|
@@ -42,10 +42,10 @@ export const datatransHandler = async (req, res) => {
|
|
|
42
42
|
try {
|
|
43
43
|
if (transaction.type === 'card_check') {
|
|
44
44
|
const paymentProviderId = referenceId;
|
|
45
|
-
const paymentCredentials = await
|
|
45
|
+
const paymentCredentials = await modules.payment.registerCredentials(
|
|
46
46
|
paymentProviderId,
|
|
47
|
-
{ transactionContext: { transactionId: transaction.transactionId } },
|
|
48
|
-
{ ...resolvedContext
|
|
47
|
+
{ userId, transactionContext: { transactionId: transaction.transactionId } },
|
|
48
|
+
{ ...resolvedContext },
|
|
49
49
|
);
|
|
50
50
|
logger.info(`Datatrans Webhook: Unchained registered payment credentials for ${userId}`, {
|
|
51
51
|
userId,
|
|
@@ -63,8 +63,8 @@ export const datatransHandler = async (req, res) => {
|
|
|
63
63
|
|
|
64
64
|
const order = await modules.orders.checkout(
|
|
65
65
|
orderPayment.orderId,
|
|
66
|
-
{ paymentContext: { transactionId: transaction.transactionId } },
|
|
67
|
-
|
|
66
|
+
{ paymentContext: { userId, transactionId: transaction.transactionId } },
|
|
67
|
+
resolvedContext,
|
|
68
68
|
);
|
|
69
69
|
res.writeHead(200);
|
|
70
70
|
logger.info(`Datatrans Webhook: Unchained confirmed checkout for order ${order.orderNumber}`, {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
2
|
import { Order } from '@unchainedshop/types/orders';
|
|
3
3
|
|
|
4
4
|
const roundedAmountFromOrder = (
|
|
5
5
|
order: Order,
|
|
6
|
-
context:
|
|
6
|
+
context: UnchainedCore,
|
|
7
7
|
): { currency: string; amount: number } => {
|
|
8
8
|
const pricing = context.modules.orders.pricingSheet(order);
|
|
9
9
|
const { currency, amount } = pricing.total({ useNetPrice: false });
|
|
@@ -99,16 +99,15 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
99
99
|
},
|
|
100
100
|
|
|
101
101
|
sign: async (transactionContext: any = {}) => {
|
|
102
|
+
const { orderPayment, order } = params.paymentContext;
|
|
103
|
+
|
|
102
104
|
const { integrationMode = IntegrationModes.PaymentPage }: { integrationMode: IntegrationModes } =
|
|
103
105
|
transactionContext;
|
|
104
106
|
const completionMode = adapter.getCompletionMode();
|
|
105
|
-
const { orderPayment } = params.paymentContext;
|
|
106
|
-
const order = await modules.orders.findOrder({
|
|
107
|
-
orderId: orderPayment.orderId,
|
|
108
|
-
});
|
|
109
107
|
const pricing = modules.orders.pricingSheet(order);
|
|
110
108
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
111
109
|
const transaction = new PostFinanceCheckout.model.TransactionCreate();
|
|
110
|
+
const userId = order?.userId || params.paymentContext?.userId;
|
|
112
111
|
transaction.currency = order.currency;
|
|
113
112
|
transaction.metaData = {
|
|
114
113
|
orderPaymentId: orderPayment._id,
|
|
@@ -119,7 +118,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
119
118
|
transaction.failedUrl = `${transactionContext?.failedUrl || PFCHECKOUT_FAILED_URL}?order_id=${
|
|
120
119
|
orderPayment.orderId
|
|
121
120
|
}`;
|
|
122
|
-
transaction.customerId =
|
|
121
|
+
transaction.customerId = userId;
|
|
123
122
|
transaction.tokenizationMode =
|
|
124
123
|
PostFinanceCheckout.model.TokenizationMode.ALLOW_ONE_CLICK_PAYMENT;
|
|
125
124
|
if (completionMode === CompletionModes.Immediate) {
|
|
@@ -208,16 +207,13 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
208
207
|
},
|
|
209
208
|
|
|
210
209
|
cancel: async () => {
|
|
211
|
-
const { orderPayment } = params.paymentContext;
|
|
210
|
+
const { orderPayment, order } = params.paymentContext;
|
|
212
211
|
const { transactionId } = orderPayment;
|
|
213
212
|
if (!transactionId) {
|
|
214
213
|
return false;
|
|
215
214
|
}
|
|
216
215
|
const transaction = await getTransaction(transactionId);
|
|
217
216
|
const refund = transaction.state === PostFinanceCheckout.model.TransactionState.FULFILL;
|
|
218
|
-
const order = await modules.orders.findOrder({
|
|
219
|
-
orderId: orderPayment.orderId,
|
|
220
|
-
});
|
|
221
217
|
const pricing = modules.orders.pricingSheet(order);
|
|
222
218
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
223
219
|
// For immediate settlements, try refunding. For deferred settlements, void the transaction.
|
package/src/payment/stripe.ts
CHANGED
|
@@ -25,7 +25,7 @@ const stripe = createStripeClient(STRIPE_SECRET);
|
|
|
25
25
|
export const stripeHandler = async (request, response) => {
|
|
26
26
|
const sig = request.headers['stripe-signature'];
|
|
27
27
|
const resolvedContext = request.unchainedContext as Context;
|
|
28
|
-
const { modules
|
|
28
|
+
const { modules } = resolvedContext;
|
|
29
29
|
|
|
30
30
|
let event;
|
|
31
31
|
|
|
@@ -42,7 +42,7 @@ export const stripeHandler = async (request, response) => {
|
|
|
42
42
|
const paymentIntent = event.data.object;
|
|
43
43
|
const orderPaymentId = paymentIntent.metadata?.orderPaymentId;
|
|
44
44
|
|
|
45
|
-
await modules.orders.payments.logEvent(orderPaymentId, event
|
|
45
|
+
await modules.orders.payments.logEvent(orderPaymentId, event);
|
|
46
46
|
|
|
47
47
|
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
48
48
|
orderPaymentId,
|
|
@@ -68,12 +68,13 @@ export const stripeHandler = async (request, response) => {
|
|
|
68
68
|
const setupIntent = event.data.object;
|
|
69
69
|
const { paymentProviderId, userId } = setupIntent.metadata;
|
|
70
70
|
|
|
71
|
-
await
|
|
71
|
+
await modules.payment.registerCredentials(
|
|
72
72
|
paymentProviderId,
|
|
73
73
|
{
|
|
74
74
|
transactionContext: {
|
|
75
75
|
setupIntentId: setupIntent.id,
|
|
76
76
|
},
|
|
77
|
+
userId,
|
|
77
78
|
},
|
|
78
79
|
resolvedContext,
|
|
79
80
|
);
|
|
@@ -197,11 +198,9 @@ const Stripe: IPaymentAdapter = {
|
|
|
197
198
|
|
|
198
199
|
sign: async (transactionContext = {}) => {
|
|
199
200
|
// eslint-disable-line
|
|
200
|
-
const { orderPayment, paymentProviderId } = params.paymentContext;
|
|
201
|
-
const { userId } = params.context;
|
|
201
|
+
const { orderPayment, order, paymentProviderId } = params.paymentContext;
|
|
202
202
|
|
|
203
203
|
if (orderPayment) {
|
|
204
|
-
const order = await modules.orders.findOrder({ orderId: orderPayment.orderId });
|
|
205
204
|
const pricing = await modules.orders.pricingSheet(order);
|
|
206
205
|
const paymentIntent = await createOrderPaymentIntent(
|
|
207
206
|
{ order, orderPayment, pricing },
|
|
@@ -210,6 +209,7 @@ const Stripe: IPaymentAdapter = {
|
|
|
210
209
|
return paymentIntent.client_secret;
|
|
211
210
|
}
|
|
212
211
|
|
|
212
|
+
const userId = order?.userId || params.paymentContext?.userId;
|
|
213
213
|
const user = await modules.users.findUserById(userId);
|
|
214
214
|
const email = modules.users.primaryEmail(user)?.address;
|
|
215
215
|
const name = user.profile.displayName || user.username || email;
|
|
@@ -64,10 +64,7 @@ const WordlineSaferpay: IPaymentAdapter = {
|
|
|
64
64
|
},
|
|
65
65
|
|
|
66
66
|
sign: async (transactionContext: any = {}) => {
|
|
67
|
-
const { orderPayment } = params.paymentContext;
|
|
68
|
-
const order = await modules.orders.findOrder({
|
|
69
|
-
orderId: orderPayment.orderId,
|
|
70
|
-
});
|
|
67
|
+
const { orderPayment, order } = params.paymentContext;
|
|
71
68
|
const pricing = modules.orders.pricingSheet(order);
|
|
72
69
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
73
70
|
const paymentPageInitInput: PaymentPageInitializeInput = {
|
|
@@ -95,8 +92,7 @@ const WordlineSaferpay: IPaymentAdapter = {
|
|
|
95
92
|
},
|
|
96
93
|
|
|
97
94
|
charge: async ({ transactionId }: { transactionId: string }) => {
|
|
98
|
-
const { orderPayment } = params.paymentContext;
|
|
99
|
-
const order = await modules.orders.findOrder({ orderId: orderPayment.orderId });
|
|
95
|
+
const { orderPayment, order } = params.paymentContext;
|
|
100
96
|
const pricing = modules.orders.pricingSheet(order);
|
|
101
97
|
const totalAmount = pricing.total({ useNetPrice: false }).amount;
|
|
102
98
|
const paymentPageAssert = await saferpayClient.paymentPageAssert({
|
|
@@ -26,10 +26,11 @@ export class SaferpayConnection {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
public async post(uri: string, data: object): Promise<any> {
|
|
29
|
-
|
|
29
|
+
const res = await fetch(this.buildUrl(uri), {
|
|
30
30
|
method: 'POST',
|
|
31
31
|
body: JSON.stringify(data),
|
|
32
32
|
headers: this.getHeaders(),
|
|
33
|
-
})
|
|
33
|
+
});
|
|
34
|
+
return res.json();
|
|
34
35
|
}
|
|
35
36
|
}
|
package/src/plugins-index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
|
|
2
|
-
import
|
|
1
|
+
import { useMiddlewareWithCurrentContext } from '@unchainedshop/api/express';
|
|
2
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
3
|
+
import express from 'express';
|
|
3
4
|
|
|
4
5
|
// Delivery
|
|
5
6
|
import './delivery/post';
|
|
@@ -95,29 +96,32 @@ export const defaultModules = {
|
|
|
95
96
|
},
|
|
96
97
|
};
|
|
97
98
|
|
|
98
|
-
export const
|
|
99
|
+
export const connectDefaultPluginsToExpress4 = (
|
|
100
|
+
app,
|
|
101
|
+
{ unchainedAPI }: { unchainedAPI: UnchainedCore },
|
|
102
|
+
) => {
|
|
99
103
|
useMiddlewareWithCurrentContext(app, GRIDFS_PUT_SERVER_PATH, gridfsHandler);
|
|
100
104
|
|
|
101
|
-
useMiddlewareWithCurrentContext(app, CRYPTOPAY_WEBHOOK_PATH,
|
|
105
|
+
useMiddlewareWithCurrentContext(app, CRYPTOPAY_WEBHOOK_PATH, express.json(), cryptopayHandler);
|
|
102
106
|
|
|
103
107
|
useMiddlewareWithCurrentContext(
|
|
104
108
|
app,
|
|
105
109
|
STRIPE_WEBHOOK_PATH,
|
|
106
|
-
|
|
110
|
+
express.raw({ type: 'application/json' }),
|
|
107
111
|
stripeHandler,
|
|
108
112
|
);
|
|
109
113
|
|
|
110
114
|
useMiddlewareWithCurrentContext(
|
|
111
115
|
app,
|
|
112
116
|
PFCHECKOUT_WEBHOOK_PATH,
|
|
113
|
-
|
|
117
|
+
express.json(),
|
|
114
118
|
postfinanceCheckoutHandler,
|
|
115
119
|
);
|
|
116
120
|
|
|
117
121
|
useMiddlewareWithCurrentContext(
|
|
118
122
|
app,
|
|
119
123
|
DATATRANS_WEBHOOK_PATH,
|
|
120
|
-
|
|
124
|
+
express.text({
|
|
121
125
|
type: 'application/json',
|
|
122
126
|
}),
|
|
123
127
|
datatransHandler,
|
|
@@ -126,7 +130,7 @@ export const useDefaultMiddlewares = (unchainedApi, app) => {
|
|
|
126
130
|
useMiddlewareWithCurrentContext(
|
|
127
131
|
app,
|
|
128
132
|
APPLE_IAP_WEBHOOK_PATH,
|
|
129
|
-
|
|
133
|
+
express.json({
|
|
130
134
|
strict: false,
|
|
131
135
|
}),
|
|
132
136
|
appleIAPHandler,
|
|
@@ -135,13 +139,13 @@ export const useDefaultMiddlewares = (unchainedApi, app) => {
|
|
|
135
139
|
// useMiddlewareWithCurrentContext(
|
|
136
140
|
// app,
|
|
137
141
|
// MINIO_PUT_SERVER_PATH,
|
|
138
|
-
//
|
|
142
|
+
// express.json({
|
|
139
143
|
// strict: false,
|
|
140
144
|
// }),
|
|
141
145
|
// minioHandler
|
|
142
146
|
// );
|
|
143
147
|
|
|
144
|
-
configureExportToken(
|
|
145
|
-
configureUpdateTokenOwnership(
|
|
148
|
+
configureExportToken(unchainedAPI);
|
|
149
|
+
configureUpdateTokenOwnership(unchainedAPI);
|
|
146
150
|
configureGenerateOrderAutoscheduling();
|
|
147
151
|
};
|
|
@@ -24,7 +24,7 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
24
24
|
},
|
|
25
25
|
|
|
26
26
|
actions: (configuration, context) => {
|
|
27
|
-
const { product, orderPosition, token, modules,
|
|
27
|
+
const { product, orderPosition, token, modules, locale } = context;
|
|
28
28
|
|
|
29
29
|
const getTokensCreated = async () => {
|
|
30
30
|
const existingTokens = await modules.warehousing.findTokens(
|
|
@@ -109,12 +109,12 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
109
109
|
const url = file && (await modules.files.getUrl(file, {}));
|
|
110
110
|
const text = await modules.products.texts.findLocalizedText({
|
|
111
111
|
productId: product._id,
|
|
112
|
-
locale:
|
|
112
|
+
locale: locale?.normalized || systemLocale.normalized,
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
const name = `${text.title} #${chainTokenId}`;
|
|
116
116
|
|
|
117
|
-
const isDefaultLanguageActive =
|
|
117
|
+
const isDefaultLanguageActive = locale ? locale?.language === systemLocale.language : true;
|
|
118
118
|
const localization = isDefaultLanguageActive
|
|
119
119
|
? {
|
|
120
120
|
uri: `${process.env.ROOT_URL}/erc-metadata/${product._id}/{locale}/${product.tokenization.tokenId}.json`,
|
|
@@ -56,15 +56,10 @@ export const BulkImportWorker: IWorkerAdapter<any, Record<string, unknown>> = {
|
|
|
56
56
|
|
|
57
57
|
doWork: async (rawPayload, unchainedAPI) => {
|
|
58
58
|
try {
|
|
59
|
-
const {
|
|
60
|
-
createShouldUpsertIfIDExists = false,
|
|
61
|
-
skipCacheInvalidation = false,
|
|
62
|
-
authorId = 'root',
|
|
63
|
-
} = rawPayload;
|
|
59
|
+
const { createShouldUpsertIfIDExists = false, skipCacheInvalidation = false } = rawPayload;
|
|
64
60
|
|
|
65
61
|
const bulkImporter = unchainedAPI.bulkImporter.createBulkImporter({
|
|
66
62
|
logger,
|
|
67
|
-
authorId,
|
|
68
63
|
createShouldUpsertIfIDExists,
|
|
69
64
|
skipCacheInvalidation,
|
|
70
65
|
});
|