Skip to content

Commit 257b110

Browse files
Atualiza módulo
1 parent 9105e99 commit 257b110

File tree

19 files changed

+205
-230
lines changed

19 files changed

+205
-230
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ scripts/dev-ssl/*
88
scripts/etc/dev-ssl/
99
scripts/etc/nginx/conf.d/
1010
app/code/Rede/Adquirencia/vendor/
11+
vendor/

app/code/Rede/Adquirencia/Block/Adminhtml/View/TransactionUpdate.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,30 @@ public function beforeSetLayout(View $view)
5858
$logger->pushHandler(new StreamHandler(BP . '/var/log/rede.log', Logger::DEBUG));
5959
$logger->info('Log Rede');
6060

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

64-
if ($status != $oldstatus) {
65-
switch ($status) {
66-
case 'Approved':
67-
$order->setState(Order::STATE_PROCESSING);
68-
break;
69-
case 'Canceled':
70-
case 'Denied':
71-
$order->setState(Order::STATE_CANCELED);
72-
break;
73-
case 'Pending':
74-
$order->setState(Order::STATE_PENDING_PAYMENT);
75-
break;
76-
}
63+
if (!empty($tid)) {
64+
$transaction = (new eRede($store, $logger))->get();
65+
$status = $transaction->getAuthorization()->getStatus();
66+
67+
if ($status != $oldstatus) {
68+
switch ($status) {
69+
case 'Approved':
70+
$order->setState(Order::STATE_PROCESSING);
71+
break;
72+
case 'Canceled':
73+
case 'Denied':
74+
$order->setState(Order::STATE_CANCELED);
75+
break;
76+
case 'Pending':
77+
$order->setState(Order::STATE_PENDING_PAYMENT);
78+
break;
79+
}
7780

78-
$payment->setAdditionalInformation('Status da Autorização', $status);
79-
$order->addStatusHistoryComment(sprintf('Status updated to %s', $status));
80-
$order->save();
81+
$payment->setAdditionalInformation('Status da Autorização', $status);
82+
$order->addStatusHistoryComment(sprintf('Status updated to %s', $status));
83+
$order->save();
84+
}
8185
}
8286
}
8387
}

app/code/Rede/Adquirencia/Gateway/Request/AbstractPaymentDataBuilder.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Rede\Adquirencia\Gateway\Config\Config;
1212
use Rede\Adquirencia\Gateway\Helper\SubjectReader;
1313

14-
1514
/**
1615
* Payment Data Builder
1716
*/
@@ -35,6 +34,7 @@ abstract class AbstractPaymentDataBuilder implements BuilderInterface
3534
public const PAYMENT = 'Payment';
3635
public const SERVICETAXAMOUNT = 'ServiceTaxAmount';
3736
public const INSTALLMENTS = 'Installments';
37+
public const DEVICE = 'Device';
3838
public const INTEREST = 'Interest';
3939
public const CAPTURE = 'Capture';
4040
public const AUTHENTICATE = 'Authenticate';
@@ -137,7 +137,12 @@ public function build(array $buildSubject)
137137
self::INSTALLMENTS => $installments,
138138
self::SOFTDESCRIPTOR => $this->config->getSoftDescriptor(),
139139
self::TYPE => $this->getTypeTransaction($buildSubject),
140-
self::AMOUNT => $order->getGrandTotalAmount()
140+
self::AMOUNT => $order->getGrandTotalAmount(),
141+
self::DEVICE => [
142+
'color_depth' => (int)$payment->getAdditionalInformation('color_depth'),
143+
'screen_width' => (int)$payment->getAdditionalInformation('screen_width'),
144+
'screen_height' => (int)$payment->getAdditionalInformation('screen_height')
145+
]
141146
]
142147
];
143148

app/code/Rede/Adquirencia/Gateway/Request/CreditCardDataBuilder.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,18 @@ public function build(array $buildSubject)
5353
self::CREDIT_CARD => [
5454
self::CARDNUMBER => $payment->getCcNumber(),
5555
self::HOLDER => $payment->getCcOwner(),
56-
self::EXPIRATIONDATE => str_pad($payment->getCcExpMonth(), 2, '0',
57-
STR_PAD_LEFT) . '/' . $payment->getCcExpYear(),
58-
self::SECURITYCODE => $payment->getCcCid()
56+
self::EXPIRATIONDATE => str_pad(
57+
$payment->getCcExpMonth(),
58+
2,
59+
'0',
60+
STR_PAD_LEFT
61+
) . '/' . $payment->getCcExpYear(),
62+
self::SECURITYCODE => $payment->getCcCid(),
63+
AbstractPaymentDataBuilder::DEVICE => [
64+
'color_depth' => (int)$payment->getAdditionalInformation('color_depth'),
65+
'screen_width' => (int)$payment->getAdditionalInformation('screen_width'),
66+
'screen_height' => (int)$payment->getAdditionalInformation('screen_height')
67+
]
5968
]
6069
]
6170
];

app/code/Rede/Adquirencia/Gateway/Response/CardDetailsHandler.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Rede\Adquirencia\Gateway\Response;
88

99
use Magento\Payment\Gateway\Response\HandlerInterface;
10+
use Monolog\Handler\StreamHandler;
11+
use Monolog\Logger;
1012
use Rede\Adquirencia\Gateway\Config\Config;
1113
use Rede\Adquirencia\Gateway\Helper\SubjectReader;
1214
use Rede\Transaction;
@@ -43,6 +45,7 @@ public function __construct(SubjectReader $subjectReader, Config $config)
4345
*/
4446
public function handle(array $handlingSubject, array $response)
4547
{
48+
4649
$paymentDO = $this->subjectReader->readPayment($handlingSubject);
4750
$payment = $paymentDO->getPayment();
4851

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

5962
// set card details to additional info
6063
$cardNumberFull = $response_obj->getCardNumber();
61-
$cardNumberFirstSix = substr($cardNumberFull, 0, 6);
62-
$cardNumberLastFour= substr($cardNumberFull, -4);
63-
64-
65-
66-
$payment->setAdditionalInformation('Titular do Cartao', $response_obj->getCardHolderName());
67-
$payment->setAdditionalInformation('Numero do Cartão - 6 Primeiros 4 Utimos', "$cardNumberFirstSix - $cardNumberLastFour");
68-
$payment->setAdditionalInformation('Ambiente', $this->config->getEnvironment());
69-
70-
64+
$cardNumberFirstSix = substr($cardNumberFull, 0, 6);
65+
$cardNumberLastFour = substr($cardNumberFull, -4);
66+
$payment->setAdditionalInformation('Titular do Cartao', $response_obj->getCardHolderName());
67+
$payment->setAdditionalInformation(
68+
'Numero do Cartão - 6 Primeiros 4 Utimos',
69+
"$cardNumberFirstSix - $cardNumberLastFour"
70+
);
71+
$payment->setAdditionalInformation('Ambiente', $this->config->getEnvironment());
7172
}
72-
7373
}
74-

app/code/Rede/Adquirencia/Gateway/Response/PaymentDetailsHandler.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ public function handle(array $handlingSubject, array $response)
6363
$payment->setAdditionalInformation('Messagem de Retorno', $response_obj->getReturnMessage());
6464
$payment->setAdditionalInformation('Parcelas', $response_obj->getInstallments());
6565

66+
$threeDS = $response_obj->getThreeDSecure();
67+
68+
if (!is_null($threeDS)) {
69+
$authentication = $threeDS->getUrl();
70+
71+
if (!empty($authentication)) {
72+
$payment->setAdditionalInformation('URL de autenticação', $authentication);
73+
}
74+
}
75+
6676
$payment->setAdditionalInformation('Id Transação', $response_obj->getTid());
6777
$payment->setAdditionalInformation('Id Refund', $response_obj->getRefundId());
6878
$payment->setAdditionalInformation('Id Cancel', $response_obj->getCancelId());

app/code/Rede/Adquirencia/Gateway/Response/TransactionIdHandler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Rede\Adquirencia\Gateway\Response;
77

88
use Exception;
9+
use Monolog\Handler\StreamHandler;
10+
use Monolog\Logger;
911
use Rede\Adquirencia\Gateway\Helper\SubjectReader;
1012
use Magento\Payment\Gateway\Response\HandlerInterface;
1113
use Magento\Sales\Model\Order\Payment;

app/code/Rede/Adquirencia/Gateway/Validator/AuthorizeValidator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ class AuthorizeValidator extends GeneralResponseValidator
1616
*/
1717
protected function getResponseValidators()
1818
{
19-
return array_merge(
19+
$response = array_merge(
2020
parent::getResponseValidators(),
2121
[
2222
function ($response) {
23+
$responseCode = $response->getReturnCode();
24+
2325
return [
24-
$response->getReturnCode() == '00',
26+
$responseCode === '00' || $responseCode === '220',
2527
sprintf('[Rede %d] - %s', $response->getReturnCode(), $response->getReturnMessage())
2628
];
2729
}
2830
]
2931
);
32+
33+
34+
return $response;
3035
}
3136
}

app/code/Rede/Adquirencia/Model/Adapter/RedeAdapter.php

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
use Monolog\Handler\StreamHandler;
1313
use Rede\Adquirencia\Gateway\Config\Config;
1414
use Rede\Adquirencia\Model\Adminhtml\Source\Environment;
15+
use Rede\Device;
1516
use Rede\eRede;
1617
use Rede\Store;
17-
use Rede\ThreeDSecure;
1818
use Rede\Transaction;
1919
use Rede\Url;
2020

@@ -54,15 +54,8 @@ public function authorize(array $attributes, $capture = false)
5454
$payment = $attributes['Sale']['Payment'];
5555
$pv = $this->config->getPv();
5656
$token = $this->config->getToken();
57-
$environment = \Rede\Environment::production();
57+
$environment = $this->config->getEnvironment() === 'test' ? \Rede\Environment::sandbox() : \Rede\Environment::production();
5858
$softDescriptor = $this->config->getSoftDescriptor();
59-
$module = $this->config->getModule();
60-
$gateway = $this->config->getGateway();
61-
62-
if ($this->config->getEnvironment() == 'test') {
63-
$environment = \Rede\Environment::sandbox();
64-
}
65-
6659
$store = new Store($pv, $token, $environment);
6760
$expiration = [];
6861
$expirationMonth = '';
@@ -74,25 +67,17 @@ public function authorize(array $attributes, $capture = false)
7467
}
7568

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

78-
if ($this->config->isDebitEnabled() && $payment['Type'] == 'DebitCard') {
72+
if ($this->config->isDebitEnabled() && $payment['Type'] == 'debit') {
73+
$debit = true;
7974
$transaction->debitCard(
8075
$payment['CreditCard']['CardNumber'],
8176
$payment['CreditCard']['SecurityCode'],
8277
$expirationMonth,
8378
$expirationYear,
8479
$payment['CreditCard']['Holder']
8580
);
86-
87-
$transaction->threeDSecure(ThreeDSecure::DECLINE_ON_FAILURE);
88-
89-
$objectManager = ObjectManager::getInstance();
90-
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
91-
92-
$baseurl = $storeManager->getStore()->getBaseUrl();
93-
94-
$transaction->addUrl($baseurl . 'checkout/onepage/success/', Url::THREE_D_SECURE_SUCCESS);
95-
$transaction->addUrl($baseurl . 'checkout/onepage/success/', Url::THREE_D_SECURE_FAILURE);
9681
} else {
9782
$transaction->creditCard(
9883
$payment['CreditCard']['CardNumber'],
@@ -103,31 +88,38 @@ public function authorize(array $attributes, $capture = false)
10388
)->setInstallments($payment['Installments'] ?? 1);
10489

10590
$transaction->capture($capture);
106-
107-
// if ($this->config->is3DSEnabled()) {
108-
// if ($payment['Authenticate'] && $payment['Amount'] > $this->config->getThresholdAmount()) {
109-
// $transaction->threeDSecure(\Rede\ThreeDSecure::DECLINE_ON_FAILURE);
110-
//
111-
// $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
112-
// $storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
113-
//
114-
// $baseurl = $storeManager->getStore()->getBaseUrl();
115-
//
116-
// $transaction->addUrl($baseurl . 'checkout/onepage/success/', \Rede\Url::THREE_D_SECURE_SUCCESS);
117-
// $transaction->addUrl($baseurl . 'checkout/onepage/success/', \Rede\Url::THREE_D_SECURE_FAILURE);
118-
// }
119-
// }
120-
}
121-
122-
if (!empty($softDescriptor)) {
123-
$transaction->setSoftDescriptor($softDescriptor);
12491
}
12592

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

130-
$logger->debug(print_r($payment, true));
97+
if ($debit || $this->config->is3DSEnabled()) {
98+
if ($debit || $payment['Amount'] > $this->config->getThresholdAmount()) {
99+
$transaction->threeDSecure(
100+
new Device(
101+
ColorDepth: $payment['Device']['color_depth'],
102+
DeviceType3ds: 'BROWSER',
103+
JavaEnabled: true,
104+
Language: 'BR',
105+
ScreenHeight: $payment['Device']['screen_height'],
106+
ScreenWidth: $payment['Device']['screen_width']
107+
)
108+
);
109+
110+
$objectManager = ObjectManager::getInstance();
111+
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
112+
113+
$baseurl = $storeManager->getStore()->getBaseUrl();
114+
115+
$transaction->addUrl($baseurl . 'checkout/onepage/success/', Url::THREE_D_SECURE_SUCCESS);
116+
$transaction->addUrl($baseurl . 'checkout/onepage/success/', Url::THREE_D_SECURE_FAILURE);
117+
}
118+
}
119+
120+
if (!empty($softDescriptor)) {
121+
$transaction->setSoftDescriptor($softDescriptor);
122+
}
131123

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

158150
try {
159-
$transaction = (new eRede($store, $logger))->capture((new Transaction($data['AMOUNT']))->setTid($data['TID']));
151+
$transaction = (new eRede(
152+
$store,
153+
$logger
154+
))->capture((new Transaction($data['AMOUNT']))->setTid($data['TID']));
160155
} catch (Exception $e) {
161156
$logger->error($e->getMessage());
162157
}
@@ -182,7 +177,10 @@ public function void(array $data)
182177
$transaction = null;
183178

184179
try {
185-
$transaction = (new eRede($store, $logger))->cancel((new Transaction($data['AMOUNT']))->setTid($data['TID']));
180+
$transaction = (new eRede(
181+
$store,
182+
$logger
183+
))->cancel((new Transaction($data['AMOUNT']))->setTid($data['TID']));
186184
} catch (Exception $e) {
187185
$logger->error($e->getMessage());
188186
}
@@ -204,5 +202,4 @@ public function getMerchant()
204202
{
205203
return new Merchant($this->config->getPv(), $this->config->getToken());
206204
}
207-
208205
}

app/code/Rede/Adquirencia/Observer/DataAssignObserver.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function execute(Observer $observer)
3434
$paymentMethod = $this->readMethodArgument($observer);
3535

3636
$payment = $observer->getPaymentModel();
37-
37+
3838
if (!$payment instanceof InfoInterface) {
3939
$payment = $paymentMethod->getInfoInstance();
4040
}
@@ -44,8 +44,22 @@ public function execute(Observer $observer)
4444
}
4545

4646
if ($additionalData->getData('number_of_installments')) {
47-
$payment->setAdditionalInformation('number_of_installments',
48-
$additionalData->getData('number_of_installments'));
47+
$payment->setAdditionalInformation(
48+
'number_of_installments',
49+
$additionalData->getData('number_of_installments')
50+
);
51+
}
52+
53+
if ($additionalData->getData('color_depth')) {
54+
$payment->setAdditionalInformation('color_depth', $additionalData->getData('color_depth'));
55+
}
56+
57+
if ($additionalData->getData('screen_height')) {
58+
$payment->setAdditionalInformation('screen_height', $additionalData->getData('screen_height'));
59+
}
60+
61+
if ($additionalData->getData('screen_width')) {
62+
$payment->setAdditionalInformation('screen_width', $additionalData->getData('screen_width'));
4963
}
5064

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

57-
$payment->setAdditionalInformation('credit_debit',$type);
71+
$payment->setAdditionalInformation('credit_debit', $type);
5872

5973
$payment->setCcLast4(substr($additionalData->getData('cc_number'), -4));
6074
$payment->setCcNumberEnc($payment->encrypt($additionalData->getData('cc_number')));

0 commit comments

Comments
 (0)