diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c95c78..129c73d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 0f2b81f..03a228f 100644 --- a/README.md +++ b/README.md @@ -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; diff --git a/UOL_PagSeguro-3.2.2.tgz b/UOL_PagSeguro-3.2.2.tgz deleted file mode 100644 index 8feb47a..0000000 Binary files a/UOL_PagSeguro-3.2.2.tgz and /dev/null differ diff --git a/UOL_PagSeguro-3.3.0.tgz b/UOL_PagSeguro-3.3.0.tgz new file mode 100644 index 0000000..5e79de7 Binary files /dev/null and b/UOL_PagSeguro-3.3.0.tgz differ diff --git a/app/code/community/UOL/PagSeguro/Block/Form/Boleto.php b/app/code/community/UOL/PagSeguro/Block/Form/Boleto.php index e4bd30b..efa4899 100644 --- a/app/code/community/UOL/PagSeguro/Block/Form/Boleto.php +++ b/app/code/community/UOL/PagSeguro/Block/Form/Boleto.php @@ -1,23 +1,52 @@ 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(); } - } -} \ No newline at end of file + + 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'); + } +} diff --git a/app/code/community/UOL/PagSeguro/Block/Form/CreditCard.php b/app/code/community/UOL/PagSeguro/Block/Form/CreditCard.php index 9d8a143..0093ac7 100644 --- a/app/code/community/UOL/PagSeguro/Block/Form/CreditCard.php +++ b/app/code/community/UOL/PagSeguro/Block/Form/CreditCard.php @@ -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'); } - } } diff --git a/app/code/community/UOL/PagSeguro/Block/Form/OnlineDebit.php b/app/code/community/UOL/PagSeguro/Block/Form/OnlineDebit.php index a0e7045..276ae65 100644 --- a/app/code/community/UOL/PagSeguro/Block/Form/OnlineDebit.php +++ b/app/code/community/UOL/PagSeguro/Block/Form/OnlineDebit.php @@ -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'); } - } } diff --git a/app/code/community/UOL/PagSeguro/Model/OrderAddress.php b/app/code/community/UOL/PagSeguro/Model/OrderAddress.php index 7884b14..71b1490 100644 --- a/app/code/community/UOL/PagSeguro/Model/OrderAddress.php +++ b/app/code/community/UOL/PagSeguro/Model/OrderAddress.php @@ -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; } diff --git a/app/code/community/UOL/PagSeguro/Model/PaymentMethod.php b/app/code/community/UOL/PagSeguro/Model/PaymentMethod.php index edbaff3..457f701 100644 --- a/app/code/community/UOL/PagSeguro/Model/PaymentMethod.php +++ b/app/code/community/UOL/PagSeguro/Model/PaymentMethod.php @@ -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()); @@ -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; + } } diff --git a/app/code/community/UOL/PagSeguro/controllers/PaymentController.php b/app/code/community/UOL/PagSeguro/controllers/PaymentController.php index 8025f5a..ee944f0 100644 --- a/app/code/community/UOL/PagSeguro/controllers/PaymentController.php +++ b/app/code/community/UOL/PagSeguro/controllers/PaymentController.php @@ -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 @@ -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); @@ -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 diff --git a/app/code/community/UOL/PagSeguro/etc/config.xml b/app/code/community/UOL/PagSeguro/etc/config.xml index f7d27a8..c312c55 100644 --- a/app/code/community/UOL/PagSeguro/etc/config.xml +++ b/app/code/community/UOL/PagSeguro/etc/config.xml @@ -19,7 +19,7 @@ limitations under the License. - 3.2.2 + 3.3.0 diff --git a/app/design/frontend/base/default/layout/uol/pagseguro.xml b/app/design/frontend/base/default/layout/uol/pagseguro.xml index 4dad35c..613b252 100644 --- a/app/design/frontend/base/default/layout/uol/pagseguro.xml +++ b/app/design/frontend/base/default/layout/uol/pagseguro.xml @@ -168,6 +168,12 @@ limitations under the License. template="uol/pagseguro/loading.phtml"/> + + + + + + diff --git a/app/design/frontend/base/default/template/uol/pagseguro/form/boleto.phtml b/app/design/frontend/base/default/template/uol/pagseguro/form/boleto.phtml index 0c219f3..ef55175 100644 --- a/app/design/frontend/base/default/template/uol/pagseguro/form/boleto.phtml +++ b/app/design/frontend/base/default/template/uol/pagseguro/form/boleto.phtml @@ -1,28 +1,40 @@ @@ -30,18 +42,18 @@ var x = document.getElementsByTagName("script");
- +
diff --git a/app/design/frontend/base/default/template/uol/pagseguro/form/creditcard.phtml b/app/design/frontend/base/default/template/uol/pagseguro/form/creditcard.phtml index 34279d4..70555b2 100644 --- a/app/design/frontend/base/default/template/uol/pagseguro/form/creditcard.phtml +++ b/app/design/frontend/base/default/template/uol/pagseguro/form/creditcard.phtml @@ -1,16 +1,28 @@