Skip to content

Commit

Permalink
Atualiza módulo
Browse files Browse the repository at this point in the history
  • Loading branch information
netojoaobatista committed Jan 4, 2023
1 parent 9105e99 commit 257b110
Show file tree
Hide file tree
Showing 19 changed files with 205 additions and 230 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ scripts/dev-ssl/*
scripts/etc/dev-ssl/
scripts/etc/nginx/conf.d/
app/code/Rede/Adquirencia/vendor/
vendor/
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,30 @@ public function beforeSetLayout(View $view)
$logger->pushHandler(new StreamHandler(BP . '/var/log/rede.log', Logger::DEBUG));
$logger->info('Log Rede');

$transaction = (new eRede($store, $logger))->get($payment->getAdditionalInformation('Id Transação'));
$status = $transaction->getAuthorization()->getStatus();
$tid = $payment->getAdditionalInformation('Id Transação');

if ($status != $oldstatus) {
switch ($status) {
case 'Approved':
$order->setState(Order::STATE_PROCESSING);
break;
case 'Canceled':
case 'Denied':
$order->setState(Order::STATE_CANCELED);
break;
case 'Pending':
$order->setState(Order::STATE_PENDING_PAYMENT);
break;
}
if (!empty($tid)) {
$transaction = (new eRede($store, $logger))->get();
$status = $transaction->getAuthorization()->getStatus();

if ($status != $oldstatus) {
switch ($status) {
case 'Approved':
$order->setState(Order::STATE_PROCESSING);
break;
case 'Canceled':
case 'Denied':
$order->setState(Order::STATE_CANCELED);
break;
case 'Pending':
$order->setState(Order::STATE_PENDING_PAYMENT);
break;
}

$payment->setAdditionalInformation('Status da Autorização', $status);
$order->addStatusHistoryComment(sprintf('Status updated to %s', $status));
$order->save();
$payment->setAdditionalInformation('Status da Autorização', $status);
$order->addStatusHistoryComment(sprintf('Status updated to %s', $status));
$order->save();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Rede\Adquirencia\Gateway\Config\Config;
use Rede\Adquirencia\Gateway\Helper\SubjectReader;


/**
* Payment Data Builder
*/
Expand All @@ -35,6 +34,7 @@ abstract class AbstractPaymentDataBuilder implements BuilderInterface
public const PAYMENT = 'Payment';
public const SERVICETAXAMOUNT = 'ServiceTaxAmount';
public const INSTALLMENTS = 'Installments';
public const DEVICE = 'Device';
public const INTEREST = 'Interest';
public const CAPTURE = 'Capture';
public const AUTHENTICATE = 'Authenticate';
Expand Down Expand Up @@ -137,7 +137,12 @@ public function build(array $buildSubject)
self::INSTALLMENTS => $installments,
self::SOFTDESCRIPTOR => $this->config->getSoftDescriptor(),
self::TYPE => $this->getTypeTransaction($buildSubject),
self::AMOUNT => $order->getGrandTotalAmount()
self::AMOUNT => $order->getGrandTotalAmount(),
self::DEVICE => [
'color_depth' => (int)$payment->getAdditionalInformation('color_depth'),
'screen_width' => (int)$payment->getAdditionalInformation('screen_width'),
'screen_height' => (int)$payment->getAdditionalInformation('screen_height')
]
]
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,18 @@ public function build(array $buildSubject)
self::CREDIT_CARD => [
self::CARDNUMBER => $payment->getCcNumber(),
self::HOLDER => $payment->getCcOwner(),
self::EXPIRATIONDATE => str_pad($payment->getCcExpMonth(), 2, '0',
STR_PAD_LEFT) . '/' . $payment->getCcExpYear(),
self::SECURITYCODE => $payment->getCcCid()
self::EXPIRATIONDATE => str_pad(
$payment->getCcExpMonth(),
2,
'0',
STR_PAD_LEFT
) . '/' . $payment->getCcExpYear(),
self::SECURITYCODE => $payment->getCcCid(),
AbstractPaymentDataBuilder::DEVICE => [
'color_depth' => (int)$payment->getAdditionalInformation('color_depth'),
'screen_width' => (int)$payment->getAdditionalInformation('screen_width'),
'screen_height' => (int)$payment->getAdditionalInformation('screen_height')
]
]
]
];
Expand Down
23 changes: 11 additions & 12 deletions app/code/Rede/Adquirencia/Gateway/Response/CardDetailsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
namespace Rede\Adquirencia\Gateway\Response;

use Magento\Payment\Gateway\Response\HandlerInterface;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Rede\Adquirencia\Gateway\Config\Config;
use Rede\Adquirencia\Gateway\Helper\SubjectReader;
use Rede\Transaction;
Expand Down Expand Up @@ -43,6 +45,7 @@ public function __construct(SubjectReader $subjectReader, Config $config)
*/
public function handle(array $handlingSubject, array $response)
{

$paymentDO = $this->subjectReader->readPayment($handlingSubject);
$payment = $paymentDO->getPayment();

Expand All @@ -58,17 +61,13 @@ public function handle(array $handlingSubject, array $response)

// set card details to additional info
$cardNumberFull = $response_obj->getCardNumber();
$cardNumberFirstSix = substr($cardNumberFull, 0, 6);
$cardNumberLastFour= substr($cardNumberFull, -4);



$payment->setAdditionalInformation('Titular do Cartao', $response_obj->getCardHolderName());
$payment->setAdditionalInformation('Numero do Cartão - 6 Primeiros 4 Utimos', "$cardNumberFirstSix - $cardNumberLastFour");
$payment->setAdditionalInformation('Ambiente', $this->config->getEnvironment());


$cardNumberFirstSix = substr($cardNumberFull, 0, 6);
$cardNumberLastFour = substr($cardNumberFull, -4);
$payment->setAdditionalInformation('Titular do Cartao', $response_obj->getCardHolderName());
$payment->setAdditionalInformation(
'Numero do Cartão - 6 Primeiros 4 Utimos',
"$cardNumberFirstSix - $cardNumberLastFour"
);
$payment->setAdditionalInformation('Ambiente', $this->config->getEnvironment());
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public function handle(array $handlingSubject, array $response)
$payment->setAdditionalInformation('Messagem de Retorno', $response_obj->getReturnMessage());
$payment->setAdditionalInformation('Parcelas', $response_obj->getInstallments());

$threeDS = $response_obj->getThreeDSecure();

if (!is_null($threeDS)) {
$authentication = $threeDS->getUrl();

if (!empty($authentication)) {
$payment->setAdditionalInformation('URL de autenticação', $authentication);
}
}

$payment->setAdditionalInformation('Id Transação', $response_obj->getTid());
$payment->setAdditionalInformation('Id Refund', $response_obj->getRefundId());
$payment->setAdditionalInformation('Id Cancel', $response_obj->getCancelId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Rede\Adquirencia\Gateway\Response;

use Exception;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Rede\Adquirencia\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Response\HandlerInterface;
use Magento\Sales\Model\Order\Payment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ class AuthorizeValidator extends GeneralResponseValidator
*/
protected function getResponseValidators()
{
return array_merge(
$response = array_merge(
parent::getResponseValidators(),
[
function ($response) {
$responseCode = $response->getReturnCode();

return [
$response->getReturnCode() == '00',
$responseCode === '00' || $responseCode === '220',
sprintf('[Rede %d] - %s', $response->getReturnCode(), $response->getReturnMessage())
];
}
]
);


return $response;
}
}
81 changes: 39 additions & 42 deletions app/code/Rede/Adquirencia/Model/Adapter/RedeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use Monolog\Handler\StreamHandler;
use Rede\Adquirencia\Gateway\Config\Config;
use Rede\Adquirencia\Model\Adminhtml\Source\Environment;
use Rede\Device;
use Rede\eRede;
use Rede\Store;
use Rede\ThreeDSecure;
use Rede\Transaction;
use Rede\Url;

Expand Down Expand Up @@ -54,15 +54,8 @@ public function authorize(array $attributes, $capture = false)
$payment = $attributes['Sale']['Payment'];
$pv = $this->config->getPv();
$token = $this->config->getToken();
$environment = \Rede\Environment::production();
$environment = $this->config->getEnvironment() === 'test' ? \Rede\Environment::sandbox() : \Rede\Environment::production();
$softDescriptor = $this->config->getSoftDescriptor();
$module = $this->config->getModule();
$gateway = $this->config->getGateway();

if ($this->config->getEnvironment() == 'test') {
$environment = \Rede\Environment::sandbox();
}

$store = new Store($pv, $token, $environment);
$expiration = [];
$expirationMonth = '';
Expand All @@ -74,25 +67,17 @@ public function authorize(array $attributes, $capture = false)
}

$transaction = new Transaction($payment['Amount'], $attributes['Sale']['orderId'] + time());
$debit = false;

if ($this->config->isDebitEnabled() && $payment['Type'] == 'DebitCard') {
if ($this->config->isDebitEnabled() && $payment['Type'] == 'debit') {
$debit = true;
$transaction->debitCard(
$payment['CreditCard']['CardNumber'],
$payment['CreditCard']['SecurityCode'],
$expirationMonth,
$expirationYear,
$payment['CreditCard']['Holder']
);

$transaction->threeDSecure(ThreeDSecure::DECLINE_ON_FAILURE);

$objectManager = ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');

$baseurl = $storeManager->getStore()->getBaseUrl();

$transaction->addUrl($baseurl . 'checkout/onepage/success/', Url::THREE_D_SECURE_SUCCESS);
$transaction->addUrl($baseurl . 'checkout/onepage/success/', Url::THREE_D_SECURE_FAILURE);
} else {
$transaction->creditCard(
$payment['CreditCard']['CardNumber'],
Expand All @@ -103,31 +88,38 @@ public function authorize(array $attributes, $capture = false)
)->setInstallments($payment['Installments'] ?? 1);

$transaction->capture($capture);

// if ($this->config->is3DSEnabled()) {
// if ($payment['Authenticate'] && $payment['Amount'] > $this->config->getThresholdAmount()) {
// $transaction->threeDSecure(\Rede\ThreeDSecure::DECLINE_ON_FAILURE);
//
// $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
// $storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
//
// $baseurl = $storeManager->getStore()->getBaseUrl();
//
// $transaction->addUrl($baseurl . 'checkout/onepage/success/', \Rede\Url::THREE_D_SECURE_SUCCESS);
// $transaction->addUrl($baseurl . 'checkout/onepage/success/', \Rede\Url::THREE_D_SECURE_FAILURE);
// }
// }
}

if (!empty($softDescriptor)) {
$transaction->setSoftDescriptor($softDescriptor);
}

$logger = new \Monolog\Logger('rede');
$logger->pushHandler(new StreamHandler(BP . '/var/log/rede.log', \Monolog\Logger::DEBUG));
$logger->info('Log Rede');

$logger->debug(print_r($payment, true));
if ($debit || $this->config->is3DSEnabled()) {
if ($debit || $payment['Amount'] > $this->config->getThresholdAmount()) {
$transaction->threeDSecure(
new Device(
ColorDepth: $payment['Device']['color_depth'],
DeviceType3ds: 'BROWSER',
JavaEnabled: true,
Language: 'BR',
ScreenHeight: $payment['Device']['screen_height'],
ScreenWidth: $payment['Device']['screen_width']
)
);

$objectManager = ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');

$baseurl = $storeManager->getStore()->getBaseUrl();

$transaction->addUrl($baseurl . 'checkout/onepage/success/', Url::THREE_D_SECURE_SUCCESS);
$transaction->addUrl($baseurl . 'checkout/onepage/success/', Url::THREE_D_SECURE_FAILURE);
}
}

if (!empty($softDescriptor)) {
$transaction->setSoftDescriptor($softDescriptor);
}

try {
$transaction = (new eRede($store, $logger))->create($transaction);
Expand Down Expand Up @@ -156,7 +148,10 @@ public function capture(array $data)
$transaction = null;

try {
$transaction = (new eRede($store, $logger))->capture((new Transaction($data['AMOUNT']))->setTid($data['TID']));
$transaction = (new eRede(
$store,
$logger
))->capture((new Transaction($data['AMOUNT']))->setTid($data['TID']));
} catch (Exception $e) {
$logger->error($e->getMessage());
}
Expand All @@ -182,7 +177,10 @@ public function void(array $data)
$transaction = null;

try {
$transaction = (new eRede($store, $logger))->cancel((new Transaction($data['AMOUNT']))->setTid($data['TID']));
$transaction = (new eRede(
$store,
$logger
))->cancel((new Transaction($data['AMOUNT']))->setTid($data['TID']));
} catch (Exception $e) {
$logger->error($e->getMessage());
}
Expand All @@ -204,5 +202,4 @@ public function getMerchant()
{
return new Merchant($this->config->getPv(), $this->config->getToken());
}

}
22 changes: 18 additions & 4 deletions app/code/Rede/Adquirencia/Observer/DataAssignObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function execute(Observer $observer)
$paymentMethod = $this->readMethodArgument($observer);

$payment = $observer->getPaymentModel();

if (!$payment instanceof InfoInterface) {
$payment = $paymentMethod->getInfoInstance();
}
Expand All @@ -44,8 +44,22 @@ public function execute(Observer $observer)
}

if ($additionalData->getData('number_of_installments')) {
$payment->setAdditionalInformation('number_of_installments',
$additionalData->getData('number_of_installments'));
$payment->setAdditionalInformation(
'number_of_installments',
$additionalData->getData('number_of_installments')
);
}

if ($additionalData->getData('color_depth')) {
$payment->setAdditionalInformation('color_depth', $additionalData->getData('color_depth'));
}

if ($additionalData->getData('screen_height')) {
$payment->setAdditionalInformation('screen_height', $additionalData->getData('screen_height'));
}

if ($additionalData->getData('screen_width')) {
$payment->setAdditionalInformation('screen_width', $additionalData->getData('screen_width'));
}

$type = 'credit';
Expand All @@ -54,7 +68,7 @@ public function execute(Observer $observer)
$type = $additionalData->getData('credit_debit');
}

$payment->setAdditionalInformation('credit_debit',$type);
$payment->setAdditionalInformation('credit_debit', $type);

$payment->setCcLast4(substr($additionalData->getData('cc_number'), -4));
$payment->setCcNumberEnc($payment->encrypt($additionalData->getData('cc_number')));
Expand Down
Loading

0 comments on commit 257b110

Please sign in to comment.