Skip to content

Commit

Permalink
PagBank 😍 Magento
Browse files Browse the repository at this point in the history
  • Loading branch information
elisei committed Mar 20, 2024
1 parent 57f5a54 commit b10ede3
Show file tree
Hide file tree
Showing 39 changed files with 1,816 additions and 65 deletions.
78 changes: 78 additions & 0 deletions Block/Sales/Form/DeepLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* PagBank Payment Magento Module.
*
* Copyright © 2023 PagBank. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* @license See LICENSE for license details.
*/

namespace PagBank\PaymentMagento\Block\Sales\Form;

use Magento\Framework\View\Element\Template\Context;
use PagBank\PaymentMagento\Gateway\Config\ConfigDeepLink;

/**
* Class DeepLink - Form for payment by DeepLink.
*/
class DeepLink extends \Magento\Payment\Block\Form
{
/**
* DeepLink Form template.
*/
public const TEMPLATE = 'PagBank_PaymentMagento::form/deep-link.phtml';

/**
* Get relevant path to template.
*
* @return string
*/
public function getTemplate()
{
return self::TEMPLATE;
}

/**
* @var ConfigDeepLink
*/
protected $configDeepLink;

/**
* @param Context $context
* @param ConfigDeepLink $configDeepLink
*/
public function __construct(
Context $context,
ConfigDeepLink $configDeepLink
) {
parent::__construct($context);
$this->configDeepLink = $configDeepLink;
}

/**
* Title - DeepLink.
*
* @return string
*/
public function getTitle()
{
return $this->configDeepLink->getTitle();
}

/**
* Get Instruction.
*
* @param int|null $storeId
*
* @return Phrase
*/
public function getInstruction()
{
$text = $this->configDeepLink->getInstructionCheckout();

$replaceText = __($text);

return $replaceText;
}
}
64 changes: 64 additions & 0 deletions Block/Sales/Info/DeepLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* PagBank Payment Magento Module.
*
* Copyright © 2023 PagBank. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* @license See LICENSE for license details.
*/

namespace PagBank\PaymentMagento\Block\Sales\Info;

use Magento\Framework\Phrase;
use Magento\Payment\Block\ConfigurableInfo;

/**
* Class DeepLink - DeepLink payment information.
*/
class DeepLink extends ConfigurableInfo
{
/**
* DeepLink Info template.
*/
public const TEMPLATE = 'PagBank_PaymentMagento::info/deep-link/instructions.phtml';

/**
* Get relevant path to template.
*
* @return string
*/
public function getTemplate()
{
return self::TEMPLATE;
}

/**
* Returns value view.
*
* @param string $field
* @param string $value
*
* @return string | Phrase
*/
protected function getValueView($field, $value)
{
if ($field === 'qr_code_url_image') {
return $this->getImageQrCode($value);
}

return parent::getValueView($field, $value);
}

/**
* Get Url to Image Qr Code.
*
* @param string $qrCode
*
* @return string
*/
public function getImageQrCode($qrCode)
{
return $this->_urlBuilder->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]).$qrCode;
}
}
10 changes: 8 additions & 2 deletions Block/Sales/Order/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class Success extends Template
*/
public const TEMPLATE_PIX = 'PagBank_PaymentMagento::sales/order/success/pix.phtml';

/**
* Template Pix.
*/
public const TEMPLATE_DEEP_LINK = 'PagBank_PaymentMagento::sales/order/success/deep-link.phtml';

/**
* @var Session
*/
Expand Down Expand Up @@ -67,8 +72,9 @@ public function getTemplate()
$paymentType = $this->getMethodCode();

$templates = [
'pagbank_paymentmagento_boleto' => self::TEMPLATE_BOLETO,
'pagbank_paymentmagento_pix' => self::TEMPLATE_PIX,
'pagbank_paymentmagento_boleto' => self::TEMPLATE_BOLETO,
'pagbank_paymentmagento_pix' => self::TEMPLATE_PIX,
'pagbank_paymentmagento_deep_link' => self::TEMPLATE_DEEP_LINK,
];

if (isset($templates[$paymentType])) {
Expand Down
41 changes: 13 additions & 28 deletions Cron/GetStatusUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Magento\Payment\Model\Method\Logger;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use PagBank\PaymentMagento\Gateway\Config\Config;
use PagBank\PaymentMagento\Model\Console\Command\Orders\Update;

/**
Expand All @@ -28,14 +27,14 @@ class GetStatusUpdate
public const PAYMENT_METHOD_CC = 'pagbank_paymentmagento_cc';

/**
* Payment Method Vault.
* Payment Method Pix.
*/
public const PAYMENT_METHOD_VAULT = 'pagbank_paymentmagento_cc_vault';
public const PAYMENT_METHOD_PIX = 'pagbank_paymentmagento_pix';

/**
* Payment Method Pix.
* Payment Method Deep Link.
*/
public const PAYMENT_METHOD_PIX = 'pagbank_paymentmagento_pix';
public const PAYMENT_METHOD_DEEP_LINK = 'pagbank_paymentmagento_deep_link';

/**
* Payment Method Boleto.
Expand All @@ -47,11 +46,6 @@ class GetStatusUpdate
*/
protected $logger;

/**
* @var Config
*/
protected $config;

/**
* @var NotifierInterface
*/
Expand All @@ -71,20 +65,17 @@ class GetStatusUpdate
* Constructor.
*
* @param Logger $logger
* @param Config $config
* @param NotifierInterface $notifierInterface
* @param Update $update
* @param CollectionFactory $collectionFactory
*/
public function __construct(
Logger $logger,
Config $config,
NotifierInterface $notifierInterface,
Update $update,
CollectionFactory $collectionFactory
) {
$this->logger = $logger;
$this->config = $config;
$this->notifierInterface = $notifierInterface;
$this->update = $update;
$this->collectionFactory = $collectionFactory;
Expand All @@ -99,18 +90,12 @@ public function __construct(
*/
public function getFilterdOrders($method)
{
$exclude = $this->config->getAddtionalValue('exclude_fetch_cron');
$exclude = explode(',', $exclude);

$orders = $this->collectionFactory->create()
->addFieldToFilter('state', [
'in' => [
Order::STATE_NEW,
Order::STATE_PAYMENT_REVIEW,
],
])
->addFieldToFilter('status', [
'nin' => $exclude,
]);

$orders->getSelect()
Expand Down Expand Up @@ -146,13 +131,13 @@ public function findPix()
}

/**
* Find Boleto.
* Find Deep Link.
*
* @return void
*/
public function findBoleto()
public function findDeepLink()
{
$orders = $this->getFilterdOrders(self::PAYMENT_METHOD_BOLETO);
$orders = $this->getFilterdOrders(self::PAYMENT_METHOD_DEEP_LINK);

foreach ($orders as $order) {
$incrementId = $order->getIncrementId();
Expand All @@ -167,13 +152,13 @@ public function findBoleto()
}

/**
* Find Credit Card.
* Find Boleto.
*
* @return void
*/
public function findCc()
public function findBoleto()
{
$orders = $this->getFilterdOrders(self::PAYMENT_METHOD_CC);
$orders = $this->getFilterdOrders(self::PAYMENT_METHOD_BOLETO);

foreach ($orders as $order) {
$incrementId = $order->getIncrementId();
Expand All @@ -188,13 +173,13 @@ public function findCc()
}

/**
* Find Vault.
* Find Credit Card.
*
* @return void
*/
public function findVault()
public function findCc()
{
$orders = $this->getFilterdOrders(self::PAYMENT_METHOD_VAULT);
$orders = $this->getFilterdOrders(self::PAYMENT_METHOD_CC);

foreach ($orders as $order) {
$incrementId = $order->getIncrementId();
Expand Down
4 changes: 2 additions & 2 deletions Gateway/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ public function createFile(WriteInterface $writeDirectory, $filePath, $fileToCop
*/
public function hasPathDir($type): bool
{
$pixPath = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('/pagbank/'.$type);
$path = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('/pagbank/'.$type);

return $this->fileIo->checkAndCreateFolder($pixPath);
return $this->fileIo->checkAndCreateFolder($path);
}

/**
Expand Down
Loading

0 comments on commit b10ede3

Please sign in to comment.