-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create custom logger and save to /var/log/pagseguro.log #3
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,12 +65,15 @@ public function __construct( | |
\Magento\Store\Model\StoreManagerInterface $storeManager, | ||
\Magento\Checkout\Model\Session $checkoutSession, | ||
\Magento\Customer\Model\Customer $customer, | ||
\Magento\Framework\App\Helper\Context $context | ||
\Magento\Framework\App\Helper\Context $context, | ||
\Psr\Log\LoggerInterface $customLogger | ||
|
||
) { | ||
$this->storeManager = $storeManager; | ||
$this->checkoutSession = $checkoutSession; | ||
$this->customerRepo = $customer; | ||
$this->_customLogger = $customLogger; | ||
|
||
parent::__construct($context); | ||
} | ||
|
||
|
@@ -82,7 +85,6 @@ public function __construct( | |
*/ | ||
public function getSessionId() | ||
{ | ||
|
||
$url = $this->getWsUrl('sessions'); | ||
$ch = curl_init($url); | ||
$params['email'] = $this->getMerchantEmail(); | ||
|
@@ -164,9 +166,9 @@ public function writeLog($obj) | |
{ | ||
if ($this->isDebugActive()) { | ||
if (is_string($obj)) { | ||
$this->_logger->debug($obj); | ||
$this->_customLogger->debug($obj); | ||
} else { | ||
$this->_logger->debug(json_encode($obj)); | ||
$this->_customLogger->debug(json_encode($obj)); | ||
} | ||
} | ||
} | ||
|
@@ -238,7 +240,7 @@ public function getPaymentHash($param = null) | |
$psPayment = $this->checkoutSession->getData('PsPayment'); | ||
|
||
$psPayment = unserialize($psPayment); | ||
// $this->writeLog('getPaymentHash'.json_encode($psPayment)); | ||
// $this->writeLog('getPaymentHash'.json_encode($psPayment)); | ||
if (is_null($param)) { | ||
return $psPayment; | ||
} | ||
|
@@ -336,9 +338,9 @@ public function callApi($params, $payment, $type='transactions') | |
$params = $paramsObj->getParams(); | ||
$paramsString = $this->convertToCURLString($params); | ||
|
||
//$this->writeLog('Parameters being sent to API (/'.$type.'): '. var_export($params, true)); | ||
$this->writeLog('Parameters being sent to API (/'.$type.'): '. var_export($params, true)); | ||
|
||
//$this->writeLog('WSDL URL:'.$this->getWsUrl($type)); | ||
$this->writeLog('WSDL URL:'.$this->getWsUrl($type)); | ||
|
||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, $this->getWsUrl($type)); | ||
|
@@ -360,7 +362,7 @@ public function callApi($params, $payment, $type='transactions') | |
} | ||
curl_close($ch); | ||
|
||
// $this->writeLog('Retorno PagSeguro (/'.$type.'): ' . var_export($response, true)); | ||
$this->writeLog('Retorno PagSeguro (/'.$type.'): ' . var_export($response, true)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
|
||
|
||
$xml = \SimpleXML_Load_String(trim($response)); | ||
|
@@ -384,16 +386,16 @@ public function callApi($params, $payment, $type='transactions') | |
if (false === $xml) { | ||
switch($response){ | ||
case 'Unauthorized': | ||
// $this->writeLog( | ||
// 'Token / email not authorized by PagSeguro. Check your settings on the panel.' | ||
// ); | ||
$this->writeLog( | ||
'Token / email not authorized by PagSeguro. Check your settings on the panel.' | ||
); | ||
break; | ||
case 'Forbidden': | ||
//$this->writeLog('Unauthorized access to Api Pagseguro. Make sure you have permission to use this service. Return: ' . var_export($response, true) | ||
// ); | ||
$this->writeLog('Unauthorized access to Api Pagseguro. Make sure you have permission to use this service. Return: ' . var_export($response, true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
); | ||
break; | ||
default: | ||
// $this->writeLog('Unexpected return of PagSeguro. Return: ' . $response); | ||
$this->writeLog('Unexpected return of PagSeguro. Return: ' . $response); | ||
} | ||
throw new \Magento\Framework\Validator\Exception( | ||
'There was a problem processing your request / payment. Please contact us.' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
|
||
namespace RicardoMartins\PagSeguro\Logger\Handler; | ||
|
||
use Monolog\Logger; | ||
use Magento\Framework\Logger\Handler\Base; | ||
|
||
class Custom extends Base | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $fileName = '/var/log/pagseguro.log'; | ||
/** | ||
* @var int | ||
*/ | ||
protected $loggerType = Logger::DEBUG; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
|
||
<virtualType name="PagSeguroLogger" type="Magento\Framework\Logger\Monolog"> | ||
<arguments> | ||
<argument name="handlers" xsi:type="array"> | ||
<item name="debug" xsi:type="object">RicardoMartins\PagSeguro\Logger\Handler\Custom</item> | ||
</argument> | ||
</arguments> | ||
</virtualType> | ||
|
||
<type name="RicardoMartins\PagSeguro\Helper\Data"> | ||
<arguments> | ||
<argument name="customLogger" xsi:type="object">PagSeguroLogger</argument> | ||
</arguments> | ||
</type> | ||
|
||
</config> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm almost sure that you don't need the var_export, and $params can be passed as the second argument of writeLog method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@r-martins there's only 1 parameter in writeLog function. var_export is needed since $param was concatenated into a string, Otherwise the log will look like this: