@commercetools/connect-payments-sdk 0.2.0 → 0.2.1
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
|
@@ -78,10 +78,18 @@ class DefaultCartService {
|
|
|
78
78
|
return payments.reduce((total, payment) => total + this.calculatePaymentAmount(payment), 0);
|
|
79
79
|
}
|
|
80
80
|
calculatePaymentAmount(payment) {
|
|
81
|
+
//If an "approved" payment has been reverted, the amount should not be considered as paid
|
|
82
|
+
if (this.wasPaymentReverted(payment)) {
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
81
85
|
return payment.transactions
|
|
82
86
|
.filter((transaction) => (transaction.state === 'Success' || transaction.state === 'Pending') &&
|
|
83
87
|
(transaction.type === 'Authorization' || transaction.type === 'Charge'))
|
|
84
88
|
.reduce((total, transaction) => total + transaction.amount.centAmount, 0);
|
|
85
89
|
}
|
|
90
|
+
wasPaymentReverted(payment) {
|
|
91
|
+
return payment.transactions.some((tx) => (tx.type === 'CancelAuthorization' || tx.type === 'Refund') &&
|
|
92
|
+
(tx.state === 'Success' || tx.state === 'Pending'));
|
|
93
|
+
}
|
|
86
94
|
}
|
|
87
95
|
exports.DefaultCartService = DefaultCartService;
|
|
@@ -106,7 +106,10 @@ class DefaultPaymentService {
|
|
|
106
106
|
actions.push(this.populateSetPaymentMethod(updateInfo.paymentMethod));
|
|
107
107
|
}
|
|
108
108
|
if (updateInfo.transaction) {
|
|
109
|
-
|
|
109
|
+
const transactionChanges = this.consolidateTransactionChanges(payment, updateInfo.transaction);
|
|
110
|
+
if (transactionChanges.length > 0) {
|
|
111
|
+
actions.push(...transactionChanges);
|
|
112
|
+
}
|
|
110
113
|
}
|
|
111
114
|
return actions;
|
|
112
115
|
}
|
|
@@ -157,6 +160,10 @@ class DefaultPaymentService {
|
|
|
157
160
|
}
|
|
158
161
|
consolidateTransactionChanges(payment, transaction) {
|
|
159
162
|
const actions = [];
|
|
163
|
+
// If the transaction is in Initial state and has no interactionId, we discard it as it does not provide any value
|
|
164
|
+
if (transaction.state === 'Initial' && !transaction.interactionId) {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
160
167
|
const matchingTxs = this.findMatchingTransactions(payment, transaction);
|
|
161
168
|
if (matchingTxs.length === 0) {
|
|
162
169
|
actions.push(this.populateAddTransactionAction(transaction));
|