Socket
Socket
Sign inDemoInstall

@commercetools/connect-payments-sdk

Package Overview
Dependencies
Maintainers
12
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools/connect-payments-sdk - npm Package Compare versions

Comparing version 0.4.3 to 0.4.4

6

CHANGELOG.md
# @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 @@

1

dist/commercetools/services/ct-payment.service.d.ts

@@ -23,3 +23,4 @@ import { Payment, PaymentDraft } from '@commercetools/platform-sdk';

private consolidateTransactionChanges;
private hasTransactionWithState;
private calculateTotalAmount;
}

20

dist/commercetools/services/ct-payment.service.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc