Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adiciona método PIX, corrige bugs e adiciona compatibilidade com versões mais recentes #8

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/img-en/01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/img-en/02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/img-en/03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/img-en/04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/img-en/05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/img-en/06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/img-en/07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions Api/UpdateStatusesInterface.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

namespace Asaas\Magento2\Api;
//use Asaas\Magento2\Api\Data\PointInterface;

/**
* @api
*/
interface UpdateStatusesInterface
{
/**
* Post Company.
* Update Order Status.
*
* @api
* @param mixed $event
Expand Down
36 changes: 36 additions & 0 deletions Block/Adminhtml/Order/View/Tab/PixPaymentInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Asaas\Magento2\Block\Adminhtml\Order\View\Tab;

class PixPaymentInfo extends \Magento\Framework\View\Element\Template
{
protected $request;
protected $orderRepository;

protected $_template = 'Asaas_Magento2::order/view/tab/pix_payment_info.phtml';

public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\Request\Http $http,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepositoryInterface,
array $data = []
) {
parent::__construct($context, $data);
$this->request = $http;
$this->orderRepository = $orderRepositoryInterface;
}
public function getOrder()
{
$orderId = $this->request->getParam('order_id');
$order = $this->orderRepository->get($orderId);
return $order;
}


public function getPaymentMethodByOrder()
{
$order = $this->getOrder();
$payment = $order->getPayment();
return $payment->getMethod();
}
}
29 changes: 28 additions & 1 deletion Block/Payment/Info.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
<?php

namespace Asaas\Magento2\Block\Payment;

class Info extends \Magento\Framework\View\Element\Template
{
protected $_checkoutSession;
protected $_orderFactory;
protected $_scopeConfig;
protected $request;
protected $orderRepository;

protected $_template = 'Asaas_Magento2::info/info.phtml';

public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Framework\App\Request\Http $http,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepositoryInterface,
array $data = []
) {
parent::__construct($context, $data);
$this->_checkoutSession = $checkoutSession;
$this->_orderFactory = $orderFactory;
$this->request = $http;
$this->orderRepository = $orderRepositoryInterface;
}


Expand All @@ -33,7 +40,12 @@ public function getOrder()
if ($this->_checkoutSession->getLastRealOrderId()) {
return $this->_checkoutSession->getLastRealOrder();
}
if ($order = $this->getInfo()->getOrder()) {
// if ($order = $this->getInfo()->getOrder()) {
// return $order;
// }
else {
$orderId = $this->request->getParam('order_id');
$order = $this->orderRepository->get($orderId);
return $order;
}
return false;
Expand All @@ -45,6 +57,13 @@ public function getPaymentMethod()
return $payment->getMethod();
}

public function getPaymentMethodByOrder()
{
$order = $this->getOrder();
$payment = $order->getPayment();
return $payment->getMethod();
}

public function getPaymentInfo()
{
$order = $this->getOrder();
Expand All @@ -66,6 +85,14 @@ public function getPaymentInfo()

);
break;
case 'pix':
return array(
'tipo' => 'Pix',
'url' => 'qrcode',
'texto' => 'Escaneie o QrCode ou copie o código para realizar o pagamento'

);
break;

}
}
Expand Down
8 changes: 8 additions & 0 deletions Block/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public function __construct(
public function getBoleto() {
return $this->checkoutSession->getBoleto();
}

public function getPixQrCode() {
return $this->checkoutSession->getPixQrCode();
}

public function getPixPayload() {
return $this->checkoutSession->getPixPayload();
}

public function getOrder() {
return $this->_order = $this->_orderFactory->create()->loadByIncrementId(
Expand Down
60 changes: 43 additions & 17 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use \Magento\Framework\App\Helper\AbstractHelper;

class Data extends AbstractHelper {
class Data extends AbstractHelper
{
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
Expand All @@ -13,15 +14,18 @@ class Data extends AbstractHelper {
* returning config value
**/

public function getConfig($path) {
public function getConfig($path)
{
$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

return $this->scopeConfig->getValue($path, $storeScope);
}
/**
* Return url
**/

public function getUrl() {
public function getUrl()
{
if ($this->getConfig('payment/asaasmagento2/general_options/ambiente') === 'production') {
return !$this->getConfig('payment/asaasmagento2/general_options/url_prod') ?
"https://www.asaas.com" :
Expand All @@ -33,60 +37,76 @@ public function getUrl() {
}
}

public function getDiscout(){
public function getDiscout()
{
return $this->getConfig('payment/asaasmagento2/options_boleto/options_boleto_discount');
}

public function getFine(){
public function getFine()
{
return $this->getConfig('payment/asaasmagento2/options_boleto/options_boleto_fine/value_fine');
}

public function getTokenWebhook(){
public function getTokenWebhook()
{
return $this->getConfig('payment/asaasmagento2/general_options/token_webhook');
}

public function getInterest(){
public function getInterest()
{
return $this->getConfig('payment/asaasmagento2/options_boleto/options_boleto_interest/value_interest');
}

public function getAcessToken() {
public function getAcessToken()
{
return $this->getConfig('payment/asaasmagento2/general_options/api_key');
}

public function getNotifications() {
public function getNotifications()
{
return $this->getConfig('payment/asaasmagento2/general_options/active_notifications');
}

public function getDays() {
public function getDays()
{
return $this->getConfig('payment/asaasmagento2/options_boleto/validade');
}

private function getModuleEnabled() {
private function getModuleEnabled()
{
return $this->getConfig('payment/asaasmagento2/active');
}

public function getStatusBillet() {
public function getStatusBillet()
{
if ($this->getModuleEnabled() && $this->getConfig('payment/asaasmagento2/options_boleto/active_billet')) {
return true;
} else {
return false;
}
}

public function getStatusCc() {
public function getStatusCc()
{
if ($this->getModuleEnabled() && $this->getConfig('payment/asaasmagento2/options_cc/active_cc')) {
return true;
} else {
return false;
}
}

public function getInstrucoes() {
public function getInstrucoes()
{
return $this->getConfig('payment/asaasmagento2/options_boleto/instrucoes');
}
public function getInstallments() {
public function getInstallments()
{
$installmentsConfig = $this->getConfig('payment/asaasmagento2/options_cc/parcelas');
if (empty($installmentsConfig)) {
return false;
}
$installments = json_decode($this->getConfig('payment/asaasmagento2/options_cc/parcelas'));
if(!$installments){
if (!$installments) {
return false;
}
$i = 1;
Expand All @@ -103,7 +123,13 @@ public function getInstallments() {
return $installmentss;
}

public function getMinParcela(){
public function getMinParcela()
{
return $this->getConfig('payment/asaasmagento2/options_cc/min_parcela');
}

public function getPixInstructions()
{
return $this->getConfig('payment/asaasmagento2/options_pix/instrucoes');
}
}
30 changes: 20 additions & 10 deletions Model/AdditionalConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,50 @@

use Magento\Checkout\Model\ConfigProviderInterface;

class AdditionalConfigProvider implements ConfigProviderInterface {
class AdditionalConfigProvider implements ConfigProviderInterface
{
private $helperData;
private $cart;
private $ccConfig;
private $customerRepositoryInterface;

public function __construct(
\Asaas\Magento2\Helper\Data $helper,
\Magento\Checkout\Model\Cart $cart,
\Magento\Payment\Model\CcConfig $ccConfig,
\Magento\Customer\Model\Customer $customerRepositoryInterface
) {
) {
$this->helperData = $helper;
$this->cart = $cart;
$this->ccConfig = $ccConfig;
$this->_customerRepositoryInterface = $customerRepositoryInterface;
$this->customerRepositoryInterface = $customerRepositoryInterface;
}

public function getInstallments() {

public function getInstallments()
{
$installments = $this->helperData->getInstallments();
return $installments;
}

public function getCpfCnpj() {
public function getCpfCnpj()
{
$customerId = $this->cart->getQuote()->getCustomerId();
$customer = $this->_customerRepositoryInterface->load($customerId);
$customer = $this->customerRepositoryInterface->load($customerId);
return $customer->getTaxvat();
}

public function getGrandTotal(){
public function getGrandTotal()
{
return $this->cart->getQuote()->getGrandTotal();
}

public function getMinParcelas(){
public function getMinParcelas()
{
return $this->helperData->getMinParcela();
}

public function getConfig() {
public function getConfig()
{
$config = [
'payment' => [
'cc' => [
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/Ambiente.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class Ambiente
* @var string[]
*/ public function toOptionArray()
{
return [['value' => 'production', 'label' => __('Produção')], ['value' => 'dev', 'label' => __('Desenvolvimento')],];
return [['value' => 'production', 'label' => __('Production')], ['value' => 'dev', 'label' => __('Development')],];
}
}
4 changes: 2 additions & 2 deletions Model/Config/Source/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Discount {
* @var string[]
*/ public function toOptionArray() {
return [
['value' => 'FIXED', 'label' => __('Valor Fixo')],
['value' => 'PERCENTAGE', 'label' => __('Percentual')],
['value' => 'FIXED', 'label' => __('Fixed Value')],
['value' => 'PERCENTAGE', 'label' => __('Percentage')],
];
}
}
Loading