From 17f465b328694314a1c91f9de899d4efe08f2d59 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 11:46:58 +0300 Subject: [PATCH 01/17] [SL-261] init --- controllers/front/ajax.php | 6 ++ src/Exception/ExceptionCode.php | 2 + .../UnauthenticatedCardUserException.php | 35 ++++++++++ src/Exception/SaferPayException.php | 8 +++ .../SaferPayCardAliasRepository.php | 11 ++++ .../CustomerCreditCardValidation.php | 66 +++++++++++++++++++ 6 files changed, 128 insertions(+) create mode 100644 src/Exception/Restriction/UnauthenticatedCardUserException.php create mode 100644 src/Validation/CustomerCreditCardValidation.php diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 3b167f65..e2fa9d7d 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -28,6 +28,7 @@ use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Utility\ExceptionUtility; +use Invertus\SaferPay\Validation\CustomerCreditCardValidation; if (!defined('_PS_VERSION_')) { exit; @@ -145,6 +146,11 @@ private function submitHostedFields() /** @var LoggerInterface $logger */ $logger = $this->module->getService(LoggerInterface::class); + /** @var CustomerCreditCardValidation $customerCreditCardValidation */ + $customerCreditCardValidation = $this->module->getService(CustomerCreditCardValidation::class); + + $customerCreditCardValidation->validate("2", $this->context->customer->id); + try { if (Order::getOrderByCartId($this->context->cart->id)) { $this->ajaxDie(json_encode([ diff --git a/src/Exception/ExceptionCode.php b/src/Exception/ExceptionCode.php index aabe86ec..01a566c2 100644 --- a/src/Exception/ExceptionCode.php +++ b/src/Exception/ExceptionCode.php @@ -34,6 +34,8 @@ class ExceptionCode const PAYMENT_FAILED_TO_FIND_CART = 5001; const PAYMENT_FAILED_TO_CREATE_ORDER = 5002; + const CANNOT_USE_CARD = 5003; + // Order related codes starts from 7*** const ORDER_FAILED_TO_FIND_ORDER = 7001; const ORDER_UNHANDLED_TRANSACTION_STATUS = 7002; diff --git a/src/Exception/Restriction/UnauthenticatedCardUserException.php b/src/Exception/Restriction/UnauthenticatedCardUserException.php new file mode 100644 index 00000000..bb8c396e --- /dev/null +++ b/src/Exception/Restriction/UnauthenticatedCardUserException.php @@ -0,0 +1,35 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\SaferPay\Exception\Restriction; + +use Invertus\SaferPay\Exception\SaferPayException; +use RuntimeException; + +if (!defined('_PS_VERSION_')) { + exit; +} + +class UnauthenticatedCardUserException extends SaferPayException +{ +} diff --git a/src/Exception/SaferPayException.php b/src/Exception/SaferPayException.php index 851bd257..6c072cc0 100644 --- a/src/Exception/SaferPayException.php +++ b/src/Exception/SaferPayException.php @@ -52,4 +52,12 @@ public static function unknownError() ExceptionCode::UNKNOWN_ERROR ); } + + public static function unauthenticatedCard() + { + return new static( + 'Customer cannot use current saved card at this moment.', + ExceptionCode::CANNOT_USE_CARD + ); + } } diff --git a/src/Repository/SaferPayCardAliasRepository.php b/src/Repository/SaferPayCardAliasRepository.php index 5cf24362..ecd067a3 100755 --- a/src/Repository/SaferPayCardAliasRepository.php +++ b/src/Repository/SaferPayCardAliasRepository.php @@ -74,4 +74,15 @@ public function getSavedCardsByCustomerId($customerId) return Db::getInstance()->executeS($query); } + + public function getCustomerIdByReferenceId($customerId, $aliasId) + { + $query = new DbQuery(); + $query->select('`id_customer`'); + $query->from('saferpay_card_alias'); + $query->where('id_customer = "' . (int) $customerId . '"'); + $query->where('alias_id = "' . pSQL($aliasId) . '"')->limit(1); + + return Db::getInstance()->getValue($query); + } } diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php new file mode 100644 index 00000000..4a86fbec --- /dev/null +++ b/src/Validation/CustomerCreditCardValidation.php @@ -0,0 +1,66 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\SaferPay\Validation; + +use Complex\Exception; +use Invertus\SaferPay\Exception\Api\SaferPayApiException; +use Invertus\SaferPay\Exception\Restriction\UnauthenticatedCardUserException; +use Invertus\SaferPay\Exception\SaferPayException; +use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; + +if (!defined('_PS_VERSION_')) { + exit; +} + +class CustomerCreditCardValidation +{ + /** @var \Module */ + private $module; + public function __construct(\Module $module) + { + $this->module = \Module::getInstanceByName('saferpayofficial'); + } + + /** + * @return true|Exception + * @throws UnauthenticatedCardUserException + */ + public function validate($idSavedCard, $idCustomer) + { + /** @var SaferPayCardAliasRepository $cardAliasRepository */ + $cardAliasRepository = $this->module->getService(SaferPayCardAliasRepository::class); + + if ($idCustomer < 1) { + return true; + } + + $cardOwnerId = $cardAliasRepository->getCustomerIdByReferenceId($idCustomer, $idSavedCard); + + if ($cardOwnerId === $idCustomer) { + return true; + } else { + throw UnauthenticatedCardUserException::unauthenticatedCard(); + } + } +} \ No newline at end of file From 9596cbe823665952259d558afed8ade091eb1ac2 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 13:36:57 +0300 Subject: [PATCH 02/17] [SL-261] fix service --- controllers/front/ajax.php | 23 ++++++++++++++++--- .../SaferPayCardAliasRepository.php | 5 ++-- .../CustomerCreditCardValidation.php | 20 ++++++++-------- 3 files changed, 31 insertions(+), 17 deletions(-) mode change 100644 => 100755 src/Validation/CustomerCreditCardValidation.php diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index e2fa9d7d..41dee156 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -25,6 +25,7 @@ use Invertus\SaferPay\Controller\Front\CheckoutController; use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; use Invertus\SaferPay\Enum\ControllerName; +use Invertus\SaferPay\Exception\Restriction\UnauthenticatedCardUserException; use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Utility\ExceptionUtility; @@ -146,10 +147,26 @@ private function submitHostedFields() /** @var LoggerInterface $logger */ $logger = $this->module->getService(LoggerInterface::class); - /** @var CustomerCreditCardValidation $customerCreditCardValidation */ - $customerCreditCardValidation = $this->module->getService(CustomerCreditCardValidation::class); + /** @var CustomerCreditCardValidation $cardValidation */ + $cardValidation = $this->module->getService(CustomerCreditCardValidation::class); - $customerCreditCardValidation->validate("2", $this->context->customer->id); + try { + $cardValidation->validate(Tools::getValue('selectedCard'), $this->context->customer->id); + } catch (UnauthenticatedCardUserException $e) { + $logger->error($e->getMessage(), [ + 'context' => [], + 'id_customer' => $this->context->customer->id, + 'id_card' => Tools::getValue('selectedCard'), + 'id_card_owner' => + 'exceptions' => ExceptionUtility::getExceptions($e), + ]); + + $this->ajaxDie(json_encode([ + 'error' => true, + 'message' => $e->getMessage(), + 'url' => $this->getRedirectionToControllerUrl('fail'), + ])); + } try { if (Order::getOrderByCartId($this->context->cart->id)) { diff --git a/src/Repository/SaferPayCardAliasRepository.php b/src/Repository/SaferPayCardAliasRepository.php index ecd067a3..182e551d 100755 --- a/src/Repository/SaferPayCardAliasRepository.php +++ b/src/Repository/SaferPayCardAliasRepository.php @@ -75,13 +75,12 @@ public function getSavedCardsByCustomerId($customerId) return Db::getInstance()->executeS($query); } - public function getCustomerIdByReferenceId($customerId, $aliasId) + public function getCustomerIdByReferenceId($cardAliasId) { $query = new DbQuery(); $query->select('`id_customer`'); $query->from('saferpay_card_alias'); - $query->where('id_customer = "' . (int) $customerId . '"'); - $query->where('alias_id = "' . pSQL($aliasId) . '"')->limit(1); + $query->where('id_saferpay_card_alias = "' . pSQL($cardAliasId) . '"'); return Db::getInstance()->getValue($query); } diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php old mode 100644 new mode 100755 index 4a86fbec..5ed2f550 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -23,10 +23,8 @@ namespace Invertus\SaferPay\Validation; -use Complex\Exception; -use Invertus\SaferPay\Exception\Api\SaferPayApiException; +use Exception; use Invertus\SaferPay\Exception\Restriction\UnauthenticatedCardUserException; -use Invertus\SaferPay\Exception\SaferPayException; use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; if (!defined('_PS_VERSION_')) { @@ -35,11 +33,14 @@ class CustomerCreditCardValidation { - /** @var \Module */ - private $module; - public function __construct(\Module $module) + /** + * @var SaferPayCardAliasRepository + */ + private $saferPayCardAliasRepository; + + public function __construct(SaferPayCardAliasRepository $saferPayCardAliasRepository) { - $this->module = \Module::getInstanceByName('saferpayofficial'); + $this->saferPayCardAliasRepository = $saferPayCardAliasRepository; } /** @@ -48,14 +49,11 @@ public function __construct(\Module $module) */ public function validate($idSavedCard, $idCustomer) { - /** @var SaferPayCardAliasRepository $cardAliasRepository */ - $cardAliasRepository = $this->module->getService(SaferPayCardAliasRepository::class); - if ($idCustomer < 1) { return true; } - $cardOwnerId = $cardAliasRepository->getCustomerIdByReferenceId($idCustomer, $idSavedCard); + $cardOwnerId = $this->saferPayCardAliasRepository->getCustomerIdByReferenceId($idSavedCard); if ($cardOwnerId === $idCustomer) { return true; From 22096d2deaaf8e20b2d41561730d39334564f52d Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 13:37:42 +0300 Subject: [PATCH 03/17] fix --- src/Validation/CustomerCreditCardValidation.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/Validation/CustomerCreditCardValidation.php diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php old mode 100755 new mode 100644 From 3cebebc6ee8ba47f13f84114b02e2e6b359c40ee Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 13:47:14 +0300 Subject: [PATCH 04/17] [SL-261] Added more context to exception --- controllers/front/ajax.php | 4 ++-- src/Exception/SaferPayException.php | 7 +++++-- src/Validation/CustomerCreditCardValidation.php | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 41dee156..2e58418b 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -27,6 +27,7 @@ use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Exception\Restriction\UnauthenticatedCardUserException; use Invertus\SaferPay\Logger\LoggerInterface; +use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Utility\ExceptionUtility; use Invertus\SaferPay\Validation\CustomerCreditCardValidation; @@ -151,13 +152,12 @@ private function submitHostedFields() $cardValidation = $this->module->getService(CustomerCreditCardValidation::class); try { - $cardValidation->validate(Tools::getValue('selectedCard'), $this->context->customer->id); + $cardValidation->validate("2", $this->context->customer->id); } catch (UnauthenticatedCardUserException $e) { $logger->error($e->getMessage(), [ 'context' => [], 'id_customer' => $this->context->customer->id, 'id_card' => Tools::getValue('selectedCard'), - 'id_card_owner' => 'exceptions' => ExceptionUtility::getExceptions($e), ]); diff --git a/src/Exception/SaferPayException.php b/src/Exception/SaferPayException.php index 6c072cc0..c2d107a1 100644 --- a/src/Exception/SaferPayException.php +++ b/src/Exception/SaferPayException.php @@ -53,11 +53,14 @@ public static function unknownError() ); } - public static function unauthenticatedCard() + public static function unauthenticatedCard($idCardOwner) { return new static( 'Customer cannot use current saved card at this moment.', - ExceptionCode::CANNOT_USE_CARD + ExceptionCode::CANNOT_USE_CARD, + [ + 'id_card_owner' => $idCardOwner, + ] ); } } diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php index 5ed2f550..8f50109d 100644 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -58,7 +58,7 @@ public function validate($idSavedCard, $idCustomer) if ($cardOwnerId === $idCustomer) { return true; } else { - throw UnauthenticatedCardUserException::unauthenticatedCard(); + throw UnauthenticatedCardUserException::unauthenticatedCard($cardOwnerId); } } } \ No newline at end of file From 825283e708171bd5b205390d026dbaa25ca22798 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 13:47:53 +0300 Subject: [PATCH 05/17] [SL-261] Removed hard-code --- controllers/front/ajax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 2e58418b..1930da64 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -152,7 +152,7 @@ private function submitHostedFields() $cardValidation = $this->module->getService(CustomerCreditCardValidation::class); try { - $cardValidation->validate("2", $this->context->customer->id); + $cardValidation->validate(Tools::getValue('selectedCard'), $this->context->customer->id); } catch (UnauthenticatedCardUserException $e) { $logger->error($e->getMessage(), [ 'context' => [], From c0e68c574722433d8ed248425d34e53c12c0fe88 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 14:48:15 +0300 Subject: [PATCH 06/17] [SL-261] fix minor --- controllers/front/ajax.php | 14 +++++++++++++- .../CustomerCreditCardValidation.php | 19 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 1930da64..2828780f 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -26,6 +26,7 @@ use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Exception\Restriction\UnauthenticatedCardUserException; +use Invertus\SaferPay\Exception\SaferPayException; use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; use Invertus\SaferPay\Repository\SaferPayOrderRepository; @@ -152,7 +153,7 @@ private function submitHostedFields() $cardValidation = $this->module->getService(CustomerCreditCardValidation::class); try { - $cardValidation->validate(Tools::getValue('selectedCard'), $this->context->customer->id); + $cardValidation->validate(null, $this->context->customer->id); } catch (UnauthenticatedCardUserException $e) { $logger->error($e->getMessage(), [ 'context' => [], @@ -161,6 +162,17 @@ private function submitHostedFields() 'exceptions' => ExceptionUtility::getExceptions($e), ]); + $this->ajaxDie(json_encode([ + 'error' => true, + 'message' => $e->getMessage(), + 'url' => $this->getRedirectionToControllerUrl('fail'), + ])); + } catch (SaferPayException $e) { + $logger->error($e->getMessage(), [ + 'context' => [], + 'exceptions' => ExceptionUtility::getExceptions($e), + ]); + $this->ajaxDie(json_encode([ 'error' => true, 'message' => $e->getMessage(), diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php index 8f50109d..a9b35e55 100644 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -25,6 +25,8 @@ use Exception; use Invertus\SaferPay\Exception\Restriction\UnauthenticatedCardUserException; +use Invertus\SaferPay\Exception\SaferPayException; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; if (!defined('_PS_VERSION_')) { @@ -37,10 +39,17 @@ class CustomerCreditCardValidation * @var SaferPayCardAliasRepository */ private $saferPayCardAliasRepository; + /** + * @var mixed + */ + private $logger; + + const FILE_NAME = 'CustomerCreditCardValidation'; - public function __construct(SaferPayCardAliasRepository $saferPayCardAliasRepository) + public function __construct(SaferPayCardAliasRepository $saferPayCardAliasRepository, LoggerInterface $logger) { $this->saferPayCardAliasRepository = $saferPayCardAliasRepository; + $this->logger = $logger; } /** @@ -49,6 +58,14 @@ public function __construct(SaferPayCardAliasRepository $saferPayCardAliasReposi */ public function validate($idSavedCard, $idCustomer) { + if (empty($idSavedCard) || $idCustomer) { + $this->logger->error(sprintf('%s - Missing required data', self::FILE_NAME), [ + 'context' => [] + ]); + + throw SaferPayException::unknownError(); + } + if ($idCustomer < 1) { return true; } From b9c20210f756e86c6df8d0ac15b5b6ffb322f0e8 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 14:48:36 +0300 Subject: [PATCH 07/17] [SL-261] whitespace --- src/Validation/CustomerCreditCardValidation.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php index a9b35e55..dc16b2ad 100644 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -54,6 +54,7 @@ public function __construct(SaferPayCardAliasRepository $saferPayCardAliasReposi /** * @return true|Exception + * * @throws UnauthenticatedCardUserException */ public function validate($idSavedCard, $idCustomer) From 6c8197bd717774331c91b299332932377e319735 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 14:49:27 +0300 Subject: [PATCH 08/17] [SL-261] fix --- src/Validation/CustomerCreditCardValidation.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php index dc16b2ad..f42d0091 100644 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -53,9 +53,10 @@ public function __construct(SaferPayCardAliasRepository $saferPayCardAliasReposi } /** - * @return true|Exception + * @return true * * @throws UnauthenticatedCardUserException + * @throws SaferPayException */ public function validate($idSavedCard, $idCustomer) { From 59f23de9e93c0ac1e3342c72f61566a007aabf48 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 14:55:12 +0300 Subject: [PATCH 09/17] typo --- controllers/front/ajax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 2828780f..d3beb143 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -153,7 +153,7 @@ private function submitHostedFields() $cardValidation = $this->module->getService(CustomerCreditCardValidation::class); try { - $cardValidation->validate(null, $this->context->customer->id); + $cardValidation->validate(Tools::getValue('selectedCard'), $this->context->customer->id); } catch (UnauthenticatedCardUserException $e) { $logger->error($e->getMessage(), [ 'context' => [], From 01caad083ad3828f42805b0c377cde2b8547ddb2 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 15:16:23 +0300 Subject: [PATCH 10/17] fix --- src/Repository/SaferPayCardAliasRepository.php | 3 ++- src/Validation/CustomerCreditCardValidation.php | 12 ++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Repository/SaferPayCardAliasRepository.php b/src/Repository/SaferPayCardAliasRepository.php index 182e551d..d1664313 100755 --- a/src/Repository/SaferPayCardAliasRepository.php +++ b/src/Repository/SaferPayCardAliasRepository.php @@ -75,12 +75,13 @@ public function getSavedCardsByCustomerId($customerId) return Db::getInstance()->executeS($query); } - public function getCustomerIdByReferenceId($cardAliasId) + public function getCustomerIdByReferenceId($cardAliasId, $idCustomer) { $query = new DbQuery(); $query->select('`id_customer`'); $query->from('saferpay_card_alias'); $query->where('id_saferpay_card_alias = "' . pSQL($cardAliasId) . '"'); + $query->where('id_customer = "' . (int) $idCustomer . '"'); return Db::getInstance()->getValue($query); } diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php index f42d0091..46ec9526 100644 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -68,16 +68,12 @@ public function validate($idSavedCard, $idCustomer) throw SaferPayException::unknownError(); } - if ($idCustomer < 1) { - return true; - } + $cardOwnerId = $this->saferPayCardAliasRepository->getCustomerIdByReferenceId($idSavedCard, $idCustomer); - $cardOwnerId = $this->saferPayCardAliasRepository->getCustomerIdByReferenceId($idSavedCard); - - if ($cardOwnerId === $idCustomer) { + if (!empty($cardOwnerId)) { return true; - } else { - throw UnauthenticatedCardUserException::unauthenticatedCard($cardOwnerId); } + + return throw UnauthenticatedCardUserException::unauthenticatedCard($cardOwnerId); } } \ No newline at end of file From b4f8f8d3378cab88755c03a2fa7060924c854af0 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 15:18:50 +0300 Subject: [PATCH 11/17] fix --- src/Validation/CustomerCreditCardValidation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php index 46ec9526..7d87147d 100644 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -60,7 +60,7 @@ public function __construct(SaferPayCardAliasRepository $saferPayCardAliasReposi */ public function validate($idSavedCard, $idCustomer) { - if (empty($idSavedCard) || $idCustomer) { + if (empty($idSavedCard) || empty($idCustomer)) { $this->logger->error(sprintf('%s - Missing required data', self::FILE_NAME), [ 'context' => [] ]); @@ -68,7 +68,7 @@ public function validate($idSavedCard, $idCustomer) throw SaferPayException::unknownError(); } - $cardOwnerId = $this->saferPayCardAliasRepository->getCustomerIdByReferenceId($idSavedCard, $idCustomer); + $cardOwnerId = $this->saferPayCardAliasRepository->getCustomerIdByReferenceId(pSQL($idSavedCard), pSQL($idCustomer)); if (!empty($cardOwnerId)) { return true; From c0a7dcae5fd79bc1d7aa1e32925f31acefd443d4 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 18 Oct 2024 15:40:34 +0300 Subject: [PATCH 12/17] reverse --- src/Validation/CustomerCreditCardValidation.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php index 7d87147d..aaaef99d 100644 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -70,10 +70,10 @@ public function validate($idSavedCard, $idCustomer) $cardOwnerId = $this->saferPayCardAliasRepository->getCustomerIdByReferenceId(pSQL($idSavedCard), pSQL($idCustomer)); - if (!empty($cardOwnerId)) { - return true; + if (empty($cardOwnerId)) { + return throw UnauthenticatedCardUserException::unauthenticatedCard($cardOwnerId); } - return throw UnauthenticatedCardUserException::unauthenticatedCard($cardOwnerId); + return true; } } \ No newline at end of file From 187972ce2c57e10cacca32350159a0683ec49eec Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Sun, 20 Oct 2024 12:17:28 +0300 Subject: [PATCH 13/17] [SL-261] added check --- src/Validation/CustomerCreditCardValidation.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php index aaaef99d..85444b90 100644 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -60,6 +60,16 @@ public function __construct(SaferPayCardAliasRepository $saferPayCardAliasReposi */ public function validate($idSavedCard, $idCustomer) { + if (!is_numeric($idCustomer) || !is_numeric($idSavedCard)) { + $this->logger->error(sprintf('%s - Invalid data', self::FILE_NAME), [ + 'context' => [], + 'id_saved_card' => $idSavedCard, + 'id_customer' => $idCustomer + ]); + + throw SaferPayException::unknownError(); + } + if (empty($idSavedCard) || empty($idCustomer)) { $this->logger->error(sprintf('%s - Missing required data', self::FILE_NAME), [ 'context' => [] From d69dcd29c7295383c27b3d572a82c38b7e9692ea Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Sun, 20 Oct 2024 12:18:12 +0300 Subject: [PATCH 14/17] replaced --- src/Validation/CustomerCreditCardValidation.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php index 85444b90..bfc91358 100644 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -60,19 +60,19 @@ public function __construct(SaferPayCardAliasRepository $saferPayCardAliasReposi */ public function validate($idSavedCard, $idCustomer) { - if (!is_numeric($idCustomer) || !is_numeric($idSavedCard)) { - $this->logger->error(sprintf('%s - Invalid data', self::FILE_NAME), [ - 'context' => [], - 'id_saved_card' => $idSavedCard, - 'id_customer' => $idCustomer + if (empty($idSavedCard) || empty($idCustomer)) { + $this->logger->error(sprintf('%s - Missing required data', self::FILE_NAME), [ + 'context' => [] ]); throw SaferPayException::unknownError(); } - if (empty($idSavedCard) || empty($idCustomer)) { - $this->logger->error(sprintf('%s - Missing required data', self::FILE_NAME), [ - 'context' => [] + if (!is_numeric($idCustomer) || !is_numeric($idSavedCard)) { + $this->logger->error(sprintf('%s - Invalid data', self::FILE_NAME), [ + 'context' => [], + 'id_saved_card' => $idSavedCard, + 'id_customer' => $idCustomer ]); throw SaferPayException::unknownError(); From cea051923886155e9949295ceee166c5adb3bbad Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Sun, 20 Oct 2024 12:21:43 +0300 Subject: [PATCH 15/17] fix --- src/Validation/CustomerCreditCardValidation.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php index bfc91358..a8e1ab06 100644 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -60,16 +60,11 @@ public function __construct(SaferPayCardAliasRepository $saferPayCardAliasReposi */ public function validate($idSavedCard, $idCustomer) { - if (empty($idSavedCard) || empty($idCustomer)) { - $this->logger->error(sprintf('%s - Missing required data', self::FILE_NAME), [ - 'context' => [] - ]); - - throw SaferPayException::unknownError(); - } - - if (!is_numeric($idCustomer) || !is_numeric($idSavedCard)) { - $this->logger->error(sprintf('%s - Invalid data', self::FILE_NAME), [ + if ( + !is_numeric($idCustomer) || !is_numeric($idSavedCard) + || empty($idCustomer) || empty($idSavedCard)) + { + $this->logger->error(sprintf('%s - Invalid data or bad types', self::FILE_NAME), [ 'context' => [], 'id_saved_card' => $idSavedCard, 'id_customer' => $idCustomer From f55748da127d6a5c3aa7df82999b8d466b56f8b6 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Sun, 20 Oct 2024 12:22:52 +0300 Subject: [PATCH 16/17] whitespace --- src/Exception/ExceptionCode.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Exception/ExceptionCode.php b/src/Exception/ExceptionCode.php index 01a566c2..d7a0a14d 100644 --- a/src/Exception/ExceptionCode.php +++ b/src/Exception/ExceptionCode.php @@ -33,7 +33,6 @@ class ExceptionCode // Payment related codes starts from 5*** const PAYMENT_FAILED_TO_FIND_CART = 5001; const PAYMENT_FAILED_TO_CREATE_ORDER = 5002; - const CANNOT_USE_CARD = 5003; // Order related codes starts from 7*** From 7722f20ed0b1bc448eaf6359de3f1b768794b118 Mon Sep 17 00:00:00 2001 From: Marijus <106698165+MarijusCoding@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:53:53 +0300 Subject: [PATCH 17/17] Update src/Validation/CustomerCreditCardValidation.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Julius Žukauskas <31609858+zuk3975@users.noreply.github.com> --- src/Validation/CustomerCreditCardValidation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Validation/CustomerCreditCardValidation.php b/src/Validation/CustomerCreditCardValidation.php index a8e1ab06..89f71949 100644 --- a/src/Validation/CustomerCreditCardValidation.php +++ b/src/Validation/CustomerCreditCardValidation.php @@ -76,7 +76,7 @@ public function validate($idSavedCard, $idCustomer) $cardOwnerId = $this->saferPayCardAliasRepository->getCustomerIdByReferenceId(pSQL($idSavedCard), pSQL($idCustomer)); if (empty($cardOwnerId)) { - return throw UnauthenticatedCardUserException::unauthenticatedCard($cardOwnerId); + throw UnauthenticatedCardUserException::unauthenticatedCard($cardOwnerId); } return true;