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 + ]; + } } 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 @@ +authorizeResponse = $authorizeResponse; + parent::__construct($message, $previous); + } + + public function getAuthorizeResponse() { + return $this->authorizeResponse; + } +} diff --git a/plugin/shared/Exceptions/Oneclick/CreateTransactionOneclickException.php b/plugin/shared/Exceptions/Oneclick/CreateTransactionOneclickException.php new file mode 100644 index 00000000..681006f3 --- /dev/null +++ b/plugin/shared/Exceptions/Oneclick/CreateTransactionOneclickException.php @@ -0,0 +1,10 @@ +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 new file mode 100644 index 00000000..e6ee0031 --- /dev/null +++ b/plugin/shared/Exceptions/Oneclick/GetInscriptionOneclickException.php @@ -0,0 +1,9 @@ +orderId = $orderId; + parent::__construct($message, $previous); + } + + public function getOrderId() { + return $this->orderId; + } + +} diff --git a/plugin/src/Exceptions/Oneclick/UserCancelInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/InvalidStatusInscriptionOneclickException.php similarity index 59% rename from plugin/src/Exceptions/Oneclick/UserCancelInscriptionOneclickException.php rename to plugin/shared/Exceptions/Oneclick/InvalidStatusInscriptionOneclickException.php index c3b6a0bc..ba703b9e 100644 --- a/plugin/src/Exceptions/Oneclick/UserCancelInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/InvalidStatusInscriptionOneclickException.php @@ -1,16 +1,18 @@ 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 new file mode 100644 index 00000000..14e11716 --- /dev/null +++ b/plugin/shared/Exceptions/Oneclick/NotFoundTransactionOneclickException.php @@ -0,0 +1,20 @@ +orderId = $orderId; + parent::__construct($message, $previous); + } + + public function getOrderId() { + return $this->orderId; + } + +} diff --git a/plugin/src/Exceptions/Oneclick/RefundOneclickException.php b/plugin/shared/Exceptions/Oneclick/RefundOneclickException.php similarity index 67% rename from plugin/src/Exceptions/Oneclick/RefundOneclickException.php rename to plugin/shared/Exceptions/Oneclick/RefundOneclickException.php index 8aae9711..140ef813 100644 --- a/plugin/src/Exceptions/Oneclick/RefundOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/RefundOneclickException.php @@ -1,18 +1,21 @@ 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 new file mode 100644 index 00000000..2ca5fe59 --- /dev/null +++ b/plugin/shared/Exceptions/Oneclick/RejectedAuthorizeOneclickException.php @@ -0,0 +1,19 @@ +authorizeResponse = $authorizeResponse; + parent::__construct($message, $previous); + } + + public function getAuthorizeResponse() { + return $this->authorizeResponse; + } +} diff --git a/plugin/src/Exceptions/Oneclick/RejectedInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/RejectedInscriptionOneclickException.php similarity index 67% rename from plugin/src/Exceptions/Oneclick/RejectedInscriptionOneclickException.php rename to plugin/shared/Exceptions/Oneclick/RejectedInscriptionOneclickException.php index 2fdb947b..69de148c 100644 --- a/plugin/src/Exceptions/Oneclick/RejectedInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/RejectedInscriptionOneclickException.php @@ -1,18 +1,21 @@ tbkToken = $tbkToken; $this->inscription = $inscription; $this->finishInscriptionResponse = $finishInscriptionResponse; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTbkToken() { diff --git a/plugin/src/Exceptions/Oneclick/RejectedRefundOneclickException.php b/plugin/shared/Exceptions/Oneclick/RejectedRefundOneclickException.php similarity index 71% rename from plugin/src/Exceptions/Oneclick/RejectedRefundOneclickException.php rename to plugin/shared/Exceptions/Oneclick/RejectedRefundOneclickException.php index edcec9cf..ea52a91a 100644 --- a/plugin/src/Exceptions/Oneclick/RejectedRefundOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/RejectedRefundOneclickException.php @@ -1,20 +1,23 @@ 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 new file mode 100644 index 00000000..7603bd3a --- /dev/null +++ b/plugin/shared/Exceptions/Oneclick/StartInscriptionOneclickException.php @@ -0,0 +1,10 @@ +buyOrder = $buyOrder; + parent::__construct($message, $previous); + } + + public function getBuyOrder() { + return $this->buyOrder; + } + +} diff --git a/plugin/src/Exceptions/Oneclick/TimeoutInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/TimeoutInscriptionOneclickException.php similarity index 60% rename from plugin/src/Exceptions/Oneclick/TimeoutInscriptionOneclickException.php rename to plugin/shared/Exceptions/Oneclick/TimeoutInscriptionOneclickException.php index 69862b68..74cd8528 100644 --- a/plugin/src/Exceptions/Oneclick/TimeoutInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/TimeoutInscriptionOneclickException.php @@ -1,16 +1,18 @@ tbkToken = $tbkToken; $this->inscription = $inscription; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTbkToken() { diff --git a/plugin/src/Exceptions/Oneclick/InvalidStatusInscriptionOneclickException.php b/plugin/shared/Exceptions/Oneclick/UserCancelInscriptionOneclickException.php similarity index 60% rename from plugin/src/Exceptions/Oneclick/InvalidStatusInscriptionOneclickException.php rename to plugin/shared/Exceptions/Oneclick/UserCancelInscriptionOneclickException.php index 90e2530d..230bdf23 100644 --- a/plugin/src/Exceptions/Oneclick/InvalidStatusInscriptionOneclickException.php +++ b/plugin/shared/Exceptions/Oneclick/UserCancelInscriptionOneclickException.php @@ -1,16 +1,18 @@ 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 new file mode 100644 index 00000000..95545ddd --- /dev/null +++ b/plugin/shared/Exceptions/Oneclick/WithoutTokenInscriptionOneclickException.php @@ -0,0 +1,10 @@ +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 new file mode 100644 index 00000000..5699eb23 --- /dev/null +++ b/plugin/shared/Exceptions/Webpay/CreateTransactionWebpayException.php @@ -0,0 +1,10 @@ +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 new file mode 100644 index 00000000..4b0ca679 --- /dev/null +++ b/plugin/shared/Exceptions/Webpay/GetTransactionWebpayException.php @@ -0,0 +1,20 @@ +orderId = $orderId; + parent::__construct($message, $previous); + } + + public function getOrderId() { + return $this->orderId; + } + +} diff --git a/plugin/src/Exceptions/Webpay/InvalidStatusWebpayException.php b/plugin/shared/Exceptions/Webpay/InvalidStatusWebpayException.php similarity index 60% rename from plugin/src/Exceptions/Webpay/InvalidStatusWebpayException.php rename to plugin/shared/Exceptions/Webpay/InvalidStatusWebpayException.php index 509624d6..3225fc6c 100644 --- a/plugin/src/Exceptions/Webpay/InvalidStatusWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/InvalidStatusWebpayException.php @@ -1,16 +1,18 @@ 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 new file mode 100644 index 00000000..2b668cd3 --- /dev/null +++ b/plugin/shared/Exceptions/Webpay/NotFoundTransactionWebpayException.php @@ -0,0 +1,20 @@ +orderId = $orderId; + parent::__construct($message, $previous); + } + + public function getOrderId() { + return $this->orderId; + } + +} diff --git a/plugin/src/Exceptions/Webpay/RefundWebpayException.php b/plugin/shared/Exceptions/Webpay/RefundWebpayException.php similarity index 61% rename from plugin/src/Exceptions/Webpay/RefundWebpayException.php rename to plugin/shared/Exceptions/Webpay/RefundWebpayException.php index 80d6ad73..05dbb40d 100644 --- a/plugin/src/Exceptions/Webpay/RefundWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/RefundWebpayException.php @@ -1,16 +1,18 @@ token = $token; $this->transaction = $transaction; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getToken() { diff --git a/plugin/src/Exceptions/Webpay/RejectedCommitWebpayException.php b/plugin/shared/Exceptions/Webpay/RejectedCommitWebpayException.php similarity index 67% rename from plugin/src/Exceptions/Webpay/RejectedCommitWebpayException.php rename to plugin/shared/Exceptions/Webpay/RejectedCommitWebpayException.php index 29277390..6de702c8 100644 --- a/plugin/src/Exceptions/Webpay/RejectedCommitWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/RejectedCommitWebpayException.php @@ -1,18 +1,21 @@ tokenWs = $tokenWs; $this->transaction = $transaction; $this->commitResponse = $commitResponse; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getTokenWs() { diff --git a/plugin/src/Exceptions/Webpay/RejectedRefundWebpayException.php b/plugin/shared/Exceptions/Webpay/RejectedRefundWebpayException.php similarity index 67% rename from plugin/src/Exceptions/Webpay/RejectedRefundWebpayException.php rename to plugin/shared/Exceptions/Webpay/RejectedRefundWebpayException.php index a109ffff..d5a99ba6 100644 --- a/plugin/src/Exceptions/Webpay/RejectedRefundWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/RejectedRefundWebpayException.php @@ -1,18 +1,21 @@ 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 new file mode 100644 index 00000000..54bd7a52 --- /dev/null +++ b/plugin/shared/Exceptions/Webpay/StatusWebpayException.php @@ -0,0 +1,20 @@ +token = $token; + parent::__construct($message, $previous); + } + + public function getToken() { + return $this->token; + } + +} diff --git a/plugin/src/Exceptions/Webpay/TimeoutWebpayException.php b/plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php similarity index 67% rename from plugin/src/Exceptions/Webpay/TimeoutWebpayException.php rename to plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php index 9dc6321c..b6453b00 100644 --- a/plugin/src/Exceptions/Webpay/TimeoutWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/TimeoutWebpayException.php @@ -1,18 +1,21 @@ buyOrder = $buyOrder; $this->sessionId = $sessionId; $this->transaction = $transaction; - parent::__construct($message, $code, $previous); + parent::__construct($message, $previous); } public function getBuyOrder() { diff --git a/plugin/src/Exceptions/Webpay/UserCancelWebpayException.php b/plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php similarity index 60% rename from plugin/src/Exceptions/Webpay/UserCancelWebpayException.php rename to plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php index ebf08b0b..90630469 100644 --- a/plugin/src/Exceptions/Webpay/UserCancelWebpayException.php +++ b/plugin/shared/Exceptions/Webpay/UserCancelWebpayException.php @@ -1,16 +1,19 @@ 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 new file mode 100644 index 00000000..3314c615 --- /dev/null +++ b/plugin/shared/Exceptions/Webpay/WithoutTokenWebpayException.php @@ -0,0 +1,10 @@ +=')) { return [ 'status' => 'OK', @@ -67,9 +67,8 @@ public static function getExtensionsValidate() { $result = []; $extensions = [ - 'openssl', - 'SimpleXML', - 'soap', + 'curl', + 'json', 'dom', ]; foreach ($extensions as $value) { diff --git a/plugin/src/Controllers/OneclickInscriptionResponseController.php b/plugin/src/Controllers/OneclickInscriptionResponseController.php index 5f9b13e6..1694747b 100644 --- a/plugin/src/Controllers/OneclickInscriptionResponseController.php +++ b/plugin/src/Controllers/OneclickInscriptionResponseController.php @@ -6,13 +6,13 @@ use Transbank\WooCommerce\WebpayRest\Helpers\TbkFactory; use Transbank\WooCommerce\WebpayRest\OneclickTransbankSdk; use Transbank\WooCommerce\WebpayRest\Models\Inscription; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\UserCancelInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\InvalidStatusInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\TimeoutInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\WithoutTokenInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\FinishInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\RejectedInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\GetInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\UserCancelInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\InvalidStatusInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\TimeoutInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\WithoutTokenInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\FinishInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\RejectedInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\GetInscriptionOneclickException; use WC_Payment_Token_Oneclick; use WC_Payment_Tokens; @@ -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) { @@ -57,7 +57,7 @@ private function savePaymentToken($inscription, $finishInscriptionResponse){ } /** - * @throws \Transbank\WooCommerce\WebpayRest\Exceptions\TokenNotFoundOnDatabaseException + * @throws \Transbank\Plugin\Exceptions\TokenNotFoundOnDatabaseException */ public function response() { diff --git a/plugin/src/Controllers/ResponseController.php b/plugin/src/Controllers/ResponseController.php index 03a75110..07e6bc4b 100644 --- a/plugin/src/Controllers/ResponseController.php +++ b/plugin/src/Controllers/ResponseController.php @@ -7,12 +7,12 @@ use Transbank\Webpay\WebpayPlus\Responses\TransactionCommitResponse; use Transbank\WooCommerce\WebpayRest\Models\Transaction; use Transbank\WooCommerce\WebpayRest\Helpers\InteractsWithFullLog; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\TimeoutWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\UserCancelWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\DoubleTokenWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\CommitWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\InvalidStatusWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\RejectedCommitWebpayException; +use Transbank\Plugin\Exceptions\Webpay\TimeoutWebpayException; +use Transbank\Plugin\Exceptions\Webpay\UserCancelWebpayException; +use Transbank\Plugin\Exceptions\Webpay\DoubleTokenWebpayException; +use Transbank\Plugin\Exceptions\Webpay\CommitWebpayException; +use Transbank\Plugin\Exceptions\Webpay\InvalidStatusWebpayException; +use Transbank\Plugin\Exceptions\Webpay\RejectedCommitWebpayException; use Transbank\WooCommerce\WebpayRest\WebpayplusTransbankSdk; use WC_Order; @@ -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(); } /** @@ -62,7 +62,7 @@ public static function getHumanReadableInstallemntsType($paymentTypeCode): strin /** * @throws \GuzzleHttp\Exception\GuzzleException - * @throws \Transbank\WooCommerce\WebpayRest\Exceptions\TokenNotFoundOnDatabaseException + * @throws \Transbank\Plugin\Exceptions\TokenNotFoundOnDatabaseException */ public function response($postData) { diff --git a/plugin/src/Controllers/TransactionStatusController.php b/plugin/src/Controllers/TransactionStatusController.php index d5799882..bfd3020b 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); @@ -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/Exceptions/InvalidOrderException.php b/plugin/src/Exceptions/InvalidOrderException.php deleted file mode 100644 index f986d280..00000000 --- a/plugin/src/Exceptions/InvalidOrderException.php +++ /dev/null @@ -1,7 +0,0 @@ -authorizeResponse = $authorizeResponse; - parent::__construct($message, $code, $previous); - } - - public function getAuthorizeResponse() { - return $this->authorizeResponse; - } -} diff --git a/plugin/src/Exceptions/Oneclick/CreateTransactionOneclickException.php b/plugin/src/Exceptions/Oneclick/CreateTransactionOneclickException.php deleted file mode 100644 index 5eba624a..00000000 --- a/plugin/src/Exceptions/Oneclick/CreateTransactionOneclickException.php +++ /dev/null @@ -1,8 +0,0 @@ -orderId = $orderId; - parent::__construct($message, $code, $previous); - } - - public function getOrderId() { - return $this->orderId; - } - -} diff --git a/plugin/src/Exceptions/Oneclick/NotFoundTransactionOneclickException.php b/plugin/src/Exceptions/Oneclick/NotFoundTransactionOneclickException.php deleted file mode 100644 index 9c93865b..00000000 --- a/plugin/src/Exceptions/Oneclick/NotFoundTransactionOneclickException.php +++ /dev/null @@ -1,18 +0,0 @@ -orderId = $orderId; - parent::__construct($message, $code, $previous); - } - - public function getOrderId() { - return $this->orderId; - } - -} diff --git a/plugin/src/Exceptions/Oneclick/RejectedAuthorizeOneclickException.php b/plugin/src/Exceptions/Oneclick/RejectedAuthorizeOneclickException.php deleted file mode 100644 index 798055dc..00000000 --- a/plugin/src/Exceptions/Oneclick/RejectedAuthorizeOneclickException.php +++ /dev/null @@ -1,17 +0,0 @@ -authorizeResponse = $authorizeResponse; - parent::__construct($message, $code, $previous); - } - - public function getAuthorizeResponse() { - return $this->authorizeResponse; - } -} diff --git a/plugin/src/Exceptions/Oneclick/StartInscriptionOneclickException.php b/plugin/src/Exceptions/Oneclick/StartInscriptionOneclickException.php deleted file mode 100644 index db7e87bc..00000000 --- a/plugin/src/Exceptions/Oneclick/StartInscriptionOneclickException.php +++ /dev/null @@ -1,8 +0,0 @@ -buyOrder = $buyOrder; - parent::__construct($message, $code, $previous); - } - - public function getBuyOrder() { - return $this->buyOrder; - } - -} diff --git a/plugin/src/Exceptions/Oneclick/WithoutTokenInscriptionOneclickException.php b/plugin/src/Exceptions/Oneclick/WithoutTokenInscriptionOneclickException.php deleted file mode 100644 index 9ff3669f..00000000 --- a/plugin/src/Exceptions/Oneclick/WithoutTokenInscriptionOneclickException.php +++ /dev/null @@ -1,8 +0,0 @@ -orderId = $orderId; - parent::__construct($message, $code, $previous); - } - - public function getOrderId() { - return $this->orderId; - } - -} diff --git a/plugin/src/Exceptions/Webpay/NotFoundTransactionWebpayException.php b/plugin/src/Exceptions/Webpay/NotFoundTransactionWebpayException.php deleted file mode 100644 index 68a94bbe..00000000 --- a/plugin/src/Exceptions/Webpay/NotFoundTransactionWebpayException.php +++ /dev/null @@ -1,18 +0,0 @@ -orderId = $orderId; - parent::__construct($message, $code, $previous); - } - - public function getOrderId() { - return $this->orderId; - } - -} diff --git a/plugin/src/Exceptions/Webpay/StatusWebpayException.php b/plugin/src/Exceptions/Webpay/StatusWebpayException.php deleted file mode 100644 index 73e58982..00000000 --- a/plugin/src/Exceptions/Webpay/StatusWebpayException.php +++ /dev/null @@ -1,18 +0,0 @@ -token = $token; - parent::__construct($message, $code, $previous); - } - - public function getToken() { - return $this->token; - } - -} diff --git a/plugin/src/Exceptions/Webpay/WithoutTokenWebpayException.php b/plugin/src/Exceptions/Webpay/WithoutTokenWebpayException.php deleted file mode 100644 index 49c36667..00000000 --- a/plugin/src/Exceptions/Webpay/WithoutTokenWebpayException.php +++ /dev/null @@ -1,8 +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(get_option('webpay_rest_environment'), get_option('webpay_rest_commerce_code'), get_option('webpay_rest_api_key')); - } - - // 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/src/Models/Inscription.php b/plugin/src/Models/Inscription.php index b6e14f68..bdb84935 100644 --- a/plugin/src/Models/Inscription.php +++ b/plugin/src/Models/Inscription.php @@ -4,7 +4,7 @@ use function is_multisite; use Exception; -use Transbank\WooCommerce\WebpayRest\Exceptions\TokenNotFoundOnDatabaseException; +use Transbank\Plugin\Exceptions\TokenNotFoundOnDatabaseException; class Inscription { @@ -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 e6fe216c..a3f51a5e 100644 --- a/plugin/src/Models/Transaction.php +++ b/plugin/src/Models/Transaction.php @@ -4,7 +4,7 @@ use function is_multisite; use Exception; -use Transbank\WooCommerce\WebpayRest\Exceptions\TokenNotFoundOnDatabaseException; +use Transbank\Plugin\Exceptions\TokenNotFoundOnDatabaseException; class Transaction { @@ -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}"); diff --git a/plugin/src/OneclickTransbankSdk.php b/plugin/src/OneclickTransbankSdk.php index 1b92facf..fbbfa237 100644 --- a/plugin/src/OneclickTransbankSdk.php +++ b/plugin/src/OneclickTransbankSdk.php @@ -10,24 +10,25 @@ use Transbank\Webpay\Options; use Transbank\WooCommerce\WebpayRest\Models\Inscription; use Transbank\WooCommerce\WebpayRest\Models\Transaction; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\TimeoutInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\UserCancelInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\WithoutTokenInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\RejectedInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\InvalidStatusInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\FinishInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\GetInscriptionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\RejectedAuthorizeOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\ConstraintsViolatedAuthorizeOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\CreateTransactionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\AuthorizeOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\RejectedRefundOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\RefundOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\NotFoundTransactionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\GetTransactionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\StatusOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\StartOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\StartInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\TimeoutInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\UserCancelInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\WithoutTokenInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\RejectedInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\InvalidStatusInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\FinishInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\GetInscriptionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\RejectedAuthorizeOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\ConstraintsViolatedAuthorizeOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\CreateTransactionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\AuthorizeOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\RejectedRefundOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\RefundOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\NotFoundTransactionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\GetTransactionOneclickException; +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); } @@ -116,7 +123,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 +142,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 +261,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 +284,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 +334,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 +436,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 +455,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/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index eba7e1bf..4d61bf34 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -3,20 +3,21 @@ 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; use Transbank\WooCommerce\WebpayRest\Controllers\OneclickInscriptionResponseController; use Transbank\WooCommerce\WebpayRest\Helpers\ErrorHelper; use Transbank\WooCommerce\WebpayRest\OneclickTransbankSdk; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\RejectedAuthorizeOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\CreateTransactionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\AuthorizeOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\ConstraintsViolatedAuthorizeOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\RejectedRefundOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\RefundOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\NotFoundTransactionOneclickException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Oneclick\GetTransactionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\RejectedAuthorizeOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\CreateTransactionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\AuthorizeOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\ConstraintsViolatedAuthorizeOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\RejectedRefundOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\RefundOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\NotFoundTransactionOneclickException; +use Transbank\Plugin\Exceptions\Oneclick\GetTransactionOneclickException; use WC_Order; use WC_Payment_Gateway_CC; use WC_Payment_Token_Oneclick; @@ -74,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, @@ -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); } @@ -274,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); 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 65822c2a..16af83d2 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; @@ -10,12 +11,12 @@ use Transbank\WooCommerce\WebpayRest\Helpers\ErrorHelper; use Transbank\WooCommerce\WebpayRest\PaymentGateways\TransbankRESTPaymentGateway; use Transbank\WooCommerce\WebpayRest\WebpayplusTransbankSdk; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\CreateWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\CreateTransactionWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\GetTransactionWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\NotFoundTransactionWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\RefundWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\RejectedRefundWebpayException; +use Transbank\Plugin\Exceptions\Webpay\CreateWebpayException; +use Transbank\Plugin\Exceptions\Webpay\CreateTransactionWebpayException; +use Transbank\Plugin\Exceptions\Webpay\GetTransactionWebpayException; +use Transbank\Plugin\Exceptions\Webpay\NotFoundTransactionWebpayException; +use Transbank\Plugin\Exceptions\Webpay\RefundWebpayException; +use Transbank\Plugin\Exceptions\Webpay\RejectedRefundWebpayException; use WC_Order; use WC_Payment_Gateway; @@ -45,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'); @@ -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); } /** 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; - } -} diff --git a/plugin/src/WebpayplusTransbankSdk.php b/plugin/src/WebpayplusTransbankSdk.php index 40ef3207..7fabbcca 100644 --- a/plugin/src/WebpayplusTransbankSdk.php +++ b/plugin/src/WebpayplusTransbankSdk.php @@ -7,19 +7,20 @@ use Transbank\Webpay\Options; use Transbank\WooCommerce\WebpayRest\Models\Transaction; use Transbank\WooCommerce\WebpayRest\Helpers\ErrorUtil; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\TimeoutWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\UserCancelWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\DoubleTokenWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\CommitWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\InvalidStatusWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\RejectedCommitWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\CreateWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\CreateTransactionWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\RejectedRefundWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\RefundWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\NotFoundTransactionWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\GetTransactionWebpayException; -use Transbank\WooCommerce\WebpayRest\Exceptions\Webpay\StatusWebpayException; +use Transbank\Plugin\Exceptions\Webpay\TimeoutWebpayException; +use Transbank\Plugin\Exceptions\Webpay\UserCancelWebpayException; +use Transbank\Plugin\Exceptions\Webpay\DoubleTokenWebpayException; +use Transbank\Plugin\Exceptions\Webpay\CommitWebpayException; +use Transbank\Plugin\Exceptions\Webpay\InvalidStatusWebpayException; +use Transbank\Plugin\Exceptions\Webpay\RejectedCommitWebpayException; +use Transbank\Plugin\Exceptions\Webpay\CreateWebpayException; +use Transbank\Plugin\Exceptions\Webpay\CreateTransactionWebpayException; +use Transbank\Plugin\Exceptions\Webpay\RejectedRefundWebpayException; +use Transbank\Plugin\Exceptions\Webpay\RefundWebpayException; +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); } @@ -97,15 +102,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 +130,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 +207,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 +224,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 +343,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); } } 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; ?> + diff --git a/plugin/views/admin/options-tabs.php b/plugin/views/admin/options-tabs.php index abdcb2a4..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'; } ?> - - - - - - - - - - - - - - - -