@commercetools/connect-payments-sdk 0.4.2 → 0.4.3
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/CHANGELOG.md
CHANGED
|
@@ -49,6 +49,10 @@ class DefaultPaymentService {
|
|
|
49
49
|
if (totalAuthorized === 0) {
|
|
50
50
|
return { isValid: false, reason: `No authorization transaction found for resource ${opts.payment.id}.` };
|
|
51
51
|
}
|
|
52
|
+
const totalCancelled = this.calculateTotalAmount(opts.payment, 'CancelAuthorization', opts.payment.amountPlanned.currencyCode);
|
|
53
|
+
if (totalCancelled > 0) {
|
|
54
|
+
return { isValid: false, reason: `Resource ${opts.payment.id} has already been cancelled.` };
|
|
55
|
+
}
|
|
52
56
|
const totalCaptured = this.calculateTotalAmount(opts.payment, 'Charge', opts.payment.amountPlanned.currencyCode);
|
|
53
57
|
if (totalCaptured > 0) {
|
|
54
58
|
return { isValid: false, reason: `Resource ${opts.payment.id} has already been charged.` };
|
|
@@ -66,6 +70,10 @@ class DefaultPaymentService {
|
|
|
66
70
|
if (totalAuthorized === 0) {
|
|
67
71
|
return { isValid: false, reason: `No authorization transaction found for resource ${opts.payment.id}.` };
|
|
68
72
|
}
|
|
73
|
+
const totalCancelled = this.calculateTotalAmount(opts.payment, 'CancelAuthorization', opts.payment.amountPlanned.currencyCode);
|
|
74
|
+
if (totalCancelled > 0) {
|
|
75
|
+
return { isValid: false, reason: `Resource ${opts.payment.id} has already been cancelled.` };
|
|
76
|
+
}
|
|
69
77
|
const totalCaptured = this.calculateTotalAmount(opts.payment, 'Charge', opts.amount.currencyCode);
|
|
70
78
|
const allowedAmount = totalAuthorized - totalCaptured;
|
|
71
79
|
if (opts.amount.centAmount > allowedAmount) {
|
|
@@ -83,6 +91,10 @@ class DefaultPaymentService {
|
|
|
83
91
|
reason: `Invalid currency ${opts.amount.currencyCode} for resource ${opts.payment.id}, expected ${opts.payment.amountPlanned.currencyCode}`,
|
|
84
92
|
};
|
|
85
93
|
}
|
|
94
|
+
const totalCancelled = this.calculateTotalAmount(opts.payment, 'CancelAuthorization', opts.payment.amountPlanned.currencyCode);
|
|
95
|
+
if (totalCancelled > 0) {
|
|
96
|
+
return { isValid: false, reason: `Resource ${opts.payment.id} has already been cancelled.` };
|
|
97
|
+
}
|
|
86
98
|
const totalCaptured = this.calculateTotalAmount(opts.payment, 'Charge', opts.amount.currencyCode);
|
|
87
99
|
if (totalCaptured === 0) {
|
|
88
100
|
return { isValid: false, reason: `No charge transaction found for resource ${opts.payment.id}.` };
|
|
@@ -154,8 +166,7 @@ class DefaultPaymentService {
|
|
|
154
166
|
tx.amount.centAmount === transaction.amount.centAmount &&
|
|
155
167
|
tx.amount.currencyCode === transaction.amount.currencyCode &&
|
|
156
168
|
transaction.interactionId &&
|
|
157
|
-
((tx.interactionId && tx.
|
|
158
|
-
(!tx.interactionId && tx.state === 'Initial')));
|
|
169
|
+
(tx.interactionId || (!tx.interactionId && tx.state === 'Initial')));
|
|
159
170
|
});
|
|
160
171
|
}
|
|
161
172
|
consolidateTransactionChanges(payment, transaction) {
|
|
@@ -188,7 +199,7 @@ class DefaultPaymentService {
|
|
|
188
199
|
calculateTotalAmount(payment, type, currencyCode) {
|
|
189
200
|
return payment.transactions
|
|
190
201
|
.filter((transaction) => transaction.type === type &&
|
|
191
|
-
transaction.state === 'Success' &&
|
|
202
|
+
(transaction.state === 'Success' || transaction.state === 'Pending') &&
|
|
192
203
|
transaction.amount.currencyCode === currencyCode)
|
|
193
204
|
.reduce((total, transaction) => total + transaction.amount.centAmount, 0);
|
|
194
205
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/connect-payments-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Payment SDK for commercetools payment connectors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
],
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@commercetools/platform-sdk": "7.
|
|
19
|
-
"@commercetools/sdk-client-v2": "2.4.
|
|
18
|
+
"@commercetools/platform-sdk": "7.7.0",
|
|
19
|
+
"@commercetools/sdk-client-v2": "2.4.1",
|
|
20
20
|
"jsonwebtoken": "9.0.2",
|
|
21
21
|
"jwks-rsa": "3.1.0"
|
|
22
22
|
}
|