Skip to content

Commit cd8eda6

Browse files
Merge pull request #111 from vindi/versionamento-master
Atualização da branch `development` para a `master` para versionamento da release 1.4.0
2 parents d8595ad + 4f51390 commit cd8eda6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2057
-132
lines changed

Api/PixConfigurationInterface.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Vindi\Payment\Api;
4+
5+
6+
use Magento\Store\Model\ScopeInterface;
7+
8+
interface PixConfigurationInterface
9+
{
10+
11+
const PATH_ENABLED_DOCUMENT = 'payment/vindi_pix/enabled_document';
12+
const PATH_INFO_MESSAGE = 'checkout/vindi_pix/info_message';
13+
const PATH_INFO_MESSAGE_ONEPAGE_SUCCESS = 'checkout/vindi_pix/info_message_onepage_success';
14+
const PATH_QR_CODE_WARNING_MESSAGE = 'checkout/vindi_pix/qr_code_warning_message';
15+
16+
/**
17+
* @param string $scopeType
18+
* @param string|null $scopeCode
19+
*
20+
* @return bool
21+
*/
22+
public function isEnabledDocument(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null);
23+
24+
/**
25+
* @param string $scopeType
26+
* @param string|null $scopeCode
27+
*
28+
* @return string
29+
*/
30+
public function getInfoMessage(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null);
31+
32+
/**
33+
* @param string $scopeType
34+
* @param string|null $scopeCode
35+
*
36+
* @return string
37+
*/
38+
public function getInfoMessageOnepageSuccess(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null);
39+
40+
/**
41+
* @param string $scopeType
42+
* @param string|null $scopeCode
43+
*
44+
* @return string
45+
*/
46+
public function getQrCodeWarningMessage(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null);
47+
}

Block/Info/Pix.php

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<?php
2+
3+
namespace Vindi\Payment\Block\Info;
4+
5+
6+
use Magento\Backend\Block\Template\Context;
7+
use Magento\Framework\Pricing\Helper\Data;
8+
use Magento\Framework\Serialize\Serializer\Json;
9+
use Magento\Payment\Block\Info;
10+
use Vindi\Payment\Api\PixConfigurationInterface;
11+
use Vindi\Payment\Model\Payment\PaymentMethod;
12+
13+
/**
14+
* Class Pix
15+
*
16+
* @package Vindi\Payment\Block\Info
17+
*/
18+
class Pix extends Info
19+
{
20+
21+
/**
22+
* @var string
23+
*/
24+
protected $_template = 'Vindi_Payment::info/pix.phtml';
25+
26+
/**
27+
* @var Data
28+
*/
29+
protected $_currency;
30+
31+
/**
32+
* @var PixConfigurationInterface
33+
*/
34+
protected $pixConfiguration;
35+
36+
/**
37+
* @var Json
38+
*/
39+
protected $json;
40+
41+
/**
42+
* @param PaymentMethod $paymentMethod
43+
* @param Data $currency
44+
* @param Context $context
45+
* @param PixConfigurationInterface $pixConfiguration
46+
* @param Json $json
47+
* @param array $data
48+
*/
49+
public function __construct(
50+
PaymentMethod $paymentMethod,
51+
Data $currency,
52+
Context $context,
53+
PixConfigurationInterface $pixConfiguration,
54+
Json $json,
55+
array $data = []
56+
) {
57+
parent::__construct($context, $data);
58+
$this->paymentMethod = $paymentMethod;
59+
$this->_currency = $currency;
60+
$this->pixConfiguration = $pixConfiguration;
61+
$this->json = $json;
62+
}
63+
64+
/**
65+
* @return string
66+
* @throws \Magento\Framework\Exception\LocalizedException
67+
*/
68+
public function getBillId()
69+
{
70+
$order = $this->getOrder();
71+
$billId = $order->getVindiBillId() ?? null;
72+
73+
return $billId;
74+
}
75+
76+
/**
77+
* @return mixed
78+
* @throws \Magento\Framework\Exception\LocalizedException
79+
*/
80+
public function getOrder()
81+
{
82+
return $this->getInfo()->getOrder();
83+
}
84+
85+
/**
86+
* Get reorder URL
87+
*
88+
* @param object $order
89+
* @return string
90+
*/
91+
public function getReorderUrl()
92+
{
93+
$order = $this->getOrder();
94+
return $this->getUrl('sales/order/reorder', ['order_id' => $order->getId()]);
95+
}
96+
97+
/**
98+
* @return bool
99+
* @throws \Magento\Framework\Exception\LocalizedException
100+
*/
101+
public function canShowPixInfo()
102+
{
103+
$paymentMethod = $this->getOrder()->getPayment()->getMethod() === \Vindi\Payment\Model\Payment\Pix::CODE;
104+
$daysToPayment = $this->getMaxDaysToPayment();
105+
106+
if (!$daysToPayment) {
107+
return true;
108+
}
109+
110+
$timestampMaxDays = strtotime($daysToPayment);
111+
112+
return $paymentMethod && $this->isValidToPayment($timestampMaxDays);
113+
}
114+
115+
/**
116+
* @return mixed
117+
* @throws \Magento\Framework\Exception\LocalizedException
118+
*/
119+
public function getQrCodePix()
120+
{
121+
return $this->getOrder()->getPayment()->getAdditionalInformation('qrcode_path');
122+
}
123+
124+
/**
125+
* @return string
126+
*/
127+
public function getQrCodeWarningMessage()
128+
{
129+
return $this->pixConfiguration->getQrCodeWarningMessage();
130+
}
131+
132+
/**
133+
* @return bool|string
134+
* @throws \Magento\Framework\Exception\LocalizedException
135+
*/
136+
public function getQrcodeOriginalPath()
137+
{
138+
$qrcodeOriginalPath = $this->getOrder()->getPayment()->getAdditionalInformation('qrcode_original_path');
139+
return $this->json->serialize($qrcodeOriginalPath);
140+
}
141+
142+
/**
143+
* @return mixed
144+
* @throws \Magento\Framework\Exception\LocalizedException
145+
*/
146+
public function getDaysToKeepWaitingPayment()
147+
{
148+
$daysToPayment = $this->getMaxDaysToPayment();
149+
if (!$daysToPayment) {
150+
return null;
151+
}
152+
153+
$timestampMaxDays = strtotime($daysToPayment);
154+
return date('d/m/Y H:m:s', $timestampMaxDays);
155+
}
156+
157+
/**
158+
* @param $timestampMaxDays
159+
*
160+
* @return bool
161+
*/
162+
protected function isValidToPayment($timestampMaxDays)
163+
{
164+
if (!$timestampMaxDays) {
165+
return false;
166+
}
167+
168+
return $timestampMaxDays >= strtotime("now");
169+
}
170+
171+
/**
172+
* @return mixed
173+
* @throws \Magento\Framework\Exception\LocalizedException
174+
*/
175+
protected function getMaxDaysToPayment()
176+
{
177+
return $this->getOrder()->getPayment()->getAdditionalInformation('max_days_to_keep_waiting_payment');
178+
}
179+
}

Block/Onepage/Pix.php

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
namespace Vindi\Payment\Block\Onepage;
4+
5+
6+
use Magento\Checkout\Model\Session;
7+
use Magento\Framework\Serialize\Serializer\Json;
8+
use Magento\Framework\View\Element\Template;
9+
use Magento\Framework\View\Element\Template\Context;
10+
use Magento\Sales\Model\Order;
11+
use Vindi\Payment\Api\PixConfigurationInterface;
12+
13+
class Pix extends Template
14+
{
15+
16+
/**
17+
* @var Session
18+
*/
19+
protected $checkoutSession;
20+
21+
/**
22+
* @var PixConfigurationInterface
23+
*/
24+
protected $pixConfiguration;
25+
26+
/**
27+
* @var Json
28+
*/
29+
protected $json;
30+
31+
/**
32+
* @param PixConfigurationInterface $pixConfiguration
33+
* @param Session $checkoutSession
34+
* @param Context $context
35+
* @param Json $json
36+
* @param array $data
37+
*/
38+
public function __construct(
39+
PixConfigurationInterface $pixConfiguration,
40+
Session $checkoutSession,
41+
Context $context,
42+
Json $json,
43+
array $data = []
44+
) {
45+
parent::__construct($context, $data);
46+
$this->checkoutSession = $checkoutSession;
47+
$this->pixConfiguration = $pixConfiguration;
48+
$this->json = $json;
49+
}
50+
51+
/**
52+
* @return bool
53+
*/
54+
public function canShowPix()
55+
{
56+
return $this->getOrder()->getPayment()->getMethod() === \Vindi\Payment\Model\Payment\Pix::CODE;
57+
}
58+
59+
/**
60+
* @return string[]
61+
*/
62+
public function getQrCodePix()
63+
{
64+
return $this->getOrder()->getPayment()->getAdditionalInformation('qrcode_path');
65+
}
66+
67+
/**
68+
* @return string
69+
*/
70+
public function getQrCodeWarningMessage()
71+
{
72+
return $this->pixConfiguration->getQrCodeWarningMessage();
73+
}
74+
75+
/**
76+
* @return string
77+
*/
78+
public function getInfoMessageOnepageSuccess()
79+
{
80+
return $this->pixConfiguration->getInfoMessageOnepageSuccess();
81+
}
82+
83+
/**
84+
* @return bool|string
85+
*/
86+
public function getQrcodeOriginalPath()
87+
{
88+
$qrcodeOriginalPath = $this->getOrder()->getPayment()->getAdditionalInformation('qrcode_original_path');
89+
return $this->json->serialize($qrcodeOriginalPath);
90+
}
91+
92+
/**
93+
* @return \Magento\Sales\Model\Order
94+
*/
95+
protected function getOrder(): Order
96+
{
97+
return $this->checkoutSession->getLastRealOrder();
98+
}
99+
}

0 commit comments

Comments
 (0)