Skip to content

Commit

Permalink
Merge pull request #111 from vindi/versionamento-master
Browse files Browse the repository at this point in the history
Atualização da branch `development` para a `master` para versionamento da release 1.4.0
  • Loading branch information
tkusuki committed Feb 14, 2024
2 parents d8595ad + 4f51390 commit cd8eda6
Show file tree
Hide file tree
Showing 50 changed files with 2,057 additions and 132 deletions.
47 changes: 47 additions & 0 deletions Api/PixConfigurationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Vindi\Payment\Api;


use Magento\Store\Model\ScopeInterface;

interface PixConfigurationInterface
{

const PATH_ENABLED_DOCUMENT = 'payment/vindi_pix/enabled_document';
const PATH_INFO_MESSAGE = 'checkout/vindi_pix/info_message';
const PATH_INFO_MESSAGE_ONEPAGE_SUCCESS = 'checkout/vindi_pix/info_message_onepage_success';
const PATH_QR_CODE_WARNING_MESSAGE = 'checkout/vindi_pix/qr_code_warning_message';

/**
* @param string $scopeType
* @param string|null $scopeCode
*
* @return bool
*/
public function isEnabledDocument(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null);

/**
* @param string $scopeType
* @param string|null $scopeCode
*
* @return string
*/
public function getInfoMessage(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null);

/**
* @param string $scopeType
* @param string|null $scopeCode
*
* @return string
*/
public function getInfoMessageOnepageSuccess(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null);

/**
* @param string $scopeType
* @param string|null $scopeCode
*
* @return string
*/
public function getQrCodeWarningMessage(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null);
}
179 changes: 179 additions & 0 deletions Block/Info/Pix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php

namespace Vindi\Payment\Block\Info;


use Magento\Backend\Block\Template\Context;
use Magento\Framework\Pricing\Helper\Data;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Payment\Block\Info;
use Vindi\Payment\Api\PixConfigurationInterface;
use Vindi\Payment\Model\Payment\PaymentMethod;

/**
* Class Pix
*
* @package Vindi\Payment\Block\Info
*/
class Pix extends Info
{

/**
* @var string
*/
protected $_template = 'Vindi_Payment::info/pix.phtml';

/**
* @var Data
*/
protected $_currency;

/**
* @var PixConfigurationInterface
*/
protected $pixConfiguration;

/**
* @var Json
*/
protected $json;

/**
* @param PaymentMethod $paymentMethod
* @param Data $currency
* @param Context $context
* @param PixConfigurationInterface $pixConfiguration
* @param Json $json
* @param array $data
*/
public function __construct(
PaymentMethod $paymentMethod,
Data $currency,
Context $context,
PixConfigurationInterface $pixConfiguration,
Json $json,
array $data = []
) {
parent::__construct($context, $data);
$this->paymentMethod = $paymentMethod;
$this->_currency = $currency;
$this->pixConfiguration = $pixConfiguration;
$this->json = $json;
}

/**
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getBillId()
{
$order = $this->getOrder();
$billId = $order->getVindiBillId() ?? null;

return $billId;
}

/**
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getOrder()
{
return $this->getInfo()->getOrder();
}

/**
* Get reorder URL
*
* @param object $order
* @return string
*/
public function getReorderUrl()
{
$order = $this->getOrder();
return $this->getUrl('sales/order/reorder', ['order_id' => $order->getId()]);
}

/**
* @return bool
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function canShowPixInfo()
{
$paymentMethod = $this->getOrder()->getPayment()->getMethod() === \Vindi\Payment\Model\Payment\Pix::CODE;
$daysToPayment = $this->getMaxDaysToPayment();

if (!$daysToPayment) {
return true;
}

$timestampMaxDays = strtotime($daysToPayment);

return $paymentMethod && $this->isValidToPayment($timestampMaxDays);
}

/**
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getQrCodePix()
{
return $this->getOrder()->getPayment()->getAdditionalInformation('qrcode_path');
}

/**
* @return string
*/
public function getQrCodeWarningMessage()
{
return $this->pixConfiguration->getQrCodeWarningMessage();
}

/**
* @return bool|string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getQrcodeOriginalPath()
{
$qrcodeOriginalPath = $this->getOrder()->getPayment()->getAdditionalInformation('qrcode_original_path');
return $this->json->serialize($qrcodeOriginalPath);
}

/**
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getDaysToKeepWaitingPayment()
{
$daysToPayment = $this->getMaxDaysToPayment();
if (!$daysToPayment) {
return null;
}

$timestampMaxDays = strtotime($daysToPayment);
return date('d/m/Y H:m:s', $timestampMaxDays);
}

/**
* @param $timestampMaxDays
*
* @return bool
*/
protected function isValidToPayment($timestampMaxDays)
{
if (!$timestampMaxDays) {
return false;
}

return $timestampMaxDays >= strtotime("now");
}

/**
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function getMaxDaysToPayment()
{
return $this->getOrder()->getPayment()->getAdditionalInformation('max_days_to_keep_waiting_payment');
}
}
99 changes: 99 additions & 0 deletions Block/Onepage/Pix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Vindi\Payment\Block\Onepage;


use Magento\Checkout\Model\Session;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Sales\Model\Order;
use Vindi\Payment\Api\PixConfigurationInterface;

class Pix extends Template
{

/**
* @var Session
*/
protected $checkoutSession;

/**
* @var PixConfigurationInterface
*/
protected $pixConfiguration;

/**
* @var Json
*/
protected $json;

/**
* @param PixConfigurationInterface $pixConfiguration
* @param Session $checkoutSession
* @param Context $context
* @param Json $json
* @param array $data
*/
public function __construct(
PixConfigurationInterface $pixConfiguration,
Session $checkoutSession,
Context $context,
Json $json,
array $data = []
) {
parent::__construct($context, $data);
$this->checkoutSession = $checkoutSession;
$this->pixConfiguration = $pixConfiguration;
$this->json = $json;
}

/**
* @return bool
*/
public function canShowPix()
{
return $this->getOrder()->getPayment()->getMethod() === \Vindi\Payment\Model\Payment\Pix::CODE;
}

/**
* @return string[]
*/
public function getQrCodePix()
{
return $this->getOrder()->getPayment()->getAdditionalInformation('qrcode_path');
}

/**
* @return string
*/
public function getQrCodeWarningMessage()
{
return $this->pixConfiguration->getQrCodeWarningMessage();
}

/**
* @return string
*/
public function getInfoMessageOnepageSuccess()
{
return $this->pixConfiguration->getInfoMessageOnepageSuccess();
}

/**
* @return bool|string
*/
public function getQrcodeOriginalPath()
{
$qrcodeOriginalPath = $this->getOrder()->getPayment()->getAdditionalInformation('qrcode_original_path');
return $this->json->serialize($qrcodeOriginalPath);
}

/**
* @return \Magento\Sales\Model\Order
*/
protected function getOrder(): Order
{
return $this->checkoutSession->getLastRealOrder();
}
}
Loading

0 comments on commit cd8eda6

Please sign in to comment.