diff --git a/Controller/Direct/Boleto.php b/Controller/Direct/Boleto.php
index 3b81c3b..27b3ed6 100644
--- a/Controller/Direct/Boleto.php
+++ b/Controller/Direct/Boleto.php
@@ -41,6 +41,9 @@ class Boleto extends \Magento\Framework\App\Action\Action
/** @var \Magento\Framework\Controller\Result\Json */
protected $result;
+ /** @var Magento\Sales\Model\Order */
+ protected $order;
+
/**
* Boleto payment constructor.
* @param \Magento\Framework\App\Action\Context $context
@@ -62,12 +65,13 @@ public function __construct(
public function execute()
{
try {
+ $this->order = $this->loadOrder();
/** @var \UOL\PagSeguro\Model\Direct\BoletoMethod $boleto */
$boleto = new BoletoMethod(
$this->_objectManager->create('Magento\Directory\Api\CountryInformationAcquirerInterface'),
$this->_objectManager->create('Magento\Framework\App\Config\ScopeConfigInterface'),
$this->_objectManager->create('Magento\Framework\Module\ModuleList'),
- $this->loadOrder(),
+ $this->order,
$this->_objectManager->create('UOL\PagSeguro\Helper\Library'),
$data = [
'sender_document' => $this->helperData()->formatDocument($this->getRequest()->getParam('sender_document')),
@@ -77,7 +81,9 @@ public function execute()
);
return $this->placeOrder($boleto);
} catch (\Exception $exception) {
- $this->changeOrderHistory('pagseguro_cancelada');
+ if (!is_null($this->order)) {
+ $this->changeOrderHistory('pagseguro_cancelada');
+ }
$this->clearSession();
return $this->whenError($exception->getMessage());
}
@@ -189,7 +195,13 @@ private function baseUrl()
*/
private function lastRealOrderId()
{
- return $this->_objectManager->create('\Magento\Checkout\Model\Session')->getLastRealOrder()->getId();
+ $lastRealOrderId = $this->_objectManager->create('\Magento\Checkout\Model\Session')->getLastRealOrder()->getId();
+
+ if (is_null($lastRealOrderId)) {
+ throw new \Exception("There is no order associated with this session.");
+ }
+
+ return $lastRealOrderId;
}
/**
@@ -209,10 +221,9 @@ private function session()
*/
private function changeOrderHistory($status)
{
- $order = $this->loadOrder();
/** change payment status in magento */
- $order->addStatusToHistory($status, null, true);
+ $this->order->addStatusToHistory($status, null, true);
/** save order */
- $order->save();
+ $this->order->save();
}
}
diff --git a/Controller/Direct/Debit.php b/Controller/Direct/Debit.php
index 276ff19..55ed37d 100755
--- a/Controller/Direct/Debit.php
+++ b/Controller/Direct/Debit.php
@@ -41,6 +41,9 @@ class Debit extends \Magento\Framework\App\Action\Action
/** @var \Magento\Framework\Controller\Result\Json */
protected $result;
+ /** @var Magento\Sales\Model\Order */
+ protected $order;
+
/**
* Checkout constructor.
* @param \Magento\Framework\App\Action\Context $context
@@ -63,11 +66,12 @@ public function __construct(
public function execute()
{
try {
+ $this->order = $this->loadOrder();
$debit = new DebitMethod(
$this->_objectManager->create('Magento\Directory\Api\CountryInformationAcquirerInterface'),
$this->_objectManager->create('Magento\Framework\App\Config\ScopeConfigInterface'),
$this->_objectManager->create('Magento\Framework\Module\ModuleList'),
- $this->loadOrder(),
+ $this->order,
$this->_objectManager->create('UOL\PagSeguro\Helper\Library'),
$data = [
'sender_document' => $this->helperData()->formatDocument($this->getRequest()->getParam('sender_document')),
@@ -78,7 +82,9 @@ public function execute()
);
return $this->placeOrder($debit);
} catch (\Exception $exception) {
- $this->changeOrderHistory('pagseguro_cancelada');
+ if (!is_null($this->order)) {
+ $this->changeOrderHistory('pagseguro_cancelada');
+ }
$this->clearSession();
return $this->whenError($exception->getMessage());
}
@@ -226,8 +232,14 @@ private function baseUrl()
* @return string id
*/
private function lastRealOrderId()
- {
- return $this->_objectManager->create('\Magento\Checkout\Model\Session')->getLastRealOrder()->getId();
+ {
+ $lastRealOrderId = $this->_objectManager->create('\Magento\Checkout\Model\Session')->getLastRealOrder()->getId();
+
+ if (is_null($lastRealOrderId)) {
+ throw new \Exception("There is no order associated with this session.");
+ }
+
+ return $lastRealOrderId;
}
/**
@@ -247,10 +259,10 @@ private function session()
*/
private function changeOrderHistory($status)
{
- $order = $this->loadOrder();
/** change payment status in magento */
- $order->addStatusToHistory($status, null, true);
+ $this->order->addStatusToHistory($status, null, true);
+
/** save order */
- $order->save();
+ $this->order->save();
}
}
diff --git a/Controller/Direct/Installments.php b/Controller/Direct/Installments.php
index ef898c9..0f9a845 100644
--- a/Controller/Direct/Installments.php
+++ b/Controller/Direct/Installments.php
@@ -43,6 +43,9 @@ class Installments extends \Magento\Framework\App\Action\Action
/** @var \Magento\Framework\Controller\Result\Json */
protected $result;
+ /** @var Magento\Sales\Model\Order */
+ protected $order;
+
/**
* installments constructor
* @param \Magento\Framework\App\Action\Context $context
@@ -56,6 +59,7 @@ public function __construct(
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->result = $this->resultJsonFactory->create();
+ $this->order = null;
}
/**
@@ -65,10 +69,11 @@ public function __construct(
public function execute()
{
try {
+ $this->order = $this->loadOrder();
$installments = new InstallmentsMethod(
$this->_objectManager->create('Magento\Framework\App\Config\ScopeConfigInterface'),
$this->_objectManager->create('Magento\Framework\Module\ModuleList'),
- $this->loadOrder(),
+ $this->order,
$this->_objectManager->create('UOL\PagSeguro\Helper\Library'),
$data = [
'brand' => $this->getRequest()->getParam('credit_card_brand'),
@@ -77,9 +82,13 @@ public function execute()
);
return $this->place($installments);
- } catch (\Exception $exception) {
- $this->changeOrderHistory('pagseguro_cancelada');
+ }
+ catch (\Exception $exception) {
+ if (!is_null($this->order)) {
+ $this->changeOrderHistory('pagseguro_cancelada');
+ }
$this->clearSession();
+
return $this->whenError($exception->getMessage());
}
}
@@ -170,10 +179,17 @@ private function baseUrl()
* Get last real order id
*
* @return string id
+ * @throws \Exception
*/
private function lastRealOrderId()
{
- return $this->_objectManager->create('\Magento\Checkout\Model\Session')->getLastRealOrder()->getId();
+ $lastRealOrderId = $this->_objectManager->create('\Magento\Checkout\Model\Session')->getLastRealOrder()->getId();
+
+ if (is_null($lastRealOrderId)) {
+ throw new \Exception("There is no order associated with this session.");
+ }
+
+ return $lastRealOrderId;
}
/**
@@ -193,10 +209,10 @@ private function session()
*/
private function changeOrderHistory($status)
{
- $order = $this->loadOrder();
/** change payment status in magento */
- $order->addStatusToHistory($status, null, true);
+ $this->order->addStatusToHistory($status, null, true);
+
/** save order */
- $order->save();
+ $this->order->save();
}
}
diff --git a/Model/Direct/BoletoMethod.php b/Model/Direct/BoletoMethod.php
index b0f5ce8..c2524b5 100644
--- a/Model/Direct/BoletoMethod.php
+++ b/Model/Direct/BoletoMethod.php
@@ -293,14 +293,14 @@ private function setShippingInformation()
{
$shipping = $this->getShippingData();
$address = \UOL\PagSeguro\Helper\Data::addressConfig($shipping['street']);
-
+
$this->_paymentRequest->setShipping()->setAddress()->withParameters(
$this->getShippingAddress($address[0], $shipping),
$this->getShippingAddress($address[1]),
$this->getShippingAddress($address[0]),
- \UOL\PagSeguro\Helper\Data::fixPostalCode($shipping['postcode']),
- $shipping['city'],
- $this->getRegionAbbreviation($shipping['region']),
+ \UOL\PagSeguro\Helper\Data::fixPostalCode($shipping->getPostcode()),
+ $shipping->getCity(),
+ $this->getRegionAbbreviation($shipping),
$this->getCountryName($shipping['country_id']),
$this->getShippingAddress($address[2])
);
@@ -360,15 +360,20 @@ private function getOrderStoreReference()
/**
* Get a brazilian region name and return the abbreviation if it exists
*
- * @param string $regionName
+ * @param shipping $shipping
* @return string
*/
- private function getRegionAbbreviation($regionName)
+ private function getRegionAbbreviation($shipping)
{
+ if (strlen($shipping->getRegionCode()) == 2) {
+ return $shipping->getRegionCode();
+ }
+
$regionAbbreviation = new \PagSeguro\Enum\Address();
- return (is_string($regionAbbreviation->getType($regionName))) ?
- $regionAbbreviation->getType($regionName) :
- $regionName;
+
+ return (is_string($regionAbbreviation->getType($shipping->getRegion()))) ?
+ $regionAbbreviation->getType($shipping->getRegion()) :
+ $shipping->getRegion();
}
/**
diff --git a/Model/Direct/CreditCardMethod.php b/Model/Direct/CreditCardMethod.php
index 6ef7147..156a818 100644
--- a/Model/Direct/CreditCardMethod.php
+++ b/Model/Direct/CreditCardMethod.php
@@ -255,9 +255,9 @@ private function setBillingInformation()
$this->getShippingAddress($address[0], $billing),
$this->getShippingAddress($address[1]),
$this->getShippingAddress($address[0]),
- \UOL\PagSeguro\Helper\Data::fixPostalCode($billing['postcode']),
- $billing['city'],
- $this->getRegionAbbreviation($billing['region']),
+ \UOL\PagSeguro\Helper\Data::fixPostalCode($billing->getPostcode()),
+ $billing->getCity(),
+ $this->getRegionAbbreviation($billing),
$this->getCountryName($billing['country_id']),
$this->getShippingAddress($address[2])
);
@@ -374,9 +374,9 @@ private function setShippingInformation()
$this->getShippingAddress($address[0], $shipping),
$this->getShippingAddress($address[1]),
$this->getShippingAddress($address[0]),
- \UOL\PagSeguro\Helper\Data::fixPostalCode($shipping['postcode']),
- $shipping['city'],
- $this->getRegionAbbreviation($shipping['region']),
+ \UOL\PagSeguro\Helper\Data::fixPostalCode($shipping->getPostcode()),
+ $shipping->getCity(),
+ $this->getRegionAbbreviation($shipping),
$this->getCountryName($shipping['country_id']),
$this->getShippingAddress($address[2])
);
@@ -436,15 +436,20 @@ private function getOrderStoreReference()
/**
* Get a brazilian region name and return the abbreviation if it exists
*
- * @param string $regionName
+ * @param shipping $shipping
* @return string
*/
- private function getRegionAbbreviation($regionName)
+ private function getRegionAbbreviation($shipping)
{
+ if (strlen($shipping->getRegionCode()) == 2) {
+ return $shipping->getRegionCode();
+ }
+
$regionAbbreviation = new \PagSeguro\Enum\Address();
- return (is_string($regionAbbreviation->getType($regionName))) ?
- $regionAbbreviation->getType($regionName) :
- $regionName;
+
+ return (is_string($regionAbbreviation->getType($shipping->getRegion()))) ?
+ $regionAbbreviation->getType($shipping->getRegion()) :
+ $shipping->getRegion();
}
/**
diff --git a/Model/Direct/DebitMethod.php b/Model/Direct/DebitMethod.php
index b41a3bc..656a75d 100644
--- a/Model/Direct/DebitMethod.php
+++ b/Model/Direct/DebitMethod.php
@@ -304,9 +304,9 @@ private function setShippingInformation()
$this->getShippingAddress($address[0], $shipping),
$this->getShippingAddress($address[1]),
$this->getShippingAddress($address[0]),
- \UOL\PagSeguro\Helper\Data::fixPostalCode($shipping['postcode']),
- $shipping['city'],
- $this->getRegionAbbreviation($shipping['region']),
+ \UOL\PagSeguro\Helper\Data::fixPostalCode($shipping->getPostcode()),
+ $shipping->getCity(),
+ $this->getRegionAbbreviation($shipping),
$this->getCountryName($shipping['country_id']),
$this->getShippingAddress($address[2])
);
@@ -366,15 +366,20 @@ private function getOrderStoreReference()
/**
* Get a brazilian region name and return the abbreviation if it exists
*
- * @param string $regionName
+ * @param shipping $shipping
* @return string
*/
- private function getRegionAbbreviation($regionName)
+ private function getRegionAbbreviation($shipping)
{
+ if (strlen($shipping->getRegionCode()) == 2) {
+ return $shipping->getRegionCode();
+ }
+
$regionAbbreviation = new \PagSeguro\Enum\Address();
- return (is_string($regionAbbreviation->getType($regionName))) ?
- $regionAbbreviation->getType($regionName) :
- $regionName;
+
+ return (is_string($regionAbbreviation->getType($shipping->getRegion()))) ?
+ $regionAbbreviation->getType($shipping->getRegion()) :
+ $shipping->getRegion();
}
/**
diff --git a/Model/Direct/InstallmentsMethod.php b/Model/Direct/InstallmentsMethod.php
index ce5d241..9de98d4 100644
--- a/Model/Direct/InstallmentsMethod.php
+++ b/Model/Direct/InstallmentsMethod.php
@@ -89,11 +89,11 @@ public function create($amount = false, $maxInstallment = false)
try {
$this->config();
$this->setOptions($this->getTotalAmount($amount), $this->getBrand());
-
$installments = \PagSeguro\Services\Installment::create(
$this->_library->getPagSeguroCredentials(),
$this->getOptions()
);
+
return $this->output($installments->getInstallments(), $maxInstallment);
} catch (PagSeguroServiceException $exception) {
throw $exception;
diff --git a/Model/PaymentMethod.php b/Model/PaymentMethod.php
index db7fc83..27e5023 100644
--- a/Model/PaymentMethod.php
+++ b/Model/PaymentMethod.php
@@ -152,16 +152,16 @@ private function setSenderInformation()
private function setShippingInformation()
{
$shipping = $this->getShippingData();
- $country = $this->getCountryName($shipping['country_id']);
$address = \UOL\PagSeguro\Helper\Data::addressConfig($shipping['street']);
+
$this->_paymentRequest->setShipping()->setAddress()->withParameters(
$this->getShippingAddress($address[0], $shipping),
$this->getShippingAddress($address[1]),
$this->getShippingAddress($address[3]),
- \UOL\PagSeguro\Helper\Data::fixPostalCode($shipping['postcode']),
- $shipping['city'],
- $this->getRegionAbbreviation($shipping['region']),
- $country,
+ \UOL\PagSeguro\Helper\Data::fixPostalCode($shipping->getPostcode()),
+ $shipping->getCity(),
+ $this->getRegionAbbreviation($shipping),
+ $this->getCountryName($shipping['country_id']),
$this->getShippingAddress($address[2])
);
}
@@ -234,13 +234,20 @@ private function getOrderStoreReference()
/**
* Get a brazilian region name and return the abbreviation if it exists
*
- * @param string $regionName
+ * @param shipping $shipping
* @return string
*/
- private function getRegionAbbreviation($regionName)
+ private function getRegionAbbreviation($shipping)
{
+ if (strlen($shipping->getRegionCode()) == 2) {
+ return $shipping->getRegionCode();
+ }
+
$regionAbbreviation = new \PagSeguro\Enum\Address();
- return (is_string($regionAbbreviation->getType($regionName))) ? $regionAbbreviation->getType($regionName) : $regionName;
+
+ return (is_string($regionAbbreviation->getType($shipping->getRegion()))) ?
+ $regionAbbreviation->getType($shipping->getRegion()) :
+ $shipping->getRegion();
}
/**
diff --git a/Observer/CreatePagSeguroOrder.php b/Observer/CreatePagSeguroOrder.php
index 7587013..1f40f66 100644
--- a/Observer/CreatePagSeguroOrder.php
+++ b/Observer/CreatePagSeguroOrder.php
@@ -93,7 +93,7 @@ public function __construct(
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
- {
+ {
$order = $observer->getEvent()->getOrder();
//verify pagseguro transaction
diff --git a/README.md b/README.md
index 999d556..e5556eb 100644
--- a/README.md
+++ b/README.md
@@ -25,15 +25,33 @@ Requisitos
Instalação
-----------
+Navegue até o diretório raíz da sua instalação do Magento 2 e siga os seguintes passos:
1. Instale via packagist
- - ```composer require pagseguro/magento2```
-2. Execute os comandos:
- - ```php bin/magento setup:upgrade```
- - ```php bin/magento setup:static-content:deploy```
+ - ```composer require pagseguro/magento2```
+ - Neste momento, podem ser solicitadas suas credenciais de autenticação do Magento. Caso tenha alguma dúvida, há uma descrição de como proceder nesse [link da documentação oficial](http://devdocs.magento.com/guides/v2.0/install-gde/prereq/connect-auth.html).
+2. Execute os comandos:
+ - ```php bin/magento setup:upgrade```
+ - ```php bin/magento setup:static-content:deploy``` ou ```php bin/magento setup:static-content:deploy pt_BR```, de acordo com as configurações da sua loja.
3. Dê permissões as pastas var/ pub/
- - ```chmod 777 -R var/ pub/```
-
+ - ```chmod 777 -R var/ pub/```
+
+
+Atualização
+-----------
+É altamente recomendado que você tenha um ambiente de testes para validar alterações e atualizações antes de atualizar sua loja em produção. É recomendado também que seja feito um **backup** da sua loja e informações importantes antes de executar qualquer procedimento de atualização/instalação.
+
+A atualização do módulo do PagSeguro é feita através do **composer** e pode ser feita de diversas maneiras, de acordo com suas preferências. Uma forma é através dos comandos:
+1. ```composer update pagseguro/magento2```
+2. ```composer update pagseguro/pagseguro-php-sdk```
+3. ```php bin/magento setup:upgrade```
+4. ```php bin/magento setup:static-content:deploy``` ou ```php bin/magento setup:static-content:deploy pt_BR```, de acordo com as configurações da sua loja.
+
+**Observações**
+- Em alguns casos, o Magento não atualiza os arquivos estáticos gerados, podendo ser necessário atualizar os mesmos via interface administrativa, comandos do terminal ou removendo diretamente conteúdo da pasta *pub/static/frontend/Magento/seu_tema/seu_idioma/UOL_PagSeguro*.
+- Em seguida, executar novamente o comando ```php bin/magento setup:static-content:deploy``` ou ```bin/magento setup:static-content:deploy pt_BR```, de acordo com as configurações da sua loja.
+
+
Inputs
---------
---
@@ -62,6 +80,19 @@ Caso tenha dúvidas ou precise de suporte, acesse nosso [fórum].
Changelog
---------
+1.3.0
+- Adicionada validação e mensagens de erro (frontend) nos formulários do checkout transparente
+
+1.2.6
+- Melhoria na configuração do log na interface administrativa
+- Adicionada seção de atualização do módulo e atualização geral da documentação (README.md)
+- Correção de bugs quando o pedido deixava de existir ou a sessão era encerrada
+- Correçao para aceitar CVV de 4 digitos
+- Melhoria no acesso aos dados do endereço do cliente
+
+1.2.1
+- Alterada a biblioteca JavaScript utilizada nas máscaras.
+
1.2.0
- Adicionada opção para utilizar o Checkout Transparente.
@@ -120,4 +151,3 @@ Achou e corrigiu um bug ou tem alguma feature em mente e deseja contribuir?
[cURL]: http://php.net/manual/en/book.curl.php
[DOM]: http://php.net/manual/en/book.dom.php
[GitHub]: https://github.com/pagseguro/magento2
-
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index 60462ff..5ecf53d 100755
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -68,8 +68,16 @@
UOL\PagSeguro\Model\System\Config\Yesno
-
- Caminho para o arquivo de log.
+
+
+ 1
+
+
+ Nome do arquivo de log a ser utilizado, com caminho relativo ou absoluto, que tenha permissões de leitura e escrita (Ex.: var/log/pagseguro.log).
+
+
+ Para que ocorra normalmente a geração de logs é estritamente necessário que o diretório e o arquivo de log configurados tenham permissões de leitura e escrita.
+
diff --git a/view/frontend/layout/pagseguro_direct_payment.xml b/view/frontend/layout/pagseguro_direct_payment.xml
index 936332e..27b3885 100755
--- a/view/frontend/layout/pagseguro_direct_payment.xml
+++ b/view/frontend/layout/pagseguro_direct_payment.xml
@@ -7,7 +7,7 @@
-->
-
+
@@ -16,4 +16,4 @@