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

Commit

Permalink
Merge pull request #66 from gabriellucius/desenvolvimento
Browse files Browse the repository at this point in the history
Add compatibility with One Step Checkout Brasil 6 Pro (inovarti)
  • Loading branch information
s2it-moscou committed Oct 19, 2017
2 parents e5373e6 + 39ce1f5 commit 5ab857e
Show file tree
Hide file tree
Showing 21 changed files with 501 additions and 120 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Changelog
---------
3.3.0
- Adicionada compatibilidade com One Step Checkout Brasil 6 Pro (Inovarti)

3.2.2
- Corrigido bug que não deixava visível o uso do checkout padrão/lightbox em alguns ambientes linux.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Com o módulo instalado e configurado, você pode pode oferecer o PagSeguro como
- Certifique-se de que não há instalação de outros módulos para o PagSeguro em seu sistema;
- Caso utilize a compilação do Magento, desative-a e limpe-a *(Sistema -> Ferramentas -> Compilação)*;
- 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;
- 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;
- 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;
- 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;
- Caso utilize a compilação, volte para a área administrativa do Magento, ative-a e execute-a novamente;
Expand Down
Binary file removed UOL_PagSeguro-3.2.2.tgz
Binary file not shown.
Binary file added UOL_PagSeguro-3.3.0.tgz
Binary file not shown.
61 changes: 45 additions & 16 deletions app/code/community/UOL/PagSeguro/Block/Form/Boleto.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
<?php

/**
* Form block for boleto payment
*/
class UOL_PagSeguro_Block_Form_Boleto extends Mage_Payment_Block_Form
{
protected function _construct()
{
parent::_construct();
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
$this->setBoletoSession($paymentModel->getSession());
$this->setTemplate('uol/pagseguro/form/boleto.phtml');
}

protected function _prepareLayout()
{
if ($this->getLayout()->getBlock('head')) {
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/boleto.js');
$this->getLayout()->getBlock('head')->addItem('skin_css', 'uol/pagseguro/css/direct-payment.css');

protected function _construct()
{
parent::_construct();
$this->initializePagSeguro();
}
}
}

protected function _prepareLayout()
{
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
$directPaymentCss = 'uol/pagseguro/css/direct-payment-onestepcheckout.css';
} else {
$directPaymentCss = 'uol/pagseguro/css/direct-payment.css';
}

if ($this->getLayout()->getBlock('head')) {
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/boleto.js');
$this->getLayout()->getBlock('head')->addItem('skin_css', $directPaymentCss);
}
}

/**
* Set variables to be used in pagseguro boleto form (boleto.phtml)
*/
private function initializePagSeguro()
{
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-onestepcheckout-before-save.js'));
} else {
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-before-save.js'));
}
// if customer is loged, get his document info (taxvat)
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
$this->setBoletoDocument($customer->getData()['taxvat']);
}
// set boleto session
$this->setBoletoSession($paymentModel->getSession());
// set template
$this->setTemplate('uol/pagseguro/form/boleto.phtml');
}
}
63 changes: 46 additions & 17 deletions app/code/community/UOL/PagSeguro/Block/Form/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,52 @@
*/
class UOL_PagSeguro_Block_Form_CreditCard extends Mage_Payment_Block_Form
{
protected function _construct()
{
parent::_construct();
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals()['grand_total'];
$this->setGrandTotal($totals->getData()['value']);

$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
$this->setCreditCardSession($paymentModel->getSession());
$this->setTemplate('uol/pagseguro/form/creditcard.phtml');
}
protected function _construct()
{
parent::_construct();
$this->initializePagSeguro();
}

protected function _prepareLayout()
{
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
$directPaymentCss = 'uol/pagseguro/css/direct-payment-onestepcheckout.css';
} else {
$directPaymentCss = 'uol/pagseguro/css/direct-payment.css';
}

if ($this->getLayout()->getBlock('head')) {
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/credit-card.js');
$this->getLayout()->getBlock('head')->addItem('skin_css', $directPaymentCss);
}
}

/**
* Set variables to be used in pagseguro boleto form (boleto.phtml)
*/
private function initializePagSeguro()
{
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals()['grand_total'];
$this->setGrandTotal($totals->getData()['value']);

$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');

protected function _prepareLayout()
{
if ($this->getLayout()->getBlock('head')) {
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/credit-card.js');
$this->getLayout()->getBlock('head')->addItem('skin_css', 'uol/pagseguro/css/direct-payment.css');
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-onestepcheckout-before-save.js'));
} else {
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-before-save.js'));
}
// if customer is loged, get his document info (taxvat)
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
$document = (is_null($customer->getData()['taxvat'])) ? '' : $customer->getData()['taxvat'];
$this->setCreditCardDocument($customer->getData()['taxvat']);
}
// set credit card session
$this->setCreditCardSession($paymentModel->getSession());
// set template
$this->setTemplate('uol/pagseguro/form/creditcard.phtml');
}
}
}
56 changes: 42 additions & 14 deletions app/code/community/UOL/PagSeguro/Block/Form/OnlineDebit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,48 @@
*/
class UOL_PagSeguro_Block_Form_OnlineDebit extends Mage_Payment_Block_Form
{
protected function _construct()
{
parent::_construct();
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
$this->setOnlineDebitSession($paymentModel->getSession());
$this->setTemplate('uol/pagseguro/form/onlinedebit.phtml');
}
protected function _construct()
{
parent::_construct();
$this->initializePagSeguro();
}

protected function _prepareLayout()
{
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
$directPaymentCss = 'uol/pagseguro/css/direct-payment-onestepcheckout.css';
} else {
$directPaymentCss = 'uol/pagseguro/css/direct-payment.css';
}

if ($this->getLayout()->getBlock('head')) {
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/online-debit.js');
$this->getLayout()->getBlock('head')->addItem('skin_css', $directPaymentCss);
}
}

protected function _prepareLayout()
{
if ($this->getLayout()->getBlock('head')) {
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/direct-payment.js');
$this->getLayout()->getBlock('head')->addItem('skin_js', 'uol/pagseguro/js/online-debit.js');
$this->getLayout()->getBlock('head')->addItem('skin_css', 'uol/pagseguro/css/direct-payment.css');
/**
* Set variables to be used in pagseguro boleto form (boleto.phtml)
*/
private function initializePagSeguro()
{
$paymentModel = Mage::getSingleton('UOL_PagSeguro_Model_PaymentMethod');
if ($paymentModel->getOneStepCheckoutIsEnabled()) {
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-onestepcheckout-before-save.js'));
} else {
$this->setPagSeguroBeforeSaveJsSkinUrl($this->getSkinUrl('uol/pagseguro/js/pagseguro-before-save.js'));
}
// if customer is loged, get his document info (taxvat)
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
$document = (is_null($customer->getData()['taxvat'])) ? '' : $customer->getData()['taxvat'];
$this->setOnlineDebitDocument($customer->getData()['taxvat']);
}
// set onlinne debit session
$this->setOnlineDebitSession($paymentModel->getSession());
// set template
$this->setTemplate('uol/pagseguro/form/onlinedebit.phtml');
}
}
}
21 changes: 16 additions & 5 deletions app/code/community/UOL/PagSeguro/Model/OrderAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,26 @@ public function getBillingAddress()
private function setAddress(Mage_Sales_Model_Order_Address $address)
{
$response = new \PagSeguro\Domains\Address();
$parse = $this->parseStreet($address->getStreet1());
$response->setStreet($parse['street']);
$response->setNumber($parse['number']);
$response->setDistrict($address->getStreet2());

if (count($address->getStreet()) === 4) {
//one step checkout default values
$response->setStreet($address->getStreet1());
$response->setNumber($address->getStreet2());
$response->setComplement($address->getStreet3());
$response->setDistrict($address->getStreet4());
} else {
//default configuration
$parse = $this->parseStreet($address->getStreet1());
$response->setStreet($parse['street']);
$response->setNumber($parse['number']);
$response->setDistrict($address->getStreet2());
$response->setComplement($address->getStreet3());
}

$response->setCity($address->getCity());
$response->setPostalCode($address->getPostcode());
$response->setState($this->getRegionAbbreviation($address));
$response->setCountry($address->getCountry());
$response->setComplement($address->getStreet3());

return $response;
}
Expand Down
31 changes: 24 additions & 7 deletions app/code/community/UOL/PagSeguro/Model/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,21 @@ private function payment($payment)
$this->setItems($payment);
$payment->setSender()->setName($this->order->getCustomerName());
$payment->setSender()->setEmail($this->order->getCustomerEmail());
$phone = $this->helper->formatPhone($this->order->getShippingAddress()->getTelephone());
$payment->setSender()->setPhone()->withParameters($phone['areaCode'], $phone['number']);
$orderAddress = new UOL_PagSeguro_Model_OrderAddress($this->order);
$payment->setShipping()->setAddress()->instance($orderAddress->getShippingAddress());
$payment->setShipping()->setType()->withParameters(SHIPPING_TYPE);
$payment->setShipping()->setCost()->withParameters(number_format($this->order->getShippingAmount(), 2, '.',
''));

if ($this->order->getShippingAddress() !== false) {
$orderAddress = new UOL_PagSeguro_Model_OrderAddress($this->order);
$payment->setShipping()->setAddress()->instance($orderAddress->getShippingAddress());
$payment->setShipping()->setType()->withParameters(SHIPPING_TYPE);
$payment->setShipping()->setCost()->withParameters(number_format($this->order->getShippingAmount(), 2, '.',
''));
//set phone
if ($this->order->getShippingAddress()->getTelephone()) {
$phone = $this->helper->formatPhone($this->order->getShippingAddress()->getTelephone());
$payment->setSender()->setPhone()->withParameters($phone['areaCode'], $phone['number']);
}

}

$payment->setExtraAmount($this->order->getBaseDiscountAmount() + $this->order->getTaxAmount());
$payment->setNotificationUrl($this->getNotificationURL());

Expand Down Expand Up @@ -282,4 +290,13 @@ public function getSession()
}
return $this->_session;
}

/**
* Return status (enabled or disabled) from the Inovarti One Step Checkout module
* @return boolean
*/
public function getOneStepCheckoutIsEnabled()
{
return (Mage::getStoreConfig("onestepcheckout/general/is_enabled") == 1) ? true : false;
}
}
17 changes: 17 additions & 0 deletions app/code/community/UOL/PagSeguro/controllers/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public function defaultAction()
try {
/** @var Mage_Sales_Model_Order $order */
$order = Mage::getModel('sales/order')->load($this->getCheckout()->getLastOrderId());

if(empty($order->getData())) {
$this->norouteAction();
return;
}

$this->payment->setOrder($order);
/**
* @var \PagSeguro\Domains\Requests\DirectPayment\Boleto|\PagSeguro\Domains\Requests\DirectPayment\CreditCard|\PagSeguro\Domains\Requests\DirectPayment\OnlineDebit $payment
Expand Down Expand Up @@ -119,6 +125,11 @@ public function directAction()
/** @var Mage_Sales_Model_Order $order */
$order = Mage::getModel('sales/order')->load($this->getCheckout()->getLastOrderId());

if(empty($order->getData())) {
$this->norouteAction();
return;
}

$customerPaymentData = Mage::getSingleton('customer/session')->getData();

$this->payment->setOrder($order);
Expand Down Expand Up @@ -173,6 +184,12 @@ public function lightboxAction()
try {
/** @var Mage_Sales_Model_Order $order */
$order = Mage::getModel('sales/order')->load($this->getCheckout()->getLastOrderId());

if(empty($order->getData())) {
$this->norouteAction();
return;
}

$this->payment->setOrder($order);
/**
* @var \PagSeguro\Domains\Requests\DirectPayment\Boleto|\PagSeguro\Domains\Requests\DirectPayment\CreditCard|\PagSeguro\Domains\Requests\DirectPayment\OnlineDebit $payment
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/UOL/PagSeguro/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.
<config>
<modules>
<UOL_PagSeguro>
<version>3.2.2</version>
<version>3.3.0</version>
</UOL_PagSeguro>
</modules>
<global>
Expand Down
6 changes: 6 additions & 0 deletions app/design/frontend/base/default/layout/uol/pagseguro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ limitations under the License.
template="uol/pagseguro/loading.phtml"/>
</reference>
</checkout_onepage_index>

<onestepcheckout_index_index>
<reference name="head">
<block type="uol_pagseguro/payment" name="loading" template="uol/pagseguro/loading.phtml"/>
</reference>
</onestepcheckout_index_index>

<catalog_product_view>
<reference name="head">
Expand Down
Loading

0 comments on commit 5ab857e

Please sign in to comment.