@commercetools/connect-payments-sdk 0.4.2 → 0.4.4
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
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @commercetools/connect-payments-sdk
|
|
2
2
|
|
|
3
|
+
## 0.4.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 062bbeb: Solved issue validating a payment refund as the code allowed to trigger a refund when the payment did not have a successful charge transaction
|
|
8
|
+
|
|
9
|
+
## 0.4.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- f155772: fix payment modification validations by checking that a payment could contain a cancelAuthorization transaction
|
|
14
|
+
|
|
3
15
|
## 0.4.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -45,12 +45,13 @@ class DefaultPaymentService {
|
|
|
45
45
|
throw err;
|
|
46
46
|
}
|
|
47
47
|
validatePaymentCancelAuthorization(opts) {
|
|
48
|
-
|
|
49
|
-
if (totalAuthorized === 0) {
|
|
48
|
+
if (!this.hasTransactionWithState(opts.payment, 'Authorization', ['Success'])) {
|
|
50
49
|
return { isValid: false, reason: `No authorization transaction found for resource ${opts.payment.id}.` };
|
|
51
50
|
}
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
if (this.hasTransactionWithState(opts.payment, 'CancelAuthorization', ['Success', 'Pending'])) {
|
|
52
|
+
return { isValid: false, reason: `Resource ${opts.payment.id} has already been cancelled.` };
|
|
53
|
+
}
|
|
54
|
+
if (this.hasTransactionWithState(opts.payment, 'Charge', ['Success'])) {
|
|
54
55
|
return { isValid: false, reason: `Resource ${opts.payment.id} has already been charged.` };
|
|
55
56
|
}
|
|
56
57
|
return { isValid: true };
|
|
@@ -66,6 +67,9 @@ class DefaultPaymentService {
|
|
|
66
67
|
if (totalAuthorized === 0) {
|
|
67
68
|
return { isValid: false, reason: `No authorization transaction found for resource ${opts.payment.id}.` };
|
|
68
69
|
}
|
|
70
|
+
if (this.hasTransactionWithState(opts.payment, 'CancelAuthorization', ['Success', 'Pending'])) {
|
|
71
|
+
return { isValid: false, reason: `Resource ${opts.payment.id} has already been cancelled.` };
|
|
72
|
+
}
|
|
69
73
|
const totalCaptured = this.calculateTotalAmount(opts.payment, 'Charge', opts.amount.currencyCode);
|
|
70
74
|
const allowedAmount = totalAuthorized - totalCaptured;
|
|
71
75
|
if (opts.amount.centAmount > allowedAmount) {
|
|
@@ -83,6 +87,9 @@ class DefaultPaymentService {
|
|
|
83
87
|
reason: `Invalid currency ${opts.amount.currencyCode} for resource ${opts.payment.id}, expected ${opts.payment.amountPlanned.currencyCode}`,
|
|
84
88
|
};
|
|
85
89
|
}
|
|
90
|
+
if (this.hasTransactionWithState(opts.payment, 'CancelAuthorization', ['Success', 'Pending'])) {
|
|
91
|
+
return { isValid: false, reason: `Resource ${opts.payment.id} has already been cancelled.` };
|
|
92
|
+
}
|
|
86
93
|
const totalCaptured = this.calculateTotalAmount(opts.payment, 'Charge', opts.amount.currencyCode);
|
|
87
94
|
if (totalCaptured === 0) {
|
|
88
95
|
return { isValid: false, reason: `No charge transaction found for resource ${opts.payment.id}.` };
|
|
@@ -154,8 +161,7 @@ class DefaultPaymentService {
|
|
|
154
161
|
tx.amount.centAmount === transaction.amount.centAmount &&
|
|
155
162
|
tx.amount.currencyCode === transaction.amount.currencyCode &&
|
|
156
163
|
transaction.interactionId &&
|
|
157
|
-
((tx.interactionId && tx.
|
|
158
|
-
(!tx.interactionId && tx.state === 'Initial')));
|
|
164
|
+
(tx.interactionId || (!tx.interactionId && tx.state === 'Initial')));
|
|
159
165
|
});
|
|
160
166
|
}
|
|
161
167
|
consolidateTransactionChanges(payment, transaction) {
|
|
@@ -185,6 +191,9 @@ class DefaultPaymentService {
|
|
|
185
191
|
}
|
|
186
192
|
return actions;
|
|
187
193
|
}
|
|
194
|
+
hasTransactionWithState(payment, type, state) {
|
|
195
|
+
return payment.transactions.some((transaction) => transaction.type === type && state.includes(transaction.state));
|
|
196
|
+
}
|
|
188
197
|
calculateTotalAmount(payment, type, currencyCode) {
|
|
189
198
|
return payment.transactions
|
|
190
199
|
.filter((transaction) => transaction.type === type &&
|
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.4",
|
|
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
|
}
|