From 8758931bfbba6621f44ab4bde4d6a87f6820e230 Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 12:06:56 -0500 Subject: [PATCH 01/16] refactor: move exceptions to share folder --- .../Exceptions/InvalidOrderException.php | 2 +- .../Oneclick/AuthorizeOneclickException.php | 2 +- ...intsViolatedAuthorizeOneclickException.php | 2 +- .../CreateTransactionOneclickException.php | 2 +- .../FinishInscriptionOneclickException.php | 2 +- .../GetInscriptionOneclickException.php | 2 +- .../GetTransactionOneclickException.php | 2 +- ...alidStatusInscriptionOneclickException.php | 2 +- .../NotFoundTransactionOneclickException.php | 2 +- .../Oneclick/RefundOneclickException.php | 2 +- .../RejectedAuthorizeOneclickException.php | 2 +- .../RejectedInscriptionOneclickException.php | 2 +- .../RejectedRefundOneclickException.php | 2 +- .../StartInscriptionOneclickException.php | 2 +- .../Oneclick/StartOneclickException.php | 8 +++++ .../Oneclick/StatusOneclickException.php | 2 +- .../TimeoutInscriptionOneclickException.php | 2 +- ...UserCancelInscriptionOneclickException.php | 2 +- ...thoutTokenInscriptionOneclickException.php | 2 +- .../TableNotExistOnDatabaseException.php | 2 +- .../TokenNotFoundOnDatabaseException.php | 2 +- .../Webpay/CommitWebpayException.php | 2 +- .../CreateTransactionWebpayException.php | 2 +- .../Webpay/CreateWebpayException.php | 8 +++++ .../Webpay/DoubleTokenWebpayException.php | 2 +- .../Webpay/GetTransactionWebpayException.php | 2 +- .../Webpay/InvalidStatusWebpayException.php | 2 +- .../NotFoundTransactionWebpayException.php | 2 +- .../Webpay/RefundWebpayException.php | 2 +- .../Webpay/RejectedCommitWebpayException.php | 2 +- .../Webpay/RejectedRefundWebpayException.php | 2 +- .../Webpay/StatusWebpayException.php | 2 +- .../Webpay/TimeoutWebpayException.php | 2 +- .../Webpay/UserCancelWebpayException.php | 2 +- .../Webpay/WithoutTokenWebpayException.php | 2 +- .../OneclickInscriptionResponseController.php | 16 ++++----- plugin/src/Controllers/ResponseController.php | 14 ++++---- .../Oneclick/StartOneclickException.php | 8 ----- .../Webpay/CreateWebpayException.php | 8 ----- plugin/src/Models/Inscription.php | 2 +- plugin/src/Models/Transaction.php | 2 +- plugin/src/OneclickTransbankSdk.php | 36 +++++++++---------- ...C_Gateway_Transbank_Oneclick_Mall_REST.php | 16 ++++----- .../WC_Gateway_Transbank_Webpay_Plus_REST.php | 12 +++---- plugin/src/WebpayplusTransbankSdk.php | 26 +++++++------- 45 files changed, 111 insertions(+), 111 deletions(-) rename plugin/{src => shared}/Exceptions/InvalidOrderException.php (51%) rename plugin/{src => shared}/Exceptions/Oneclick/AuthorizeOneclickException.php (50%) rename plugin/{src => shared}/Exceptions/Oneclick/ConstraintsViolatedAuthorizeOneclickException.php (87%) rename plugin/{src => shared}/Exceptions/Oneclick/CreateTransactionOneclickException.php (53%) rename plugin/{src => shared}/Exceptions/Oneclick/FinishInscriptionOneclickException.php (89%) rename plugin/{src => shared}/Exceptions/Oneclick/GetInscriptionOneclickException.php (51%) rename plugin/{src => shared}/Exceptions/Oneclick/GetTransactionOneclickException.php (84%) rename plugin/{src => shared}/Exceptions/Oneclick/InvalidStatusInscriptionOneclickException.php (89%) rename plugin/{src => shared}/Exceptions/Oneclick/NotFoundTransactionOneclickException.php (85%) rename plugin/{src => shared}/Exceptions/Oneclick/RefundOneclickException.php (91%) rename plugin/{src => shared}/Exceptions/Oneclick/RejectedAuthorizeOneclickException.php (86%) rename plugin/{src => shared}/Exceptions/Oneclick/RejectedInscriptionOneclickException.php (92%) rename plugin/{src => shared}/Exceptions/Oneclick/RejectedRefundOneclickException.php (93%) rename plugin/{src => shared}/Exceptions/Oneclick/StartInscriptionOneclickException.php (52%) create mode 100644 plugin/shared/Exceptions/Oneclick/StartOneclickException.php rename plugin/{src => shared}/Exceptions/Oneclick/StatusOneclickException.php (84%) rename plugin/{src => shared}/Exceptions/Oneclick/TimeoutInscriptionOneclickException.php (89%) rename plugin/{src => shared}/Exceptions/Oneclick/UserCancelInscriptionOneclickException.php (89%) rename plugin/{src => shared}/Exceptions/Oneclick/WithoutTokenInscriptionOneclickException.php (55%) rename plugin/{src => shared}/Exceptions/TableNotExistOnDatabaseException.php (56%) rename plugin/{src => shared}/Exceptions/TokenNotFoundOnDatabaseException.php (56%) rename plugin/{src => shared}/Exceptions/Webpay/CommitWebpayException.php (89%) rename plugin/{src => shared}/Exceptions/Webpay/CreateTransactionWebpayException.php (53%) create mode 100644 plugin/shared/Exceptions/Webpay/CreateWebpayException.php rename plugin/{src => shared}/Exceptions/Webpay/DoubleTokenWebpayException.php (91%) rename plugin/{src => shared}/Exceptions/Webpay/GetTransactionWebpayException.php (85%) rename plugin/{src => shared}/Exceptions/Webpay/InvalidStatusWebpayException.php (89%) rename plugin/{src => shared}/Exceptions/Webpay/NotFoundTransactionWebpayException.php (85%) rename plugin/{src => shared}/Exceptions/Webpay/RefundWebpayException.php (88%) rename plugin/{src => shared}/Exceptions/Webpay/RejectedCommitWebpayException.php (91%) rename plugin/{src => shared}/Exceptions/Webpay/RejectedRefundWebpayException.php (91%) rename plugin/{src => shared}/Exceptions/Webpay/StatusWebpayException.php (84%) rename plugin/{src => shared}/Exceptions/Webpay/TimeoutWebpayException.php (91%) rename plugin/{src => shared}/Exceptions/Webpay/UserCancelWebpayException.php (89%) rename plugin/{src => shared}/Exceptions/Webpay/WithoutTokenWebpayException.php (51%) delete mode 100644 plugin/src/Exceptions/Oneclick/StartOneclickException.php delete mode 100644 plugin/src/Exceptions/Webpay/CreateWebpayException.php diff --git a/plugin/src/Exceptions/InvalidOrderException.php b/plugin/shared/Exceptions/InvalidOrderException.php similarity index 51% rename from plugin/src/Exceptions/InvalidOrderException.php rename to plugin/shared/Exceptions/InvalidOrderException.php index f986d280..4dba745c 100644 --- a/plugin/src/Exceptions/InvalidOrderException.php +++ b/plugin/shared/Exceptions/InvalidOrderException.php @@ -1,6 +1,6 @@ Date: Tue, 31 Oct 2023 12:07:51 -0500 Subject: [PATCH 02/16] feat: add base exception --- plugin/shared/Exceptions/BaseException.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 plugin/shared/Exceptions/BaseException.php diff --git a/plugin/shared/Exceptions/BaseException.php b/plugin/shared/Exceptions/BaseException.php new file mode 100644 index 00000000..a201dc90 --- /dev/null +++ b/plugin/shared/Exceptions/BaseException.php @@ -0,0 +1,12 @@ + Date: Tue, 31 Oct 2023 12:15:47 -0500 Subject: [PATCH 03/16] feat: change base class --- plugin/shared/Exceptions/EcommerceException.php | 8 ++------ plugin/shared/Exceptions/InvalidOrderException.php | 2 +- .../Exceptions/Oneclick/AuthorizeOneclickException.php | 4 +++- .../ConstraintsViolatedAuthorizeOneclickException.php | 8 +++++--- .../Oneclick/CreateTransactionOneclickException.php | 4 +++- .../Oneclick/FinishInscriptionOneclickException.php | 8 +++++--- .../Oneclick/GetInscriptionOneclickException.php | 4 +++- .../Oneclick/GetTransactionOneclickException.php | 8 +++++--- .../InvalidStatusInscriptionOneclickException.php | 8 +++++--- .../Oneclick/NotFoundTransactionOneclickException.php | 8 +++++--- .../Exceptions/Oneclick/RefundOneclickException.php | 8 +++++--- .../Oneclick/RejectedAuthorizeOneclickException.php | 8 +++++--- .../Oneclick/RejectedInscriptionOneclickException.php | 8 +++++--- .../Oneclick/RejectedRefundOneclickException.php | 8 +++++--- .../Oneclick/StartInscriptionOneclickException.php | 4 +++- .../shared/Exceptions/Oneclick/StartOneclickException.php | 4 +++- .../Exceptions/Oneclick/StatusOneclickException.php | 8 +++++--- .../Oneclick/TimeoutInscriptionOneclickException.php | 8 +++++--- .../Oneclick/UserCancelInscriptionOneclickException.php | 8 +++++--- .../Oneclick/WithoutTokenInscriptionOneclickException.php | 4 +++- .../Exceptions/TableNotExistOnDatabaseException.php | 2 +- .../Exceptions/TokenNotFoundOnDatabaseException.php | 2 +- plugin/shared/Exceptions/Webpay/CommitWebpayException.php | 8 +++++--- .../Webpay/CreateTransactionWebpayException.php | 4 +++- plugin/shared/Exceptions/Webpay/CreateWebpayException.php | 4 +++- .../Exceptions/Webpay/DoubleTokenWebpayException.php | 8 +++++--- .../Exceptions/Webpay/GetTransactionWebpayException.php | 8 +++++--- .../Exceptions/Webpay/InvalidStatusWebpayException.php | 8 +++++--- .../Webpay/NotFoundTransactionWebpayException.php | 8 +++++--- plugin/shared/Exceptions/Webpay/RefundWebpayException.php | 8 +++++--- .../Exceptions/Webpay/RejectedCommitWebpayException.php | 8 +++++--- .../Exceptions/Webpay/RejectedRefundWebpayException.php | 8 +++++--- plugin/shared/Exceptions/Webpay/StatusWebpayException.php | 8 +++++--- .../shared/Exceptions/Webpay/TimeoutWebpayException.php | 8 +++++--- .../Exceptions/Webpay/UserCancelWebpayException.php | 8 +++++--- .../Exceptions/Webpay/WithoutTokenWebpayException.php | 4 +++- 36 files changed, 147 insertions(+), 87 deletions(-) diff --git a/plugin/shared/Exceptions/EcommerceException.php b/plugin/shared/Exceptions/EcommerceException.php index 90eb649e..f55f5376 100644 --- a/plugin/shared/Exceptions/EcommerceException.php +++ b/plugin/shared/Exceptions/EcommerceException.php @@ -2,11 +2,7 @@ namespace Transbank\Plugin\Exceptions; -use Transbank\Plugin\Helpers\ExceptionConstants; - -class EcommerceException extends \Exception +class EcommerceException extends BaseException { - public function __construct($message, \Exception $previous = null) { - parent::__construct($message, ExceptionConstants::DEFAULT_CODE, $previous); - } + } diff --git a/plugin/shared/Exceptions/InvalidOrderException.php b/plugin/shared/Exceptions/InvalidOrderException.php index 4dba745c..16afdf04 100644 --- a/plugin/shared/Exceptions/InvalidOrderException.php +++ b/plugin/shared/Exceptions/InvalidOrderException.php @@ -2,6 +2,6 @@ namespace Transbank\Plugin\Exceptions; -class InvalidOrderException extends \Exception +class InvalidOrderException extends BaseException { } diff --git a/plugin/shared/Exceptions/Oneclick/AuthorizeOneclickException.php b/plugin/shared/Exceptions/Oneclick/AuthorizeOneclickException.php index 2b148cef..519ccd6b 100644 --- a/plugin/shared/Exceptions/Oneclick/AuthorizeOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/AuthorizeOneclickException.php @@ -2,7 +2,9 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class AuthorizeOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class AuthorizeOneclickException extends BaseException { } diff --git a/plugin/shared/Exceptions/Oneclick/ConstraintsViolatedAuthorizeOneclickException.php b/plugin/shared/Exceptions/Oneclick/ConstraintsViolatedAuthorizeOneclickException.php index 41dc8df0..eb1b27fc 100644 --- a/plugin/shared/Exceptions/Oneclick/ConstraintsViolatedAuthorizeOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/ConstraintsViolatedAuthorizeOneclickException.php @@ -2,13 +2,15 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class ConstraintsViolatedAuthorizeOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class ConstraintsViolatedAuthorizeOneclickException extends BaseException { private $authorizeResponse; - public function __construct($message, $authorizeResponse, $code = 0, \Exception $previous = null) { + public function __construct($message, $authorizeResponse, \Exception $previous = null) { $this->authorizeResponse = $authorizeResponse; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getAuthorizeResponse() { diff --git a/plugin/shared/Exceptions/Oneclick/CreateTransactionOneclickException.php b/plugin/shared/Exceptions/Oneclick/CreateTransactionOneclickException.php index 11128824..681006f3 100644 --- a/plugin/shared/Exceptions/Oneclick/CreateTransactionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/CreateTransactionOneclickException.php @@ -2,7 +2,9 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class CreateTransactionOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class CreateTransactionOneclickException extends BaseException { } diff --git a/plugin/shared/Exceptions/Oneclick/FinishInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/FinishInscriptionOneclickException.php index 00f7205d..dc0abfdc 100644 --- a/plugin/shared/Exceptions/Oneclick/FinishInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/FinishInscriptionOneclickException.php @@ -2,15 +2,17 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class FinishInscriptionOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class FinishInscriptionOneclickException extends BaseException { private $tbkToken; private $inscription; - public function __construct($message, $tbkToken, $inscription, $code = 0, \Exception $previous = null) { + public function __construct($message, $tbkToken, $inscription, \Exception $previous = null) { $this->tbkToken = $tbkToken; $this->inscription = $inscription; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTbkToken() { diff --git a/plugin/shared/Exceptions/Oneclick/GetInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/GetInscriptionOneclickException.php index 56c58fa5..e6ee0031 100644 --- a/plugin/shared/Exceptions/Oneclick/GetInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/GetInscriptionOneclickException.php @@ -2,6 +2,8 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class GetInscriptionOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class GetInscriptionOneclickException extends BaseException { } diff --git a/plugin/shared/Exceptions/Oneclick/GetTransactionOneclickException.php b/plugin/shared/Exceptions/Oneclick/GetTransactionOneclickException.php index fe3225cc..886a7d4a 100644 --- a/plugin/shared/Exceptions/Oneclick/GetTransactionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/GetTransactionOneclickException.php @@ -2,13 +2,15 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class GetTransactionOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class GetTransactionOneclickException extends BaseException { private $orderId; - public function __construct($message, $orderId, $code = 0, \Exception $previous = null) { + public function __construct($message, $orderId, \Exception $previous = null) { $this->orderId = $orderId; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getOrderId() { diff --git a/plugin/shared/Exceptions/Oneclick/InvalidStatusInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/InvalidStatusInscriptionOneclickException.php index 5ad50fdb..ba703b9e 100644 --- a/plugin/shared/Exceptions/Oneclick/InvalidStatusInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/InvalidStatusInscriptionOneclickException.php @@ -2,15 +2,17 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class InvalidStatusInscriptionOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class InvalidStatusInscriptionOneclickException extends BaseException { private $tbkToken; private $inscription; - public function __construct($message, $tbkToken, $inscription, $code = 0, \Exception $previous = null) { + public function __construct($message, $tbkToken, $inscription, \Exception $previous = null) { $this->tbkToken = $tbkToken; $this->inscription = $inscription; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTbkToken() { diff --git a/plugin/shared/Exceptions/Oneclick/NotFoundTransactionOneclickException.php b/plugin/shared/Exceptions/Oneclick/NotFoundTransactionOneclickException.php index cc4ff851..14e11716 100644 --- a/plugin/shared/Exceptions/Oneclick/NotFoundTransactionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/NotFoundTransactionOneclickException.php @@ -2,13 +2,15 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class NotFoundTransactionOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class NotFoundTransactionOneclickException extends BaseException { private $orderId; - public function __construct($message, $orderId, $code = 0, \Exception $previous = null) { + public function __construct($message, $orderId, \Exception $previous = null) { $this->orderId = $orderId; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getOrderId() { diff --git a/plugin/shared/Exceptions/Oneclick/RefundOneclickException.php b/plugin/shared/Exceptions/Oneclick/RefundOneclickException.php index 68098466..2df12ded 100644 --- a/plugin/shared/Exceptions/Oneclick/RefundOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/RefundOneclickException.php @@ -2,17 +2,19 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class RefundOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class RefundOneclickException extends BaseException { private $buyOrder; private $childBuyOrder; private $transaction; - public function __construct($message, $buyOrder, $childBuyOrder, $transaction, $code = 0, \Exception $previous = null) { + public function __construct($message, $buyOrder, $childBuyOrder, $transaction, \Exception $previous = null) { $this->buyOrder = $buyOrder; $this->childBuyOrder = $childBuyOrder; $this->transaction = $transaction; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getBuyOrder() { diff --git a/plugin/shared/Exceptions/Oneclick/RejectedAuthorizeOneclickException.php b/plugin/shared/Exceptions/Oneclick/RejectedAuthorizeOneclickException.php index abf149f7..2ca5fe59 100644 --- a/plugin/shared/Exceptions/Oneclick/RejectedAuthorizeOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/RejectedAuthorizeOneclickException.php @@ -2,13 +2,15 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class RejectedAuthorizeOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class RejectedAuthorizeOneclickException extends BaseException { private $authorizeResponse; - public function __construct($message, $authorizeResponse, $code = 0, \Exception $previous = null) { + public function __construct($message, $authorizeResponse, \Exception $previous = null) { $this->authorizeResponse = $authorizeResponse; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getAuthorizeResponse() { diff --git a/plugin/shared/Exceptions/Oneclick/RejectedInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/RejectedInscriptionOneclickException.php index 0cf8b5da..40f801f0 100644 --- a/plugin/shared/Exceptions/Oneclick/RejectedInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/RejectedInscriptionOneclickException.php @@ -2,17 +2,19 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class RejectedInscriptionOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class RejectedInscriptionOneclickException extends BaseException { private $tbkToken; private $inscription; private $finishInscriptionResponse; - public function __construct($message, $tbkToken, $inscription, $finishInscriptionResponse, $code = 0, \Exception $previous = null) { + public function __construct($message, $tbkToken, $inscription, $finishInscriptionResponse, \Exception $previous = null) { $this->tbkToken = $tbkToken; $this->inscription = $inscription; $this->finishInscriptionResponse = $finishInscriptionResponse; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTbkToken() { diff --git a/plugin/shared/Exceptions/Oneclick/RejectedRefundOneclickException.php b/plugin/shared/Exceptions/Oneclick/RejectedRefundOneclickException.php index 9f9746f7..10cca0c5 100644 --- a/plugin/shared/Exceptions/Oneclick/RejectedRefundOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/RejectedRefundOneclickException.php @@ -2,19 +2,21 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class RejectedRefundOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class RejectedRefundOneclickException extends BaseException { private $buyOrder; private $childBuyOrder; private $transaction; private $refundResponse; - public function __construct($message, $buyOrder, $childBuyOrder, $transaction, $refundResponse, $code = 0, \Exception $previous = null) { + public function __construct($message, $buyOrder, $childBuyOrder, $transaction, $refundResponse, \Exception $previous = null) { $this->buyOrder = $buyOrder; $this->childBuyOrder = $childBuyOrder; $this->transaction = $transaction; $this->refundResponse = $refundResponse; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getBuyOrder() { diff --git a/plugin/shared/Exceptions/Oneclick/StartInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/StartInscriptionOneclickException.php index 3a6bb248..7603bd3a 100644 --- a/plugin/shared/Exceptions/Oneclick/StartInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/StartInscriptionOneclickException.php @@ -2,7 +2,9 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class StartInscriptionOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class StartInscriptionOneclickException extends BaseException { } diff --git a/plugin/shared/Exceptions/Oneclick/StartOneclickException.php b/plugin/shared/Exceptions/Oneclick/StartOneclickException.php index 731479e8..c03c7c7e 100644 --- a/plugin/shared/Exceptions/Oneclick/StartOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/StartOneclickException.php @@ -2,7 +2,9 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class StartOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class StartOneclickException extends BaseException { } diff --git a/plugin/shared/Exceptions/Oneclick/StatusOneclickException.php b/plugin/shared/Exceptions/Oneclick/StatusOneclickException.php index 009a2657..cad927ce 100644 --- a/plugin/shared/Exceptions/Oneclick/StatusOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/StatusOneclickException.php @@ -2,13 +2,15 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class StatusOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class StatusOneclickException extends BaseException { private $buyOrder; - public function __construct($message, $buyOrder, $code = 0, \Exception $previous = null) { + public function __construct($message, $buyOrder, \Exception $previous = null) { $this->buyOrder = $buyOrder; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getBuyOrder() { diff --git a/plugin/shared/Exceptions/Oneclick/TimeoutInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/TimeoutInscriptionOneclickException.php index cfd69e39..74cd8528 100644 --- a/plugin/shared/Exceptions/Oneclick/TimeoutInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/TimeoutInscriptionOneclickException.php @@ -2,15 +2,17 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class TimeoutInscriptionOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class TimeoutInscriptionOneclickException extends BaseException { private $tbkToken; private $inscription; - public function __construct($message, $tbkToken, $inscription, $code = 0, \Exception $previous = null) { + public function __construct($message, $tbkToken, $inscription, \Exception $previous = null) { $this->tbkToken = $tbkToken; $this->inscription = $inscription; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTbkToken() { diff --git a/plugin/shared/Exceptions/Oneclick/UserCancelInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/UserCancelInscriptionOneclickException.php index e5771ef4..230bdf23 100644 --- a/plugin/shared/Exceptions/Oneclick/UserCancelInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/UserCancelInscriptionOneclickException.php @@ -2,15 +2,17 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class UserCancelInscriptionOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class UserCancelInscriptionOneclickException extends BaseException { private $tbkToken; private $inscription; - public function __construct($message, $tbkToken, $inscription, $code = 0, \Exception $previous = null) { + public function __construct($message, $tbkToken, $inscription, \Exception $previous = null) { $this->tbkToken = $tbkToken; $this->inscription = $inscription; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTbkToken() { diff --git a/plugin/shared/Exceptions/Oneclick/WithoutTokenInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/WithoutTokenInscriptionOneclickException.php index bdb41f4e..95545ddd 100644 --- a/plugin/shared/Exceptions/Oneclick/WithoutTokenInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/WithoutTokenInscriptionOneclickException.php @@ -2,7 +2,9 @@ namespace Transbank\Plugin\Exceptions\Oneclick; -class WithoutTokenInscriptionOneclickException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class WithoutTokenInscriptionOneclickException extends BaseException { } diff --git a/plugin/shared/Exceptions/TableNotExistOnDatabaseException.php b/plugin/shared/Exceptions/TableNotExistOnDatabaseException.php index 725d88f3..b711d8c1 100644 --- a/plugin/shared/Exceptions/TableNotExistOnDatabaseException.php +++ b/plugin/shared/Exceptions/TableNotExistOnDatabaseException.php @@ -2,6 +2,6 @@ namespace Transbank\Plugin\Exceptions; -class TableNotExistOnDatabaseException extends \Exception +class TableNotExistOnDatabaseException extends BaseException { } diff --git a/plugin/shared/Exceptions/TokenNotFoundOnDatabaseException.php b/plugin/shared/Exceptions/TokenNotFoundOnDatabaseException.php index 2006ad64..b48bb40d 100644 --- a/plugin/shared/Exceptions/TokenNotFoundOnDatabaseException.php +++ b/plugin/shared/Exceptions/TokenNotFoundOnDatabaseException.php @@ -2,6 +2,6 @@ namespace Transbank\Plugin\Exceptions; -class TokenNotFoundOnDatabaseException extends \Exception +class TokenNotFoundOnDatabaseException extends BaseException { } diff --git a/plugin/shared/Exceptions/Webpay/CommitWebpayException.php b/plugin/shared/Exceptions/Webpay/CommitWebpayException.php index 8ef63fd3..eef9a5ae 100644 --- a/plugin/shared/Exceptions/Webpay/CommitWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/CommitWebpayException.php @@ -2,15 +2,17 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class CommitWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class CommitWebpayException extends BaseException { private $tbkToken; private $transaction; - public function __construct($message, $tbkToken, $transaction, $code = 0, \Exception $previous = null) { + public function __construct($message, $tbkToken, $transaction, \Exception $previous = null) { $this->tbkToken = $tbkToken; $this->transaction = $transaction; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTbkToken() { diff --git a/plugin/shared/Exceptions/Webpay/CreateTransactionWebpayException.php b/plugin/shared/Exceptions/Webpay/CreateTransactionWebpayException.php index 3b1de50f..5699eb23 100644 --- a/plugin/shared/Exceptions/Webpay/CreateTransactionWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/CreateTransactionWebpayException.php @@ -2,7 +2,9 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class CreateTransactionWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class CreateTransactionWebpayException extends BaseException { } diff --git a/plugin/shared/Exceptions/Webpay/CreateWebpayException.php b/plugin/shared/Exceptions/Webpay/CreateWebpayException.php index 1aa7aeec..b52945ee 100644 --- a/plugin/shared/Exceptions/Webpay/CreateWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/CreateWebpayException.php @@ -2,7 +2,9 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class CreateWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class CreateWebpayException extends BaseException { } diff --git a/plugin/shared/Exceptions/Webpay/DoubleTokenWebpayException.php b/plugin/shared/Exceptions/Webpay/DoubleTokenWebpayException.php index 6fb3c12a..573bd6db 100644 --- a/plugin/shared/Exceptions/Webpay/DoubleTokenWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/DoubleTokenWebpayException.php @@ -2,17 +2,19 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class DoubleTokenWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class DoubleTokenWebpayException extends BaseException { private $tbkToken1; private $tbkToken2; private $transaction; - public function __construct($message, $tbkToken1, $tbkToken2, $transaction, $code = 0, \Exception $previous = null) { + public function __construct($message, $tbkToken1, $tbkToken2, $transaction, \Exception $previous = null) { $this->tbkToken1 = $tbkToken1; $this->tbkToken2 = $tbkToken2; $this->transaction = $transaction; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTbkToken1() { diff --git a/plugin/shared/Exceptions/Webpay/GetTransactionWebpayException.php b/plugin/shared/Exceptions/Webpay/GetTransactionWebpayException.php index 75c298d5..4b0ca679 100644 --- a/plugin/shared/Exceptions/Webpay/GetTransactionWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/GetTransactionWebpayException.php @@ -2,13 +2,15 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class GetTransactionWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class GetTransactionWebpayException extends BaseException { private $orderId; - public function __construct($message, $orderId, $code = 0, \Exception $previous = null) { + public function __construct($message, $orderId, \Exception $previous = null) { $this->orderId = $orderId; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getOrderId() { diff --git a/plugin/shared/Exceptions/Webpay/InvalidStatusWebpayException.php b/plugin/shared/Exceptions/Webpay/InvalidStatusWebpayException.php index 08d104d9..3225fc6c 100644 --- a/plugin/shared/Exceptions/Webpay/InvalidStatusWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/InvalidStatusWebpayException.php @@ -2,15 +2,17 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class InvalidStatusWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class InvalidStatusWebpayException extends BaseException { private $tokenWs; private $transaction; - public function __construct($message, $tokenWs, $transaction, $code = 0, \Exception $previous = null) { + public function __construct($message, $tokenWs, $transaction, \Exception $previous = null) { $this->tokenWs = $tokenWs; $this->transaction = $transaction; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTokenWs() { diff --git a/plugin/shared/Exceptions/Webpay/NotFoundTransactionWebpayException.php b/plugin/shared/Exceptions/Webpay/NotFoundTransactionWebpayException.php index 1fe0d79f..2b668cd3 100644 --- a/plugin/shared/Exceptions/Webpay/NotFoundTransactionWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/NotFoundTransactionWebpayException.php @@ -2,13 +2,15 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class NotFoundTransactionWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class NotFoundTransactionWebpayException extends BaseException { private $orderId; - public function __construct($message, $orderId, $code = 0, \Exception $previous = null) { + public function __construct($message, $orderId, \Exception $previous = null) { $this->orderId = $orderId; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getOrderId() { diff --git a/plugin/shared/Exceptions/Webpay/RefundWebpayException.php b/plugin/shared/Exceptions/Webpay/RefundWebpayException.php index b8255114..05dbb40d 100644 --- a/plugin/shared/Exceptions/Webpay/RefundWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/RefundWebpayException.php @@ -2,15 +2,17 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class RefundWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class RefundWebpayException extends BaseException { private $token; private $transaction; - public function __construct($message, $token, $transaction, $code = 0, \Exception $previous = null) { + public function __construct($message, $token, $transaction, \Exception $previous = null) { $this->token = $token; $this->transaction = $transaction; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getToken() { diff --git a/plugin/shared/Exceptions/Webpay/RejectedCommitWebpayException.php b/plugin/shared/Exceptions/Webpay/RejectedCommitWebpayException.php index 97c0e882..6718eccb 100644 --- a/plugin/shared/Exceptions/Webpay/RejectedCommitWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/RejectedCommitWebpayException.php @@ -2,17 +2,19 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class RejectedCommitWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class RejectedCommitWebpayException extends BaseException { private $tokenWs; private $transaction; private $commitResponse; - public function __construct($message, $tokenWs, $transaction, $commitResponse, $code = 0, \Exception $previous = null) { + public function __construct($message, $tokenWs, $transaction, $commitResponse, \Exception $previous = null) { $this->tokenWs = $tokenWs; $this->transaction = $transaction; $this->commitResponse = $commitResponse; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTokenWs() { diff --git a/plugin/shared/Exceptions/Webpay/RejectedRefundWebpayException.php b/plugin/shared/Exceptions/Webpay/RejectedRefundWebpayException.php index fd4e10c8..0293a28c 100644 --- a/plugin/shared/Exceptions/Webpay/RejectedRefundWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/RejectedRefundWebpayException.php @@ -2,17 +2,19 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class RejectedRefundWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class RejectedRefundWebpayException extends BaseException { private $token; private $transaction; private $refundResponse; - public function __construct($message, $token, $transaction, $refundResponse, $code = 0, \Exception $previous = null) { + public function __construct($message, $token, $transaction, $refundResponse, \Exception $previous = null) { $this->token = $token; $this->transaction = $transaction; $this->refundResponse = $refundResponse; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getToken() { diff --git a/plugin/shared/Exceptions/Webpay/StatusWebpayException.php b/plugin/shared/Exceptions/Webpay/StatusWebpayException.php index 821fd380..54bd7a52 100644 --- a/plugin/shared/Exceptions/Webpay/StatusWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/StatusWebpayException.php @@ -2,13 +2,15 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class StatusWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class StatusWebpayException extends BaseException { private $token; - public function __construct($message, $token, $code = 0, \Exception $previous = null) { + public function __construct($message, $token, \Exception $previous = null) { $this->token = $token; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getToken() { diff --git a/plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php b/plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php index bb6d9b57..803700ae 100644 --- a/plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php @@ -2,17 +2,19 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class TimeoutWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class TimeoutWebpayException extends BaseException { private $buyOrder; private $sessionId; private $transaction; - public function __construct($message, $buyOrder, $sessionId, $transaction, $code = 0, \Exception $previous = null) { + public function __construct($message, $buyOrder, $sessionId, $transaction, \Exception $previous = null) { $this->buyOrder = $buyOrder; $this->sessionId = $sessionId; $this->transaction = $transaction; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getBuyOrder() { diff --git a/plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php b/plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php index e4d21d26..d7172543 100644 --- a/plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php @@ -2,15 +2,17 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class UserCancelWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class UserCancelWebpayException extends BaseException { private $tbkToken; private $transaction; - public function __construct($message, $tbkToken, $transaction, $code = 0, \Exception $previous = null) { + public function __construct($message, $tbkToken, $transaction, \Exception $previous = null) { $this->tbkToken = $tbkToken; $this->transaction = $transaction; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTbkToken() { diff --git a/plugin/shared/Exceptions/Webpay/WithoutTokenWebpayException.php b/plugin/shared/Exceptions/Webpay/WithoutTokenWebpayException.php index 591a1b85..3314c615 100644 --- a/plugin/shared/Exceptions/Webpay/WithoutTokenWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/WithoutTokenWebpayException.php @@ -2,7 +2,9 @@ namespace Transbank\Plugin\Exceptions\Webpay; -class WithoutTokenWebpayException extends \Exception +use Transbank\Plugin\Exceptions\BaseException; + +class WithoutTokenWebpayException extends BaseException { } From 4336cc2ddba79b243af743b6314df82fedb3a71b Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 12:19:21 -0500 Subject: [PATCH 04/16] syle: break lines --- plugin/shared/Exceptions/Oneclick/RefundOneclickException.php | 3 ++- .../Oneclick/RejectedInscriptionOneclickException.php | 3 ++- .../Exceptions/Oneclick/RejectedRefundOneclickException.php | 3 ++- plugin/shared/Exceptions/Webpay/DoubleTokenWebpayException.php | 3 ++- .../shared/Exceptions/Webpay/RejectedCommitWebpayException.php | 3 ++- .../shared/Exceptions/Webpay/RejectedRefundWebpayException.php | 3 ++- plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php | 3 ++- plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php | 3 ++- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/plugin/shared/Exceptions/Oneclick/RefundOneclickException.php b/plugin/shared/Exceptions/Oneclick/RefundOneclickException.php index 2df12ded..140ef813 100644 --- a/plugin/shared/Exceptions/Oneclick/RefundOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/RefundOneclickException.php @@ -10,7 +10,8 @@ class RefundOneclickException extends BaseException private $childBuyOrder; private $transaction; - public function __construct($message, $buyOrder, $childBuyOrder, $transaction, \Exception $previous = null) { + public function __construct($message, $buyOrder, $childBuyOrder, $transaction, + \Exception $previous = null) { $this->buyOrder = $buyOrder; $this->childBuyOrder = $childBuyOrder; $this->transaction = $transaction; diff --git a/plugin/shared/Exceptions/Oneclick/RejectedInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/RejectedInscriptionOneclickException.php index 40f801f0..69de148c 100644 --- a/plugin/shared/Exceptions/Oneclick/RejectedInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/RejectedInscriptionOneclickException.php @@ -10,7 +10,8 @@ class RejectedInscriptionOneclickException extends BaseException private $inscription; private $finishInscriptionResponse; - public function __construct($message, $tbkToken, $inscription, $finishInscriptionResponse, \Exception $previous = null) { + public function __construct($message, $tbkToken, $inscription, $finishInscriptionResponse, + \Exception $previous = null) { $this->tbkToken = $tbkToken; $this->inscription = $inscription; $this->finishInscriptionResponse = $finishInscriptionResponse; diff --git a/plugin/shared/Exceptions/Oneclick/RejectedRefundOneclickException.php b/plugin/shared/Exceptions/Oneclick/RejectedRefundOneclickException.php index 10cca0c5..ea52a91a 100644 --- a/plugin/shared/Exceptions/Oneclick/RejectedRefundOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/RejectedRefundOneclickException.php @@ -11,7 +11,8 @@ class RejectedRefundOneclickException extends BaseException private $transaction; private $refundResponse; - public function __construct($message, $buyOrder, $childBuyOrder, $transaction, $refundResponse, \Exception $previous = null) { + public function __construct($message, $buyOrder, $childBuyOrder, $transaction, $refundResponse, + \Exception $previous = null) { $this->buyOrder = $buyOrder; $this->childBuyOrder = $childBuyOrder; $this->transaction = $transaction; diff --git a/plugin/shared/Exceptions/Webpay/DoubleTokenWebpayException.php b/plugin/shared/Exceptions/Webpay/DoubleTokenWebpayException.php index 573bd6db..d01cf572 100644 --- a/plugin/shared/Exceptions/Webpay/DoubleTokenWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/DoubleTokenWebpayException.php @@ -10,7 +10,8 @@ class DoubleTokenWebpayException extends BaseException private $tbkToken2; private $transaction; - public function __construct($message, $tbkToken1, $tbkToken2, $transaction, \Exception $previous = null) { + public function __construct($message, $tbkToken1, $tbkToken2, $transaction, + \Exception $previous = null) { $this->tbkToken1 = $tbkToken1; $this->tbkToken2 = $tbkToken2; $this->transaction = $transaction; diff --git a/plugin/shared/Exceptions/Webpay/RejectedCommitWebpayException.php b/plugin/shared/Exceptions/Webpay/RejectedCommitWebpayException.php index 6718eccb..6de702c8 100644 --- a/plugin/shared/Exceptions/Webpay/RejectedCommitWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/RejectedCommitWebpayException.php @@ -10,7 +10,8 @@ class RejectedCommitWebpayException extends BaseException private $transaction; private $commitResponse; - public function __construct($message, $tokenWs, $transaction, $commitResponse, \Exception $previous = null) { + public function __construct($message, $tokenWs, $transaction, $commitResponse, + \Exception $previous = null) { $this->tokenWs = $tokenWs; $this->transaction = $transaction; $this->commitResponse = $commitResponse; diff --git a/plugin/shared/Exceptions/Webpay/RejectedRefundWebpayException.php b/plugin/shared/Exceptions/Webpay/RejectedRefundWebpayException.php index 0293a28c..d5a99ba6 100644 --- a/plugin/shared/Exceptions/Webpay/RejectedRefundWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/RejectedRefundWebpayException.php @@ -10,7 +10,8 @@ class RejectedRefundWebpayException extends BaseException private $transaction; private $refundResponse; - public function __construct($message, $token, $transaction, $refundResponse, \Exception $previous = null) { + public function __construct($message, $token, $transaction, $refundResponse, + \Exception $previous = null) { $this->token = $token; $this->transaction = $transaction; $this->refundResponse = $refundResponse; diff --git a/plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php b/plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php index 803700ae..b6453b00 100644 --- a/plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php @@ -10,7 +10,8 @@ class TimeoutWebpayException extends BaseException private $sessionId; private $transaction; - public function __construct($message, $buyOrder, $sessionId, $transaction, \Exception $previous = null) { + public function __construct($message, $buyOrder, $sessionId, $transaction, + \Exception $previous = null) { $this->buyOrder = $buyOrder; $this->sessionId = $sessionId; $this->transaction = $transaction; diff --git a/plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php b/plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php index d7172543..90630469 100644 --- a/plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php @@ -9,7 +9,8 @@ class UserCancelWebpayException extends BaseException private $tbkToken; private $transaction; - public function __construct($message, $tbkToken, $transaction, \Exception $previous = null) { + public function __construct($message, $tbkToken, $transaction, + \Exception $previous = null) { $this->tbkToken = $tbkToken; $this->transaction = $transaction; parent::__construct($message, $previous); From c3c81f2196b43449439a94b0470ecc9a73211309 Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 12:35:29 -0500 Subject: [PATCH 05/16] refactor: delete unused file --- plugin/src/TransbankSdkWebpayRest.php | 150 -------------------------- 1 file changed, 150 deletions(-) delete mode 100644 plugin/src/TransbankSdkWebpayRest.php diff --git a/plugin/src/TransbankSdkWebpayRest.php b/plugin/src/TransbankSdkWebpayRest.php deleted file mode 100644 index cbec5536..00000000 --- a/plugin/src/TransbankSdkWebpayRest.php +++ /dev/null @@ -1,150 +0,0 @@ -log = TbkFactory::createLogger(); - if (!isset($config)) { - $configProvider = new ConfigProvider(); - $config = [ - 'MODO' => $configProvider->getConfig('webpay_rest_environment'), - 'COMMERCE_CODE' => $configProvider->getConfig('webpay_rest_commerce_code'), - 'API_KEY' => $configProvider->getConfig('webpay_rest_api_key'), - ]; - } - $environment = isset($config['MODO']) ? $config['MODO'] : 'TEST'; - - $options = Transaction::getDefaultOptions(); - if ($environment !== 'TEST') { - $options = Options::forProduction($config['COMMERCE_CODE'], $config['API_KEY']); - } - - $this->transaction = new Transaction($options); - $this->interactsWithFullLog = new InteractsWithFullLog(); - } - - /** - * @param $amount - * @param $sessionId - * @param $buyOrder - * @param $returnUrl - * - * @throws Exception - * - * @return array - */ - public function createTransaction($amount, $sessionId, $buyOrder, $returnUrl) - { - $result = []; - - try { - $this->interactsWithFullLog->logWebpayPlusIniciando(); - - $txDate = date('d-m-Y'); - $txTime = date('H:i:s'); - $this->log->logInfo('initTransaction - amount: '.$amount.', sessionId: '.$sessionId. - ', buyOrder: '.$buyOrder.', txDate: '.$txDate.', txTime: '.$txTime); - - $this->interactsWithFullLog->logWebpayPlusAntesCrearTx($amount, $sessionId, $buyOrder, $returnUrl); // Logs - $initResult = $this->transaction->create($buyOrder, $sessionId, $amount, $returnUrl); - - $this->log->logInfo('createTransaction - initResult: '.json_encode($initResult)); - $this->interactsWithFullLog->logWebpayPlusDespuesCrearTx($initResult); // Logs - if (isset($initResult) && isset($initResult->url) && isset($initResult->token)) { - $result = [ - 'url' => $initResult->url, - 'token_ws' => $initResult->token, - ]; - } else { - $this->interactsWithFullLog->logWebpayPlusDespuesCrearTxError($initResult); // Logs - throw new Exception('No se ha creado la transacción para, amount: '.$amount.', sessionId: '.$sessionId.', buyOrder: '.$buyOrder); - } - } catch (Exception $e) { - $result = [ - 'error' => 'Error al crear la transacción', - 'detail' => $e->getMessage(), - ]; - $this->log->logError(json_encode($result)); - } - - return $result; - } - - /** - * @param $tokenWs - * - * @throws \GuzzleHttp\Exception\GuzzleException - * @throws Exception - * - * @return array|WebpayPlus\TransactionCommitResponse - */ - public function commitTransaction($tokenWs) - { - try { - $this->log->logInfo('getTransactionResult - tokenWs: '.$tokenWs); - if ($tokenWs == null) { - throw new Exception('El token webpay es requerido'); - } - - return $this->transaction->commit($tokenWs); - } catch (TransactionCommitException $e) { - $result = [ - 'error' => 'Error al confirmar la transacción', - 'detail' => $e->getMessage(), - ]; - $this->log->logError(json_encode($result)); - } - - return $result; - } - - public function refund($token, $amount) - { - return $this->transaction->refund($token, $amount); - } - - public function status($token) - { - return $this->transaction->status($token); - } - - /** - * @return Transaction|null - */ - public function getTransaction(): Transaction - { - return $this->transaction; - } -} From d2d16ba879c3c62d1e45e261844594596ca25a5b Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 12:38:45 -0500 Subject: [PATCH 06/16] feat: pass original exception --- plugin/src/OneclickTransbankSdk.php | 14 +++++++------- plugin/src/WebpayplusTransbankSdk.php | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/plugin/src/OneclickTransbankSdk.php b/plugin/src/OneclickTransbankSdk.php index f2dde475..a2a5e9af 100644 --- a/plugin/src/OneclickTransbankSdk.php +++ b/plugin/src/OneclickTransbankSdk.php @@ -116,7 +116,7 @@ public function status($orderId, $buyOrder) } catch (Exception $e) { $errorMessage = 'Ocurrió un error al tratar de obtener el status ( buyOrder: '.$buyOrder.') de la transacción Oneclick en Transbank: '.$e->getMessage(); $this->errorExecutionTbkApi($orderId, 'status', $params, 'StatusOneclickException', $e->getMessage(), $errorMessage); - throw new StatusOneclickException($errorMessage, $buyOrder); + throw new StatusOneclickException($errorMessage, $buyOrder, $e); } } @@ -135,7 +135,7 @@ public function startInner($orderId, $username, $email, $returnUrl) } catch (Exception $e) { $errorMessage = 'Ocurrió un error al tratar iniciar la inscripcion: '.$e->getMessage(); $this->errorExecutionTbkApi($orderId, 'start', $params, 'StartOneclickException', $e->getMessage(), $errorMessage); - throw new StartOneclickException($errorMessage); + throw new StartOneclickException($errorMessage, $e); } } @@ -254,7 +254,7 @@ public function getInscriptionByToken($tbkToken) } catch (Exception $e) { $error = 'Ocurrió un error al obtener la inscripción: '.$e->getMessage(); $this->logError($error); - throw new GetInscriptionOneclickException($error); + throw new GetInscriptionOneclickException($error, $e); } } @@ -277,7 +277,7 @@ public function finishInscription($orderId, $tbkToken, $inscription) $errorMessage = 'Ocurrió un error al ejecutar la inscripción: '.$e->getMessage(); $this->errorExecutionTbkApi($orderId, 'finish', $params, 'FinishInscriptionOneclickException', $e->getMessage(), $errorMessage); $ins = $this->saveInscriptionWithError($tbkToken, $errorMessage); - throw new FinishInscriptionOneclickException($errorMessage, $tbkToken, $ins); + throw new FinishInscriptionOneclickException($errorMessage, $tbkToken, $ins, $e); } } @@ -327,7 +327,7 @@ public function authorizeInner($orderId, $parentBuyOrder, $childBuyOrder, $amoun $errorMessage = 'Ocurrió un error al ejecutar la autorización: '.$e->getMessage(); $this->errorExecutionTbkApi($orderId, 'authorize', $params, 'AuthorizeOneclickException', $e->getMessage(), $errorMessage); $this->saveTransactionWithError($txId, 'AuthorizeOneclickException', $errorMessage); - throw new AuthorizeOneclickException($e->getMessage()); + throw new AuthorizeOneclickException($e->getMessage(), $e); } } @@ -429,7 +429,7 @@ public function getTransactionApprovedByOrderId($orderId) } catch (Exception $e) { $errorMessage = 'Ocurrió un error al tratar de obtener la transacción aprobada ("orderId": "'.$orderId.'") desde la base de datos. Error: '.$e->getMessage(); $this->logError($errorMessage); - throw new GetTransactionOneclickException($errorMessage, $orderId); + throw new GetTransactionOneclickException($errorMessage, $orderId, $e); } } @@ -448,7 +448,7 @@ public function refundInner($orderId, $buyOrder, $childCommerceCode, $childBuyOr } catch (Exception $e) { $errorMessage = 'Ocurrió un error al ejecutar el refund de la transacción en Webpay ("buyOrder": "'.$buyOrder.'", "childBuyOrder": "'.$childBuyOrder.'", "amount": "'.$amount.'"). Error: '.$e->getMessage(); $this->errorExecutionTbkApi($orderId, 'refund', $params, 'RefundOneclickException', $e->getMessage(), $errorMessage); - throw new RefundOneclickException($errorMessage, $buyOrder, $childBuyOrder, $transaction); + throw new RefundOneclickException($errorMessage, $buyOrder, $childBuyOrder, $transaction, $e); } } diff --git a/plugin/src/WebpayplusTransbankSdk.php b/plugin/src/WebpayplusTransbankSdk.php index e3fbda00..2b598bb7 100644 --- a/plugin/src/WebpayplusTransbankSdk.php +++ b/plugin/src/WebpayplusTransbankSdk.php @@ -97,15 +97,15 @@ public function status($orderId, $token) if (ErrorUtil::isApiMismatchError($e)) { $errorMessage = 'Esta utilizando una version de api distinta a la utilizada para crear la transacción'; $this->errorExecutionTbkApi($orderId, 'status', $params, 'StatusWebpayException', $e->getMessage(), $errorMessage); - throw new StatusWebpayException($errorMessage, $token); + throw new StatusWebpayException($errorMessage, $token, $e); } elseif (ErrorUtil::isMaxTimeError($e)) { $errorMessage = 'Ya pasaron mas de 7 dias desde la creacion de la transacción, ya no es posible consultarla por este medio'; $this->errorExecutionTbkApi($orderId, 'status', $params, 'StatusWebpayException', $e->getMessage(), $errorMessage); - throw new StatusWebpayException($errorMessage, $token); + throw new StatusWebpayException($errorMessage, $token, $e); } $errorMessage = 'Ocurrió un error al tratar de obtener el status ( token: '.$token.') de la transacción Webpay en Transbank: '.$e->getMessage(); $this->errorExecutionTbkApi($orderId, 'status', $params, 'StatusWebpayException', $e->getMessage(), $errorMessage); - throw new StatusWebpayException($errorMessage, $token); + throw new StatusWebpayException($errorMessage, $token, $e); } } @@ -125,7 +125,7 @@ public function createInner($orderId, $buyOrder, $sessionId, $amount, $returnUrl } catch (Exception $e) { $errorMessage = 'Ocurrió un error al tratar de crear la transacción en Transbank: '.$e->getMessage(); $this->errorExecutionTbkApi($orderId, 'create', $params, 'CreateWebpayException', $e->getMessage(), $errorMessage); - throw new CreateWebpayException($errorMessage); + throw new CreateWebpayException($errorMessage, $e); } } @@ -202,7 +202,7 @@ public function getTransactionApprovedByOrderId($orderId) } catch (Exception $e) { $errorMessage = 'Ocurrió un error al tratar de obtener la transacción aprobada para la "orden": "'.$orderId.'" desde la base de datos. Error: '.$e->getMessage(); $this->errorExecution($orderId, 'create', [], 'GetTransactionWebpayException', $e->getMessage(), $errorMessage); - throw new GetTransactionWebpayException($errorMessage, $orderId); + throw new GetTransactionWebpayException($errorMessage, $orderId, $e); } } @@ -219,7 +219,7 @@ public function refundInner($orderId, $token, $amount, $tx) } catch (Exception $e) { $errorMessage = 'Ocurrió un error al ejecutar el refund de la transacción en Webpay con el "token": "'.$token.'" y "monto": "'.$amount.'". Error: '.$e->getMessage(); $this->errorExecutionTbkApi($orderId, 'refund', $params, 'RefundWebpayException', $e->getMessage(), $errorMessage); - throw new RefundWebpayException($errorMessage, $token, $tx); + throw new RefundWebpayException($errorMessage, $token, $tx, $e); } } @@ -338,7 +338,7 @@ public function commitInner($orderId, $token, $transaction) $errorMessage = 'Ocurrió un error al ejecutar el commit de la transacción: '.$e->getMessage(); $this->errorExecutionTbkApi($orderId, 'commit', $params, 'CommitWebpayException', $e->getMessage(), $errorMessage); $this->saveTransactionWithErrorByTransaction($transaction, 'CommitWebpayException', $errorMessage); - throw new CommitWebpayException($errorMessage, $token, $transaction); + throw new CommitWebpayException($errorMessage, $token, $transaction, $e); } } From 5fda9ee6d769bb5681526ac242a5cc628bf5d3a9 Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 12:42:56 -0500 Subject: [PATCH 07/16] refactor: replace Exception by EcommerceException --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 15 ++++++++------- .../WC_Gateway_Transbank_Webpay_Plus_REST.php | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 4e616cd9..09056524 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -3,6 +3,7 @@ namespace Transbank\WooCommerce\WebpayRest\PaymentGateways; use Exception; +use Transbank\Plugin\Exceptions\EcommerceException; use Transbank\WooCommerce\WebpayRest\Helpers\TbkFactory; use Transbank\Webpay\Oneclick; use Transbank\Webpay\Options; @@ -127,25 +128,25 @@ public function process_refund($order_id, $amount = null, $reason = '') $errorMessage = 'Se intentó anular transacción, pero hubo un problema obteniendolo de la base de datos de transacciones de webpay plus. '; $order->add_order_note($errorMessage); do_action('transbank_oneclick_refund_failed', $order, null); - throw new Exception($errorMessage); + throw new EcommerceException($errorMessage, $e); } catch (NotFoundTransactionOneclickException $e) { $errorMessage = 'Se intentó anular transacción, pero no se encontró en la base de datos de transacciones de webpay plus. '; $order->add_order_note($errorMessage); do_action('transbank_oneclick_refund_failed', $order, null); - throw new Exception($errorMessage); + throw new EcommerceException($errorMessage, $e); } catch (RefundOneclickException $e) { $order->add_order_note('Error al anular:
'.$e->getMessage()); do_action('transbank_oneclick_refund_failed', $order, $e->getTransaction(), $e->getMessage()); - throw new Exception('Error al anular: '.$e->getMessage()); + throw new EcommerceException('Error al anular: '.$e->getMessage(), $e); }catch (RejectedRefundOneclickException $e) { $errorMessage = 'Anulación a través de Webpay FALLIDA. '."\n\n".json_encode($e->getRefundResponse(), JSON_PRETTY_PRINT); $order->add_order_note($errorMessage); do_action('transbank_oneclick_refund_failed', $order, $e->getTransaction()); - throw new Exception($errorMessage); + throw new EcommerceException($errorMessage, $e); } catch (Exception $e) { $order->add_order_note('Anulación a través de Webpay FALLIDA. '.$e->getMessage()); do_action('transbank_oneclick_refund_failed', $order, null); - throw new Exception('Anulación a través de Webpay fallida.'); + throw new EcommerceException('Anulación a través de Webpay fallida.', $e); } } @@ -197,14 +198,14 @@ public function scheduled_subscription_payment($amount_to_charge, WC_Order $rene if (!$customerId) { $this->logger->logError('There is no costumer id on the renewal order'); - throw new Exception('There is no costumer id on the renewal order'); + throw new EcommerceException('There is no costumer id on the renewal order'); } /** @var WC_Payment_Token_Oneclick $paymentToken */ $paymentToken = WC_Payment_Tokens::get_customer_default_token($customerId); $response = $this->authorizeTransaction($renewalOrder, $paymentToken, $amount_to_charge); if ($response['result'] == 'error'){ - throw new Exception('Se produjo un error en la autorización'); + throw new EcommerceException('Se produjo un error en la autorización'); } $this->setAfterPaymentOrderStatus($renewalOrder); } diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php index 8806a0a1..183bb00a 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php @@ -3,6 +3,7 @@ namespace Transbank\WooCommerce\WebpayRest\PaymentGateways; use Exception; +use Transbank\Plugin\Exceptions\EcommerceException; use Transbank\WooCommerce\WebpayRest\Helpers\TbkFactory; use Transbank\Webpay\WebpayPlus; use Transbank\WooCommerce\WebpayRest\Controllers\ResponseController; @@ -128,7 +129,7 @@ private function processRefundError($order, $exception, $action, $tx, $response) } $order->add_order_note($messageError); do_action($action, $order, $tx, $exception->getMessage()); - throw new Exception($messageError); + throw new EcommerceException($messageError); } /** From e51d5f8e32586e03356003644defcdd0ab9ccd03 Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 12:53:59 -0500 Subject: [PATCH 08/16] fix: change way of obtaining Oneclick credentials --- .../OneclickInscriptionResponseController.php | 2 +- .../src/Controllers/TransactionStatusController.php | 2 +- plugin/src/OneclickTransbankSdk.php | 13 ++++++++++--- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/plugin/src/Controllers/OneclickInscriptionResponseController.php b/plugin/src/Controllers/OneclickInscriptionResponseController.php index e77058f3..1694747b 100644 --- a/plugin/src/Controllers/OneclickInscriptionResponseController.php +++ b/plugin/src/Controllers/OneclickInscriptionResponseController.php @@ -31,7 +31,7 @@ public function __construct($gatewayId) { $this->logger = TbkFactory::createLogger(); $this->gatewayId = $gatewayId; - $this->oneclickTransbankSdk = new OneclickTransbankSdk(get_option('environment'), get_option('commerce_code'), get_option('api_key'), get_option('child_commerce_code')); + $this->oneclickTransbankSdk = new OneclickTransbankSdk(); } private function getWcOrder($orderId) { diff --git a/plugin/src/Controllers/TransactionStatusController.php b/plugin/src/Controllers/TransactionStatusController.php index d5799882..c1b6474f 100644 --- a/plugin/src/Controllers/TransactionStatusController.php +++ b/plugin/src/Controllers/TransactionStatusController.php @@ -36,7 +36,7 @@ public static function status() 'message' => 'El buy_order enviado y el buy_order de la transacción no coinciden', ], 401); } - $oneclickTransbankSdk = new OneclickTransbankSdk(get_option('environment'), get_option('commerce_code'), get_option('api_key'), get_option('child_commerce_code')); + $oneclickTransbankSdk = new OneclickTransbankSdk(); $status = $oneclickTransbankSdk->status($orderId, $buyOrder); $statusArray = json_decode(json_encode($status), true); $firstDetail = json_decode(json_encode($status->getDetails()[0]), true); diff --git a/plugin/src/OneclickTransbankSdk.php b/plugin/src/OneclickTransbankSdk.php index a2a5e9af..fbbfa237 100644 --- a/plugin/src/OneclickTransbankSdk.php +++ b/plugin/src/OneclickTransbankSdk.php @@ -28,6 +28,7 @@ use Transbank\Plugin\Exceptions\Oneclick\StatusOneclickException; use Transbank\Plugin\Exceptions\Oneclick\StartOneclickException; use Transbank\Plugin\Exceptions\Oneclick\StartInscriptionOneclickException; +use Transbank\WooCommerce\WebpayRest\Helpers\ConfigProvider; /** * Class OneclickTransbankSdk. @@ -45,11 +46,17 @@ class OneclickTransbankSdk extends TransbankSdk */ protected $mallInscription; - public function __construct($environment, $commerceCode, $apiKey, $childCommerceCode) + public function __construct() { + $conf = new ConfigProvider(); $this->log = TbkFactory::createLogger(); - $this->options = $this->createOptions($environment, $commerceCode, $apiKey); - $this->childCommerceCode = $environment === Options::ENVIRONMENT_PRODUCTION ? $childCommerceCode : Oneclick::DEFAULT_CHILD_COMMERCE_CODE_1; + $environment = $conf->getConfig('environment'); + $this->options = $this->createOptions( + $environment, + $conf->getConfig('commerce_code'), + $conf->getConfig('api_key')); + $this->childCommerceCode = $environment === Options::ENVIRONMENT_PRODUCTION ? + $conf->getConfig('child_commerce_code') : Oneclick::DEFAULT_CHILD_COMMERCE_CODE_1; $this->mallTransaction = new MallTransaction($this->options); $this->mallInscription = new MallInscription($this->options); } diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 09056524..75aebeeb 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -75,7 +75,7 @@ public function __construct() $this->logger = TbkFactory::createLogger(); $this->max_amount = $this->get_option('max_amount') ?? 100000; - $this->oneclickTransbankSdk = new OneclickTransbankSdk(get_option('environment'), get_option('commerce_code'), get_option('api_key'), get_option('child_commerce_code')); + $this->oneclickTransbankSdk = new OneclickTransbankSdk(); add_action( 'woocommerce_scheduled_subscription_payment_'.$this->id, From 906ee030e4f57f298e3d9a13d0f7cce71a4801fd Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 12:55:02 -0500 Subject: [PATCH 09/16] fix: change way of obtaining Webpay credentialss --- plugin/src/Controllers/ResponseController.php | 2 +- plugin/src/Controllers/TransactionStatusController.php | 2 +- plugin/src/Helpers/HealthCheck.php | 2 +- .../WC_Gateway_Transbank_Webpay_Plus_REST.php | 2 +- plugin/src/WebpayplusTransbankSdk.php | 9 +++++++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/plugin/src/Controllers/ResponseController.php b/plugin/src/Controllers/ResponseController.php index a38f32ee..07e6bc4b 100644 --- a/plugin/src/Controllers/ResponseController.php +++ b/plugin/src/Controllers/ResponseController.php @@ -37,7 +37,7 @@ public function __construct(array $pluginConfig) { $this->pluginConfig = $pluginConfig; $this->interactsWithFullLog = new InteractsWithFullLog(); - $this->webpayplusTransbankSdk = new WebpayplusTransbankSdk(get_option('webpay_rest_environment'), get_option('webpay_rest_commerce_code'), get_option('webpay_rest_api_key')); + $this->webpayplusTransbankSdk = new WebpayplusTransbankSdk(); } /** diff --git a/plugin/src/Controllers/TransactionStatusController.php b/plugin/src/Controllers/TransactionStatusController.php index c1b6474f..bfd3020b 100644 --- a/plugin/src/Controllers/TransactionStatusController.php +++ b/plugin/src/Controllers/TransactionStatusController.php @@ -59,7 +59,7 @@ public static function status() } try { - $webpayplusTransbankSdk = new WebpayplusTransbankSdk(get_option('webpay_rest_environment'), get_option('webpay_rest_commerce_code'), get_option('webpay_rest_api_key')); + $webpayplusTransbankSdk = new WebpayplusTransbankSdk(); $resp = $webpayplusTransbankSdk->status($transaction->order_id, $transaction->token); wp_send_json([ 'product' => $transaction->product, diff --git a/plugin/src/Helpers/HealthCheck.php b/plugin/src/Helpers/HealthCheck.php index eaf1ba12..0fb08fa6 100644 --- a/plugin/src/Helpers/HealthCheck.php +++ b/plugin/src/Helpers/HealthCheck.php @@ -37,7 +37,7 @@ public function __construct($config) 'curl', 'json', ]; - $this->webpayplusTransbankSdk = new WebpayplusTransbankSdk(get_option('webpay_rest_environment'), get_option('webpay_rest_commerce_code'), get_option('webpay_rest_api_key')); + $this->webpayplusTransbankSdk = new WebpayplusTransbankSdk(); } // valida version de php diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php index 183bb00a..16af83d2 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php @@ -46,7 +46,7 @@ class WC_Gateway_Transbank_Webpay_Plus_REST extends WC_Payment_Gateway public function __construct() { self::$URL_FINAL = home_url('/').'?wc-api=TransbankWebpayRestThankYouPage'; - $this->webpayplusTransbankSdk = new WebpayplusTransbankSdk(get_option('webpay_rest_environment'), get_option('webpay_rest_commerce_code'), get_option('webpay_rest_api_key')); + $this->webpayplusTransbankSdk = new WebpayplusTransbankSdk(); $this->id = 'transbank_webpay_plus_rest'; $this->icon = plugin_dir_url(dirname(dirname(__FILE__))).'images/webpay.png'; $this->method_title = __('Transbank Webpay Plus', 'transbank_webpay_plus_rest'); diff --git a/plugin/src/WebpayplusTransbankSdk.php b/plugin/src/WebpayplusTransbankSdk.php index 2b598bb7..7fabbcca 100644 --- a/plugin/src/WebpayplusTransbankSdk.php +++ b/plugin/src/WebpayplusTransbankSdk.php @@ -20,6 +20,7 @@ use Transbank\Plugin\Exceptions\Webpay\NotFoundTransactionWebpayException; use Transbank\Plugin\Exceptions\Webpay\GetTransactionWebpayException; use Transbank\Plugin\Exceptions\Webpay\StatusWebpayException; +use Transbank\WooCommerce\WebpayRest\Helpers\ConfigProvider; /** * Class WebpayplusTransbankSdk. @@ -32,10 +33,14 @@ class WebpayplusTransbankSdk extends TransbankSdk */ protected $webpayplusTransaction; - public function __construct($environment, $commerceCode, $apiKey) + public function __construct() { + $conf = new ConfigProvider(); $this->log = TbkFactory::createLogger(); - $this->options = $this->createOptions($environment, $commerceCode, $apiKey); + $this->options = $this->createOptions( + $conf->getConfig('webpay_rest_environment'), + $conf->getConfig('webpay_rest_commerce_code'), + $conf->getConfig('webpay_rest_api_key')); $this->webpayplusTransaction = new \Transbank\Webpay\WebpayPlus\Transaction($this->options); } From e2a38938461b7faece8d4a0c90b13557e063f980 Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 13:01:06 -0500 Subject: [PATCH 10/16] refactor: replace print_r by json_encode --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 75aebeeb..4d61bf34 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -275,8 +275,8 @@ public function process_payment($order_id) return wc_add_notice($errorMessage, 'error'); } - $this->logger->logInfo('[O neclick] Checkout: inscription response: '); - $this->logger->logInfo(print_r($response, true)); + $this->logger->logInfo('[Oneclick] Checkout: inscription response: '); + $this->logger->logInfo(json_encode($response)); $order->add_order_note('El usuario inició inscripción de nueva tarjeta. Redirigiendo a formulario OneClick...'); do_action('transbank_oneclick_adding_card_from_order', $order); From 89f6dd35ddee4589609f8b58680a1dad5757925e Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 13:03:29 -0500 Subject: [PATCH 11/16] refactor: remove unused var --- plugin/src/Models/Inscription.php | 2 +- plugin/src/Models/Transaction.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/Models/Inscription.php b/plugin/src/Models/Inscription.php index 75a9dbf3..bdb84935 100644 --- a/plugin/src/Models/Inscription.php +++ b/plugin/src/Models/Inscription.php @@ -59,7 +59,7 @@ public static function checkExistTable() $transactionTable = static::getTableName(); $sql = "SELECT COUNT(1) FROM ".$transactionTable; try { - $sqlResult = $wpdb->get_results($sql); + $wpdb->get_results($sql); $success = empty($wpdb->last_error); if (!$success) { return array('ok' => false, 'error' => "La tabla '{$transactionTable}' no se encontró en la base de datos.", 'exception' => "{$wpdb->last_error}"); diff --git a/plugin/src/Models/Transaction.php b/plugin/src/Models/Transaction.php index c6218aea..a3f51a5e 100644 --- a/plugin/src/Models/Transaction.php +++ b/plugin/src/Models/Transaction.php @@ -118,7 +118,7 @@ public static function checkExistTable() $transactionTable = static::getTableName(); $sql = "SELECT COUNT(1) FROM ".$transactionTable; try { - $sqlResult = $wpdb->get_results($sql); + $wpdb->get_results($sql); $success = empty($wpdb->last_error); if (!$success) { return array('ok' => false, 'error' => "La tabla '{$transactionTable}' no se encontró en la base de datos.", 'exception' => "{$wpdb->last_error}"); From daef8b6a3c88d5d610aad9c407ec5d7c95837fc1 Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 13:10:46 -0500 Subject: [PATCH 12/16] refactor: remove comment --- plugin/views/admin/options-tabs.php | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/plugin/views/admin/options-tabs.php b/plugin/views/admin/options-tabs.php index abdcb2a4..c54f7362 100644 --- a/plugin/views/admin/options-tabs.php +++ b/plugin/views/admin/options-tabs.php @@ -58,30 +58,4 @@ function tbk_is_nav_active($tab, $val) ?> - - - - - - - - - - - - - - - - From 00f0ced76023c8ae6261afb89a19c432101a9da2 Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 13:31:22 -0500 Subject: [PATCH 13/16] refactor: replace HealthCheck class by method --- plugin/libwebpay/ConnectionCheck.php | 33 ++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/plugin/libwebpay/ConnectionCheck.php b/plugin/libwebpay/ConnectionCheck.php index f6cde2b3..bbb73327 100644 --- a/plugin/libwebpay/ConnectionCheck.php +++ b/plugin/libwebpay/ConnectionCheck.php @@ -1,18 +1,43 @@ setCreateTransaction(); + $resp = ConnectionCheck::setCreateTransaction(); header('Content-Type: application/json'); ob_clean(); echo json_encode($resp); wp_die(); } + + public static function setCreateTransaction() + { + $amount = 990; + $buyOrder = '_Healthcheck_'; + $sessionId = uniqid(); + $returnUrl = 'http://test.com/test'; + + $status = 'Error'; + try { + $webpayplusTransbankSdk = new WebpayplusTransbankSdk(); + $result = $webpayplusTransbankSdk->createInner(0, $buyOrder, $sessionId, $amount, $returnUrl); + $status = 'OK'; + + } catch (\Exception $e) { + $status = 'Error'; + $result = [ + 'error' => 'Error al crear la transacción', + 'detail' => $e->getMessage() + ]; + } + + return [ + 'status' => ['string' => $status], + 'response' => $result + ]; + } } From 3454f429c738918b5c2dd56624f604adada0ed44 Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 13:32:34 -0500 Subject: [PATCH 14/16] refactor: remove unnecessary HealthCheck class --- plugin/src/Helpers/HealthCheck.php | 265 ---------------------- plugin/src/Helpers/HealthCheckFactory.php | 25 -- plugin/views/admin/options-tabs.php | 4 - 3 files changed, 294 deletions(-) delete mode 100644 plugin/src/Helpers/HealthCheck.php delete mode 100644 plugin/src/Helpers/HealthCheckFactory.php diff --git a/plugin/src/Helpers/HealthCheck.php b/plugin/src/Helpers/HealthCheck.php deleted file mode 100644 index 0fb08fa6..00000000 --- a/plugin/src/Helpers/HealthCheck.php +++ /dev/null @@ -1,265 +0,0 @@ -config = $config; - $this->environment = $config['MODO']; - $this->commerceCode = $config['COMMERCE_CODE']; - $this->apiKey = $config['API_KEY']; - $this->ecommerce = $config['ECOMMERCE']; - // extensiones necesarias - $this->extensions = [ - 'dom', - 'curl', - 'json', - ]; - $this->webpayplusTransbankSdk = new WebpayplusTransbankSdk(); - } - - // valida version de php - private function getValidatephp() - { - if (version_compare(phpversion(), '7.0.0', '>=')) { - $this->versionInfo = [ - 'status' => 'OK', - 'version' => phpversion(), - ]; - } else { - $this->versionInfo = [ - 'status' => 'Error!: Version no soportada', - 'version' => phpversion(), - ]; - } - - return $this->versionInfo; - } - - // verifica si existe la extension y cual es la version de esta - private function getCheckExtension($extension) - { - if (extension_loaded($extension)) { - if ($extension == 'openssl') { - $version = OPENSSL_VERSION_TEXT; - } else { - $version = phpversion($extension); - if (empty($version) or $version == null or $version === false or $version == ' ' or $version == '') { - $version = 'PHP Extension Compiled. ver:'.phpversion(); - } - } - $status = 'OK'; - $result = [ - 'status' => $status, - 'version' => $version, - ]; - } else { - $result = [ - 'status' => 'Error!', - 'version' => 'No Disponible', - ]; - } - - return $result; - } - - //obtiene ultimas versiones - // obtiene versiones ultima publica en github (no compatible con virtuemart) lo ideal es que el :usuario/:repo sean entregados como string - // permite un maximo de 60 consultas por hora - private function getLastGitHubReleaseVersion($string) - { - $baseurl = 'https://api.github.com/repos/'.$string.'/releases/latest'; - $response = wp_remote_get($baseurl); - $body = wp_remote_retrieve_body($response); - $json = json_decode($body, true); - $version = is_array($json) && array_key_exists('tag_name', $json) ? $json['tag_name'] : '-'; - - return $version; - } - - // funcion para obtener info de cada ecommerce, si el ecommerce es incorrecto o no esta seteado se escapa como respuesta "NO APLICA" - private function getEcommerceInfo($ecommerce) - { - if (!class_exists('WooCommerce')) { - exit; - } else { - global $woocommerce; - if (!$woocommerce->version) { - exit; - } else { - $actualversion = $woocommerce->version; - $lastversion = $this->getLastGitHubReleaseVersion('woocommerce/woocommerce'); - $file = __DIR__.'/../../webpay-rest.php'; - $search = ' * Version:'; - $lines = file($file); - foreach ($lines as $line) { - if (strpos($line, $search) !== false) { - $currentplugin = str_replace(' * Version:', '', $line); - } - } - } - } - $result = [ - 'current_ecommerce_version' => $actualversion, - 'last_ecommerce_version' => $lastversion, - 'current_plugin_version' => $currentplugin, - ]; - - return $result; - } - - // creacion de retornos - // arma array que entrega informacion del ecommerce: nombre, version instalada, ultima version disponible - private function getPluginInfo($ecommerce) - { - $data = $this->getEcommerceInfo($ecommerce); - $result = [ - 'ecommerce' => $ecommerce, - 'ecommerce_version' => $data['current_ecommerce_version'], - 'current_plugin_version' => $data['current_plugin_version'], - 'last_plugin_version' => $this->getPluginLastVersion(), - ]; - - return $result; - } - - // arma array con informacion del último plugin compatible con el ecommerce - private function getPluginLastVersion() - { - $response = wp_remote_get('https://api.github.com/repos/TransbankDevelopers/transbank-plugin-woocommerce-webpay-rest/releases/latest'); - $body = wp_remote_retrieve_body($response); - - $json = json_decode($body, true); - if (isset($json['message'])) { - return 'No se pudo obtener'; - } - - $tag_name = $json['tag_name']; - - return $tag_name; - } - - // lista y valida extensiones/ modulos de php en servidor ademas mostrar version - private function getExtensionsValidate() - { - foreach ($this->extensions as $value) { - $this->resExtensions[$value] = $this->getCheckExtension($value); - } - - return $this->resExtensions; - } - - // crea resumen de informacion del servidor. NO incluye a PHP info - private function getServerResume() - { - // arma array de despliegue - $this->resume = [ - 'php_version' => $this->getValidatephp(), - 'server_version' => ['server_software' => $_SERVER['SERVER_SOFTWARE']], - 'plugin_info' => $this->getPluginInfo($this->ecommerce), - ]; - - return $this->resume; - } - - // crea array con la informacion de comercio para posteriormente exportarla via json - private function getCommerceInfo() - { - $result = [ - 'environment' => $this->environment, - 'commerce_code' => $this->commerceCode, - 'api_key' => $this->apiKey, - ]; - - return ['data' => $result]; - } - - public function setCreateTransaction() - { - $amount = 990; - $buyOrder = '_Healthcheck_'; - $sessionId = uniqid(); - $returnUrl = 'http://test.com/test'; - - $status = 'Error'; - try { - $result = $this->webpayplusTransbankSdk->createInner(0, $buyOrder, $sessionId, $amount, $returnUrl); - $status = 'OK'; - - } catch (\Exception $e) { - $status = 'Error'; - $result = [ - 'error' => 'Error al crear la transacción', - 'detail' => $e->getMessage() - ]; - } - - return [ - 'status' => ['string' => $status], - 'response' => $result - ]; - } - - //compila en solo un metodo toda la informacion obtenida, lista para imprimir - private function getFullResume() - { - $this->fullResume = [ - 'server_resume' => $this->getServerResume(), - 'php_extensions_status' => $this->getExtensionsValidate(), - 'commerce_info' => $this->getCommerceInfo() - ]; - - return $this->fullResume; - } - - // imprime informacion de comercio y llaves - public function printCommerceInfo() - { - return json_encode($this->getCommerceInfo()); - } - - // imprime en formato json la validacion de extensiones / modulos de php - public function printExtensionStatus() - { - return json_encode($this->getExtensionsValidate()); - } - - // imprime en formato json informacion del servidor - public function printServerResume() - { - return json_encode($this->getServerResume()); - } - - // imprime en formato json el resumen completo - public function printFullResume() - { - return json_encode($this->getFullResume()); - } - - public function getInitTransaction() - { - return json_encode($this->setCreateTransaction()); - } -} diff --git a/plugin/src/Helpers/HealthCheckFactory.php b/plugin/src/Helpers/HealthCheckFactory.php deleted file mode 100644 index d15cca33..00000000 --- a/plugin/src/Helpers/HealthCheckFactory.php +++ /dev/null @@ -1,25 +0,0 @@ - $configProvider->getConfig('webpay_rest_environment'), - 'COMMERCE_CODE' => $configProvider->getConfig('webpay_rest_commerce_code'), - 'API_KEY' => $configProvider->getConfig('webpay_api_key'), - 'ECOMMERCE' => 'woocommerce', - ]; - - return new HealthCheck($config); - } -} diff --git a/plugin/views/admin/options-tabs.php b/plugin/views/admin/options-tabs.php index c54f7362..049e77b2 100644 --- a/plugin/views/admin/options-tabs.php +++ b/plugin/views/admin/options-tabs.php @@ -1,7 +1,5 @@ printFullResume()); include_once __DIR__.'/healthcheck.php'; } ?> From d977bf45575135bbe8e13c4d2163c4302249bb95 Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 14:21:06 -0500 Subject: [PATCH 15/16] feat: update php version and extensions --- plugin/shared/Helpers/InfoUtil.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugin/shared/Helpers/InfoUtil.php b/plugin/shared/Helpers/InfoUtil.php index 369d74dd..ebfa47db 100644 --- a/plugin/shared/Helpers/InfoUtil.php +++ b/plugin/shared/Helpers/InfoUtil.php @@ -11,7 +11,7 @@ class InfoUtil */ public static function getValidatephp() { - if (version_compare(phpversion(), '7.4.28', '<=') && + if (version_compare(phpversion(), '8.1.8', '<=') && version_compare(phpversion(), '7.0.0', '>=')) { return [ 'status' => 'OK', @@ -67,9 +67,8 @@ public static function getExtensionsValidate() { $result = []; $extensions = [ - 'openssl', - 'SimpleXML', - 'soap', + 'curl', + 'json', 'dom', ]; foreach ($extensions as $value) { From fbded2b840f333a7bdcbc1105c0e6a44f8264842 Mon Sep 17 00:00:00 2001 From: Miguel Vargas Date: Tue, 31 Oct 2023 14:22:01 -0500 Subject: [PATCH 16/16] refactor: change info utils --- plugin/views/admin/healthcheck.php | 47 +++++++++++++++++------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/plugin/views/admin/healthcheck.php b/plugin/views/admin/healthcheck.php index 44376de0..db46b937 100644 --- a/plugin/views/admin/healthcheck.php +++ b/plugin/views/admin/healthcheck.php @@ -1,7 +1,14 @@
@@ -167,11 +174,11 @@ class="label label-info">?
- server_resume->plugin_info->ecommerce; ?> +
-
?
@@ -180,11 +187,11 @@ class="label label-info">?
- server_resume->plugin_info->ecommerce_version; ?> +
-
?
@@ -193,11 +200,11 @@ class="label label-info">?
- server_resume->plugin_info->current_plugin_version; ?> +
-
?
@@ -206,7 +213,7 @@ class="label label-info">?
- server_resume->plugin_info->last_plugin_version; ?> +
@@ -224,7 +231,7 @@ class="label label-info">?
- server_resume->server_version->server_software; ?> +
@@ -237,11 +244,11 @@ class="label label-info">?
server_resume->php_version->status; ?> + } ?>">
@@ -254,7 +261,7 @@ class="label label-info">?
- server_resume->php_version->version; ?> +
@@ -272,48 +279,48 @@ class="label label-info">? json - php_extensions_status->json->status; ?> + - php_extensions_status->json->version; ?> + dom - php_extensions_status->dom->status; ?> + - php_extensions_status->dom->version; ?> + curl - php_extensions_status->curl->status; ?> + - php_extensions_status->curl->version; ?> +