Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Commit 3df3ec3

Browse files
authored
Add compatibility with One Step Checkout Brasil 6 Pro (inovarti)
Merge pull request #67 from pagseguro/desenvolvimento
2 parents f1c7e84 + 5ab857e commit 3df3ec3

File tree

21 files changed

+501
-120
lines changed

21 files changed

+501
-120
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Changelog
22
---------
3+
3.3.0
4+
- Adicionada compatibilidade com One Step Checkout Brasil 6 Pro (Inovarti)
5+
36
3.2.2
47
- Corrigido bug que não deixava visível o uso do checkout padrão/lightbox em alguns ambientes linux.
58

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Com o módulo instalado e configurado, você pode pode oferecer o PagSeguro como
3030
3131
- Certifique-se de que não há instalação de outros módulos para o PagSeguro em seu sistema;
3232
- Caso utilize a compilação do Magento, desative-a e limpe-a *(Sistema -> Ferramentas -> Compilação)*;
33-
- Baixe a última versão do módulo **[nesse link](https://github.com/pagseguro/magento/raw/master/UOL_PagSeguro-3.2.2.tgz)** ou então baixe o repositório como arquivo zip através do botão do GitHub;
33+
- Baixe a última versão do módulo **[nesse link](https://github.com/pagseguro/magento/raw/master/UOL_PagSeguro-3.3.0.tgz)** ou então baixe o repositório como arquivo zip através do botão do GitHub;
3434
- Na área administrativa do seu Magento, acesse o menu *Sistema/System -> Magento Connect -> Magento Connect Manager*. Caso tenha uma versão anterior do módulo instalada faça a remoção agora;
3535
- No Magento Connect Manger, dentro da seção Direct package file upload, clique em **Escolher arquivo/Choose file**, selecione o arquivo UOL_PagSeguro-x.x.x.tgz (baixado anteriormente), clique no botão de upload e acompanhe a instalação do módulo no console da página;
3636
- Caso utilize a compilação, volte para a área administrativa do Magento, ative-a e execute-a novamente;

UOL_PagSeguro-3.2.2.tgz

-486 KB
Binary file not shown.

UOL_PagSeguro-3.3.0.tgz

487 KB
Binary file not shown.
Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,52 @@
11
<?php
2+
23
/**
34
* Form block for boleto payment
45
*/
56
class UOL_PagSeguro_Block_Form_Boleto extends Mage_Payment_Block_Form
67
{
7-
protected function _construct()
8-
{
9-
parent::_construct();
10-
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
11-
$this->setBoletoSession($paymentModel->getSession());
12-
$this->setTemplate('uol/pagseguro/form/boleto.phtml');
13-
}
14-
15-
protected function _prepareLayout()
16-
{
17-
if ($this->getLayout()->getBlock('head')) {
18-
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
19-
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/boleto.js');
20-
$this->getLayout()->getBlock('head')->addItem('skin_css', 'uol/pagseguro/css/direct-payment.css');
8+
9+
protected function _construct()
10+
{
11+
parent::_construct();
12+
$this->initializePagSeguro();
2113
}
22-
}
23-
}
14+
15+
protected function _prepareLayout()
16+
{
17+
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
18+
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
19+
$directPaymentCss = 'uol/pagseguro/css/direct-payment-onestepcheckout.css';
20+
} else {
21+
$directPaymentCss = 'uol/pagseguro/css/direct-payment.css';
22+
}
23+
24+
if ($this->getLayout()->getBlock('head')) {
25+
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
26+
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/boleto.js');
27+
$this->getLayout()->getBlock('head')->addItem('skin_css', $directPaymentCss);
28+
}
29+
}
30+
31+
/**
32+
* Set variables to be used in pagseguro boleto form (boleto.phtml)
33+
*/
34+
private function initializePagSeguro()
35+
{
36+
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
37+
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
38+
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-onestepcheckout-before-save.js'));
39+
} else {
40+
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-before-save.js'));
41+
}
42+
// if customer is loged, get his document info (taxvat)
43+
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
44+
$customer = Mage::getSingleton('customer/session')->getCustomer();
45+
$this->setBoletoDocument($customer->getData()['taxvat']);
46+
}
47+
// set boleto session
48+
$this->setBoletoSession($paymentModel->getSession());
49+
// set template
50+
$this->setTemplate('uol/pagseguro/form/boleto.phtml');
51+
}
52+
}

app/code/community/UOL/PagSeguro/Block/Form/CreditCard.php

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,52 @@
44
*/
55
class UOL_PagSeguro_Block_Form_CreditCard extends Mage_Payment_Block_Form
66
{
7-
protected function _construct()
8-
{
9-
parent::_construct();
10-
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals()['grand_total'];
11-
$this->setGrandTotal($totals->getData()['value']);
12-
13-
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
14-
$this->setCreditCardSession($paymentModel->getSession());
15-
$this->setTemplate('uol/pagseguro/form/creditcard.phtml');
16-
}
7+
protected function _construct()
8+
{
9+
parent::_construct();
10+
$this->initializePagSeguro();
11+
}
12+
13+
protected function _prepareLayout()
14+
{
15+
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
16+
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
17+
$directPaymentCss = 'uol/pagseguro/css/direct-payment-onestepcheckout.css';
18+
} else {
19+
$directPaymentCss = 'uol/pagseguro/css/direct-payment.css';
20+
}
21+
22+
if ($this->getLayout()->getBlock('head')) {
23+
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
24+
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/credit-card.js');
25+
$this->getLayout()->getBlock('head')->addItem('skin_css', $directPaymentCss);
26+
}
27+
}
28+
29+
/**
30+
* Set variables to be used in pagseguro boleto form (boleto.phtml)
31+
*/
32+
private function initializePagSeguro()
33+
{
34+
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals()['grand_total'];
35+
$this->setGrandTotal($totals->getData()['value']);
36+
37+
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
1738

18-
protected function _prepareLayout()
19-
{
20-
if ($this->getLayout()->getBlock('head')) {
21-
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
22-
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/credit-card.js');
23-
$this->getLayout()->getBlock('head')->addItem('skin_css', 'uol/pagseguro/css/direct-payment.css');
39+
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
40+
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-onestepcheckout-before-save.js'));
41+
} else {
42+
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-before-save.js'));
43+
}
44+
// if customer is loged, get his document info (taxvat)
45+
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
46+
$customer = Mage::getSingleton('customer/session')->getCustomer();
47+
$document = (is_null($customer->getData()['taxvat'])) ? '' : $customer->getData()['taxvat'];
48+
$this->setCreditCardDocument($customer->getData()['taxvat']);
49+
}
50+
// set credit card session
51+
$this->setCreditCardSession($paymentModel->getSession());
52+
// set template
53+
$this->setTemplate('uol/pagseguro/form/creditcard.phtml');
2454
}
25-
}
2655
}

app/code/community/UOL/PagSeguro/Block/Form/OnlineDebit.php

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,48 @@
44
*/
55
class UOL_PagSeguro_Block_Form_OnlineDebit extends Mage_Payment_Block_Form
66
{
7-
protected function _construct()
8-
{
9-
parent::_construct();
10-
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
11-
$this->setOnlineDebitSession($paymentModel->getSession());
12-
$this->setTemplate('uol/pagseguro/form/onlinedebit.phtml');
13-
}
7+
protected function _construct()
8+
{
9+
parent::_construct();
10+
$this->initializePagSeguro();
11+
}
12+
13+
protected function _prepareLayout()
14+
{
15+
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
16+
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
17+
$directPaymentCss = 'uol/pagseguro/css/direct-payment-onestepcheckout.css';
18+
} else {
19+
$directPaymentCss = 'uol/pagseguro/css/direct-payment.css';
20+
}
21+
22+
if ($this->getLayout()->getBlock('head')) {
23+
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
24+
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/online-debit.js');
25+
$this->getLayout()->getBlock('head')->addItem('skin_css', $directPaymentCss);
26+
}
27+
}
1428

15-
protected function _prepareLayout()
16-
{
17-
if ($this->getLayout()->getBlock('head')) {
18-
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
19-
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/online-debit.js');
20-
$this->getLayout()->getBlock('head')->addItem('skin_css', 'uol/pagseguro/css/direct-payment.css');
29+
/**
30+
* Set variables to be used in pagseguro boleto form (boleto.phtml)
31+
*/
32+
private function initializePagSeguro()
33+
{
34+
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
35+
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
36+
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-onestepcheckout-before-save.js'));
37+
} else {
38+
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-before-save.js'));
39+
}
40+
// if customer is loged, get his document info (taxvat)
41+
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
42+
$customer = Mage::getSingleton('customer/session')->getCustomer();
43+
$document = (is_null($customer->getData()['taxvat'])) ? '' : $customer->getData()['taxvat'];
44+
$this->setOnlineDebitDocument($customer->getData()['taxvat']);
45+
}
46+
// set onlinne debit session
47+
$this->setOnlineDebitSession($paymentModel->getSession());
48+
// set template
49+
$this->setTemplate('uol/pagseguro/form/onlinedebit.phtml');
2150
}
22-
}
2351
}

app/code/community/UOL/PagSeguro/Model/OrderAddress.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,26 @@ public function getBillingAddress()
4646
private function setAddress(Mage_Sales_Model_Order_Address $address)
4747
{
4848
$response = new \PagSeguro\Domains\Address();
49-
$parse = $this->parseStreet($address->getStreet1());
50-
$response->setStreet($parse['street']);
51-
$response->setNumber($parse['number']);
52-
$response->setDistrict($address->getStreet2());
49+
50+
if (count($address->getStreet()) === 4) {
51+
//one step checkout default values
52+
$response->setStreet($address->getStreet1());
53+
$response->setNumber($address->getStreet2());
54+
$response->setComplement($address->getStreet3());
55+
$response->setDistrict($address->getStreet4());
56+
} else {
57+
//default configuration
58+
$parse = $this->parseStreet($address->getStreet1());
59+
$response->setStreet($parse['street']);
60+
$response->setNumber($parse['number']);
61+
$response->setDistrict($address->getStreet2());
62+
$response->setComplement($address->getStreet3());
63+
}
64+
5365
$response->setCity($address->getCity());
5466
$response->setPostalCode($address->getPostcode());
5567
$response->setState($this->getRegionAbbreviation($address));
5668
$response->setCountry($address->getCountry());
57-
$response->setComplement($address->getStreet3());
5869

5970
return $response;
6071
}

app/code/community/UOL/PagSeguro/Model/PaymentMethod.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,21 @@ private function payment($payment)
117117
$this->setItems($payment);
118118
$payment->setSender()->setName($this->order->getCustomerName());
119119
$payment->setSender()->setEmail($this->order->getCustomerEmail());
120-
$phone = $this->helper->formatPhone($this->order->getShippingAddress()->getTelephone());
121-
$payment->setSender()->setPhone()->withParameters($phone['areaCode'], $phone['number']);
122-
$orderAddress = new UOL_PagSeguro_Model_OrderAddress($this->order);
123-
$payment->setShipping()->setAddress()->instance($orderAddress->getShippingAddress());
124-
$payment->setShipping()->setType()->withParameters(SHIPPING_TYPE);
125-
$payment->setShipping()->setCost()->withParameters(number_format($this->order->getShippingAmount(), 2, '.',
126-
''));
120+
121+
if ($this->order->getShippingAddress() !== false) {
122+
$orderAddress = new UOL_PagSeguro_Model_OrderAddress($this->order);
123+
$payment->setShipping()->setAddress()->instance($orderAddress->getShippingAddress());
124+
$payment->setShipping()->setType()->withParameters(SHIPPING_TYPE);
125+
$payment->setShipping()->setCost()->withParameters(number_format($this->order->getShippingAmount(), 2, '.',
126+
''));
127+
//set phone
128+
if ($this->order->getShippingAddress()->getTelephone()) {
129+
$phone = $this->helper->formatPhone($this->order->getShippingAddress()->getTelephone());
130+
$payment->setSender()->setPhone()->withParameters($phone['areaCode'], $phone['number']);
131+
}
132+
133+
}
134+
127135
$payment->setExtraAmount($this->order->getBaseDiscountAmount() + $this->order->getTaxAmount());
128136
$payment->setNotificationUrl($this->getNotificationURL());
129137

@@ -282,4 +290,13 @@ public function getSession()
282290
}
283291
return $this->_session;
284292
}
293+
294+
/**
295+
* Return status (enabled or disabled) from the Inovarti One Step Checkout module
296+
* @return boolean
297+
*/
298+
public function getOneStepCheckoutIsEnabled()
299+
{
300+
return (Mage::getStoreConfig("onestepcheckout/general/is_enabled") == 1) ? true : false;
301+
}
285302
}

app/code/community/UOL/PagSeguro/controllers/PaymentController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public function defaultAction()
7878
try {
7979
/** @var Mage_Sales_Model_Order $order */
8080
$order = Mage::getModel('sales/order')->load($this->getCheckout()->getLastOrderId());
81+
82+
if(empty($order->getData())) {
83+
$this->norouteAction();
84+
return;
85+
}
86+
8187
$this->payment->setOrder($order);
8288
/**
8389
* @var \PagSeguro\Domains\Requests\DirectPayment\Boleto|\PagSeguro\Domains\Requests\DirectPayment\CreditCard|\PagSeguro\Domains\Requests\DirectPayment\OnlineDebit $payment
@@ -119,6 +125,11 @@ public function directAction()
119125
/** @var Mage_Sales_Model_Order $order */
120126
$order = Mage::getModel('sales/order')->load($this->getCheckout()->getLastOrderId());
121127

128+
if(empty($order->getData())) {
129+
$this->norouteAction();
130+
return;
131+
}
132+
122133
$customerPaymentData = Mage::getSingleton('customer/session')->getData();
123134

124135
$this->payment->setOrder($order);
@@ -173,6 +184,12 @@ public function lightboxAction()
173184
try {
174185
/** @var Mage_Sales_Model_Order $order */
175186
$order = Mage::getModel('sales/order')->load($this->getCheckout()->getLastOrderId());
187+
188+
if(empty($order->getData())) {
189+
$this->norouteAction();
190+
return;
191+
}
192+
176193
$this->payment->setOrder($order);
177194
/**
178195
* @var \PagSeguro\Domains\Requests\DirectPayment\Boleto|\PagSeguro\Domains\Requests\DirectPayment\CreditCard|\PagSeguro\Domains\Requests\DirectPayment\OnlineDebit $payment

0 commit comments

Comments
 (0)