Skip to content

Commit

Permalink
- Melhoria: adicionado suporte à novos status PagSeguro (Debitado e R…
Browse files Browse the repository at this point in the history
…etenção Temporária), fazendo com que pedidos sejam cancelados ou entrem em espera caso o comprador abra uma contestação junto ao cartão de crédito.

- Melhoria: Adiciona IP do comprador aos parâmetros enviados ao PagSeguro a fim de melhorar análise de fraude, em especial nos casos onde o sender_hash não foi enviado
  • Loading branch information
r-martins committed Sep 2, 2020
1 parent d1d324e commit 9d54839
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
16 changes: 16 additions & 0 deletions app/code/community/RicardoMartins/PagSeguro/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ public function getWsUrl($amend='', $useApp = false)
return Mage::getStoreConfig(self::XML_PATH_PAYMENT_PAGSEGURO_WS_URL) . $amend;
}


/**
* Returns Webservice V3 URL based on selected environment (prod or sandbox)
* This API endpoint should be used only for GET requests
*
* @param string $amend suffix
* @param bool $useApp uses app?
*
* @return string
*/
public function getWsV3Url($amend='', $useApp = false)
{
$url = $this->getWsUrl($amend, $useApp);
return str_ireplace('/v2/', '/v3/', $url);
}

/**
* Return PagSeguro's lib url based on selected environment (prod or sandbox)
* @return string
Expand Down
22 changes: 21 additions & 1 deletion app/code/community/RicardoMartins/PagSeguro/Helper/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ public function getSenderParams(Mage_Sales_Model_Order $order, $payment)
'senderCPF' => $digits->filter($cpf),
'senderAreaCode'=> $phone['area'],
'senderPhone' => $phone['number'],
'isSandbox' => (strpos('@sandbox.pagseguro', $customerEmail) !== false)
'isSandbox' => (strpos('@sandbox.pagseguro', $customerEmail) !== false),
);

$return = $this->addSenderIp($return);

if (strlen($return['senderCPF']) > 11) {
$return['senderCNPJ'] = $return['senderCPF'];
Expand Down Expand Up @@ -789,6 +790,25 @@ public function getPaymentParamsJson($paymentInfo)
)
)
);
}

/**
* Adds sender ip to $originalParameters array or return original array if unsuccessful or not ip_v4 address
* @param array $originalParameters
*
* @return array
*/
public function addSenderIp($originalParameters)
{
$senderIp = $_SERVER['REMOTE_ADDR'];

if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) { //Cloudflare
$senderIp = $_SERVER['HTTP_CF_CONNECTING_IP'];
}

if (false === filter_var($senderIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
return $originalParameters;

return array_merge($originalParameters, array('senderIp'=>$senderIp));
}
}
22 changes: 19 additions & 3 deletions app/code/community/RicardoMartins/PagSeguro/Model/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function proccessNotificatonResult(SimpleXMLElement $resultXML)

$message = $processedState->getMessage();

if ((int)$resultXML->status == 6) { //valor devolvido (gera credit memo e tenta cancelar o pedido)
if (in_array((int)$resultXML->status, array(6,8))) { //valor devolvido (gera credit memo e tenta cancelar o pedido)
if ($order->canUnhold()) {
$order->unhold();
}
Expand Down Expand Up @@ -220,7 +220,7 @@ public function getNotificationStatus($notificationCode)
{
$helper = Mage::helper('ricardomartins_pagseguro');
$useApp = $helper->getLicenseType() == 'app';
$url = $helper->getWsUrl('transactions/notifications/' . $notificationCode, $useApp);
$url = $helper->getWsV3Url('transactions/notifications/' . $notificationCode, $useApp);

$params = array('token' => $helper->getToken(), 'email' => $helper->getMerchantEmail());
if ($useApp) {
Expand Down Expand Up @@ -341,9 +341,25 @@ public function processStatus($statusCode)
if ($this->_order && Mage::helper('ricardomartins_pagseguro')->canRetryOrder($this->_order)) {
$return->setState(Mage_Sales_Model_Order::STATE_HOLDED);
$return->setIsCustomerNotified(false);
$return->setMessage('Retentativa: a transação ia ser cancelada (status 7), mas a opção de retentativa estava ativada. O pedido será cancelado posteriormente caso o cliente não use o link de retentativa no prazo estabelecido.');
$return->setMessage(
'Retentativa: a transação ia ser cancelada (status 7), mas '
. 'a opção de retentativa estava ativada. O pedido será cancelado posteriormente '
. 'caso o cliente não use o link de retentativa no prazo estabelecido.'
);
}
break;
case '8':
$return->setState(Mage_Sales_Model_Order::STATE_CANCELED);
$return->setIsCustomerNotified(false);
$return->setMessage('Debitado: o valor da transação foi devolvida ao comprador após processo'
. ' de disputa.');
break;
case '9':
$return->setState(Mage_Sales_Model_Order::STATE_HOLDED);
$return->setIsCustomerNotified(false);
$return->setMessage('Retenção Temporária: O comprador abriu uma solicitação de chargeback junto à'
. ' operadora do cartão de crédito.');
break;
default:
$return->setIsCustomerNotified(false);
$return->setStateChanged(false);
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/RicardoMartins/PagSeguro/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<RicardoMartins_PagSeguro>
<version>3.9.0</version>
<version>3.10.0</version>
</RicardoMartins_PagSeguro>
</modules>
<global>
Expand Down

0 comments on commit 9d54839

Please sign in to comment.