@commercetools/connect-payments-sdk
Advanced tools
Comparing version 0.4.3 to 0.4.4
# @commercetools/connect-payments-sdk | ||
## 0.4.4 | ||
### Patch Changes | ||
- 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 | ||
## 0.4.3 | ||
@@ -4,0 +10,0 @@ |
@@ -23,3 +23,4 @@ import { Payment, PaymentDraft } from '@commercetools/platform-sdk'; | ||
private consolidateTransactionChanges; | ||
private hasTransactionWithState; | ||
private calculateTotalAmount; | ||
} |
@@ -48,12 +48,9 @@ "use strict"; | ||
validatePaymentCancelAuthorization(opts) { | ||
const totalAuthorized = this.calculateTotalAmount(opts.payment, 'Authorization', opts.payment.amountPlanned.currencyCode); | ||
if (totalAuthorized === 0) { | ||
if (!this.hasTransactionWithState(opts.payment, 'Authorization', ['Success'])) { | ||
return { isValid: false, reason: `No authorization transaction found for resource ${opts.payment.id}.` }; | ||
} | ||
const totalCancelled = this.calculateTotalAmount(opts.payment, 'CancelAuthorization', opts.payment.amountPlanned.currencyCode); | ||
if (totalCancelled > 0) { | ||
if (this.hasTransactionWithState(opts.payment, 'CancelAuthorization', ['Success', 'Pending'])) { | ||
return { isValid: false, reason: `Resource ${opts.payment.id} has already been cancelled.` }; | ||
} | ||
const totalCaptured = this.calculateTotalAmount(opts.payment, 'Charge', opts.payment.amountPlanned.currencyCode); | ||
if (totalCaptured > 0) { | ||
if (this.hasTransactionWithState(opts.payment, 'Charge', ['Success'])) { | ||
return { isValid: false, reason: `Resource ${opts.payment.id} has already been charged.` }; | ||
@@ -74,4 +71,3 @@ } | ||
} | ||
const totalCancelled = this.calculateTotalAmount(opts.payment, 'CancelAuthorization', opts.payment.amountPlanned.currencyCode); | ||
if (totalCancelled > 0) { | ||
if (this.hasTransactionWithState(opts.payment, 'CancelAuthorization', ['Success', 'Pending'])) { | ||
return { isValid: false, reason: `Resource ${opts.payment.id} has already been cancelled.` }; | ||
@@ -96,4 +92,3 @@ } | ||
} | ||
const totalCancelled = this.calculateTotalAmount(opts.payment, 'CancelAuthorization', opts.payment.amountPlanned.currencyCode); | ||
if (totalCancelled > 0) { | ||
if (this.hasTransactionWithState(opts.payment, 'CancelAuthorization', ['Success', 'Pending'])) { | ||
return { isValid: false, reason: `Resource ${opts.payment.id} has already been cancelled.` }; | ||
@@ -202,6 +197,9 @@ } | ||
} | ||
hasTransactionWithState(payment, type, state) { | ||
return payment.transactions.some((transaction) => transaction.type === type && state.includes(transaction.state)); | ||
} | ||
calculateTotalAmount(payment, type, currencyCode) { | ||
return payment.transactions | ||
.filter((transaction) => transaction.type === type && | ||
(transaction.state === 'Success' || transaction.state === 'Pending') && | ||
transaction.state === 'Success' && | ||
transaction.amount.currencyCode === currencyCode) | ||
@@ -208,0 +206,0 @@ .reduce((total, transaction) => total + transaction.amount.centAmount, 0); |
{ | ||
"name": "@commercetools/connect-payments-sdk", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Payment SDK for commercetools payment connectors", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
107605
2765