Skip to content

Commit

Permalink
Workaround para problemas com desconto em OneStepCheckout diversos por
Browse files Browse the repository at this point in the history
…@leuterio, com modificacoes. Mais detalhes em http://bit.ly/2A5SHk0. Fixes #251
  • Loading branch information
r-martins committed Nov 25, 2017
2 parents c12f395 + 86b61d3 commit 069aa5a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
20 changes: 17 additions & 3 deletions app/code/community/RicardoMartins/PagSeguro/Model/Payment/Cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public function assignData($data)
public function validate()
{
parent::validate();
$missingInfo = $this->getInfoInstance();

/** @var RicardoMartins_PagSeguro_Helper_Params $pHelper */
$pHelper = Mage::helper('ricardomartins_pagseguro/params');
Expand All @@ -131,14 +130,29 @@ public function validate()
$senderHash = $pHelper->getPaymentHash('sender_hash');
$creditCardToken = $pHelper->getPaymentHash('credit_card_token');

if (!$creditCardToken || !$senderHash) {
//mapeia a request URL atual
$controller = Mage::app()->getRequest()->getControllerName();
$action = Mage::app()->getRequest()->getActionName();
$route = Mage::app()->getRequest()->getRouteName();
$pathRequest = $route.'/'.$controller.'/'.$action;

//seta os paths para bloqueio de validação instantânea definidos no admin no array
$configPaths = Mage::getStoreConfig('payment/rm_pagseguro/exception_request_validate');
// $configPaths = explode(PHP_EOL, $configPaths);
$configPaths = preg_split('/\r\n|[\r\n]/', $configPaths);

//Valida token e hash se a request atual se encontra na lista de
//exceções do admin ou se a requisição vem de placeOrder
if ( (!$creditCardToken || !$senderHash) && !in_array($pathRequest, $configPaths)) {
$missingInfo = sprintf('Token do cartão: %s', var_export($creditCardToken, true));
$missingInfo .= sprintf('/ Sender_hash: %s', var_export($senderHash, true));
$missingInfo .= '/ URL desta requisição: ' . $pathRequest;
Mage::helper('ricardomartins_pagseguro')
->writeLog(
"Falha ao obter o token do cartao ou sender_hash.
Ative o modo debug e observe o console de erros do seu navegador.
Se esta for uma atualização via Ajax, ignore esta mensagem até a finalização do pedido.
Se esta for uma atualização via Ajax, ignore esta mensagem até a finalização do pedido, ou configure
a url de exceção.
$missingInfo"
);
Mage::throwException(
Expand Down
1 change: 1 addition & 0 deletions app/code/community/RicardoMartins/PagSeguro/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<sandbox_ws_url_app>https://ws.ricardomartins.net.br/pspro/v6/wspagseguro/sandbox/v2/</sandbox_ws_url_app>
<!--<sandbox_ws_url_app>http://ws.local.com.br/pspro/v6/wspagseguro/sandbox/v2/</sandbox_ws_url_app>-->
<sandbox_js_url>https://stc.sandbox.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.directpayment.js</sandbox_js_url>
<exception_request_validate>onestepcheckout/ajax/savePaymentMethod</exception_request_validate>
</rm_pagseguro>
<rm_pagseguro_kiosk>
<active>0</active>
Expand Down
11 changes: 10 additions & 1 deletion app/code/community/RicardoMartins/PagSeguro/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@
<show_in_store>0</show_in_store>
<comment><![CDATA[Caso sua loja utilize um atributo personalizado para o campo 'Bairro' de entrega, selecione aqui.]]></comment>
</address_neighborhood_attribute>
<exception_request_validate>
<label>Bloquear Validação Instantânea</label>
<frontend_type>textarea</frontend_type>
<sort_order>80</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<comment><![CDATA[Informe as URLs (um por linha) que deseja desativar validação imediata. Informe URLs vindas de atualizações via Ajax em seu checkout e que validam o meio de pagamento. Ex.: onestepcheckout/ajax/savePaymentMethod <br/>Para mais informações, consulte <a href="//pagsegurotransparente.zendesk.com/hc/pt-br/articles/115003006172" target="_blank">este artigo</a>.]]></comment>
</exception_request_validate>
</fields>
</rm_pagseguro>
<rm_pagseguro_cc module="ricardomartins_pagseguro">
Expand Down Expand Up @@ -379,4 +388,4 @@
</groups>
</payment>
</sections>
</config>
</config>

0 comments on commit 069aa5a

Please sign in to comment.