Skip to content

Commit

Permalink
Merge pull request #57 from elisei/Magento@2.4.6
Browse files Browse the repository at this point in the history
PagBank 😍 Magento
  • Loading branch information
elisei authored Mar 20, 2024
2 parents 51692c2 + 5b87b64 commit ac58a20
Show file tree
Hide file tree
Showing 38 changed files with 1,826 additions and 16 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
26 changes: 26 additions & 0 deletions Cron/GetStatusUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class GetStatusUpdate
*/
public const PAYMENT_METHOD_PIX = 'pagbank_paymentmagento_pix';

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

/**
* Payment Method Boleto.
*/
Expand Down Expand Up @@ -145,6 +150,27 @@ public function findPix()
}
}

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

foreach ($orders as $order) {
$incrementId = $order->getIncrementId();

try {
$this->update->getUpdate($incrementId);
} catch (\Throwable $th) {
$this->errorNotificationManager($order);
continue;
}
}
}

/**
* Find Boleto.
*
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 ac58a20

Please sign in to comment.