Skip to content

Commit a09e5b9

Browse files
:construct: ADd QR Code on success page
1 parent 0a02313 commit a09e5b9

File tree

8 files changed

+180
-3
lines changed

8 files changed

+180
-3
lines changed

Block/Payment/Info/Pix.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@ public function _construct()
2424
* @return string|null
2525
* @throws LocalizedException
2626
*/
27-
public function getPixUrl()
27+
public function getPixInfo()
2828
{
29-
$method = $this->getInfo()->getMethod();
29+
$info = $this->getInfo();
30+
$method = $info->getMethod();
3031

3132
if (strpos($method, "mundipagg_pix") === false) {
3233
return null;
3334
}
3435

35-
return 'pix-url-qrcode';
36+
$lastTransId = $info->getLastTransId();
37+
$orderId = substr($lastTransId, 0, 19);
38+
39+
Magento2CoreSetup::bootstrap();
40+
$orderService= new \Mundipagg\Core\Payment\Services\OrderService();
41+
return $orderService->getPixQrCodeInfoFromOrder(new OrderId($orderId));
3642
}
3743

3844
public function getTitle()

Block/Payment/Pix.php

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Class Billet
4+
*
5+
* @author MundiPagg Embeddables Team <[email protected]>
6+
* @copyright 2017 MundiPagg (http://www.mundipagg.com)
7+
* @license http://www.mundipagg.com Copyright
8+
*
9+
* @link http://www.mundipagg.com
10+
*/
11+
12+
namespace MundiPagg\MundiPagg\Block\Payment;
13+
14+
use Magento\Framework\View\Element\Template;
15+
use Magento\Framework\View\Element\Template\Context;
16+
use Magento\Checkout\Model\Session as CheckoutSession;
17+
use Magento\Sales\Api\Data\OrderInterface as Order;
18+
use Magento\Sales\Api\Data\OrderPaymentInterface as Payment;
19+
use Mundipagg\Core\Kernel\Repositories\OrderRepository;
20+
use Mundipagg\Core\Kernel\ValueObjects\Id\OrderId;
21+
use Mundipagg\Core\Kernel\ValueObjects\Id\SubscriptionId;
22+
use Mundipagg\Core\Recurrence\Repositories\SubscriptionRepository;
23+
use MundiPagg\MundiPagg\Concrete\Magento2CoreSetup;
24+
use Mundipagg\Core\Recurrence\Repositories\ChargeRepository as SubscriptionChargeRepository;
25+
26+
class Pix extends Template
27+
{
28+
protected $checkoutSession;
29+
/**
30+
* Link constructor.
31+
* @param Context $context
32+
* @param CheckoutSession $checkoutSession
33+
*/
34+
public function __construct(Context $context, CheckoutSession $checkoutSession)
35+
{
36+
$this->checkoutSession = $checkoutSession;
37+
parent::__construct($context, []);
38+
}
39+
40+
/**
41+
* @return CheckoutSession
42+
*/
43+
protected function getCheckoutSession()
44+
{
45+
return $this->checkoutSession;
46+
}
47+
48+
/**
49+
* @return Order
50+
*/
51+
protected function getLastOrder()
52+
{
53+
if (! ($this->checkoutSession->getLastRealOrder()) instanceof Order) {
54+
throw new \InvalidArgumentException;
55+
}
56+
return $this->checkoutSession->getLastRealOrder();
57+
}
58+
59+
/**
60+
* @return Payment
61+
*/
62+
protected function getPayment()
63+
{
64+
if (! ($this->getLastOrder()->getPayment()) instanceof Payment) {
65+
throw new \InvalidArgumentException;
66+
}
67+
return $this->getLastOrder()->getPayment();
68+
}
69+
70+
/**
71+
* @return string
72+
*/
73+
public function getPixInfo()
74+
{
75+
$info = $this->getPayment();
76+
$method = $info->getMethod();
77+
78+
if (strpos($method, "mundipagg_pix") === false) {
79+
return null;
80+
}
81+
82+
$lastTransId = $info->getLastTransId();
83+
$orderId = substr($lastTransId, 0, 19);
84+
85+
Magento2CoreSetup::bootstrap();
86+
$orderService= new \Mundipagg\Core\Payment\Services\OrderService();
87+
return $orderService->getPixQrCodeInfoFromOrder(new OrderId($orderId));
88+
}
89+
}

Observer/PaymentMethodAvailable.php

+4
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ public function getAvailableConfigMethods()
168168
$paymentMethods[] = "mundipagg_debit";
169169
}
170170

171+
if ($this->mundipaggConfig->getPixConfig()->isEnabled()) {
172+
$paymentMethods[] = "mundipagg_pix";
173+
}
174+
171175
return $paymentMethods;
172176
}
173177

Observer/PixDataAssignObserver.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace MundiPagg\MundiPagg\Observer;
4+
5+
use Magento\Framework\App\ObjectManager;
6+
use Magento\Framework\DataObject;
7+
use Magento\Framework\Exception\NoSuchEntityException;
8+
use Magento\Payment\Observer\AbstractDataAssignObserver;
9+
use Magento\Framework\Event\Observer;
10+
use Magento\Quote\Api\Data\PaymentInterface;
11+
use Mundipagg\Core\Payment\Repositories\SavedCardRepository;
12+
use MundiPagg\MundiPagg\Concrete\Magento2CoreSetup;
13+
use MundiPagg\MundiPagg\Model\Cards;
14+
use MundiPagg\MundiPagg\Model\CardsRepository;
15+
16+
class PixDataAssignObserver extends AbstractDataAssignObserver
17+
{
18+
public function execute(Observer $observer)
19+
{
20+
$method = $this->readMethodArgument($observer);
21+
$info = $method->getInfoInstance();
22+
$data = $this->readDataArgument($observer);
23+
24+
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
25+
26+
if (!is_object($additionalData)) {
27+
$additionalData = new DataObject($additionalData ?: []);
28+
}
29+
30+
$info->setAdditionalInformation('pix_buyer_checkbox', $additionalData->getBilletBuyerCheckbox());
31+
$info->setAdditionalInformation('pix_buyer_name', $additionalData->getBilletBuyerName());
32+
$info->setAdditionalInformation('pix_buyer_email', $additionalData->getBilletBuyerEmail());
33+
$info->setAdditionalInformation('pix_buyer_document', $additionalData->getBilletBuyerDocument());
34+
$info->setAdditionalInformation('pix_buyer_street_title', $additionalData->getBilletBuyerStreetTitle());
35+
$info->setAdditionalInformation('pix_buyer_street_number', $additionalData->getBilletBuyerStreetNumber());
36+
$info->setAdditionalInformation('pix_buyer_street_complement', $additionalData->getBilletBuyerStreetComplement());
37+
$info->setAdditionalInformation('pix_buyer_zipcode', $additionalData->getBilletBuyerZipcode());
38+
$info->setAdditionalInformation('pix_buyer_neighborhood', $additionalData->getBilletBuyerNeighborhood());
39+
$info->setAdditionalInformation('pix_buyer_city', $additionalData->getBilletBuyerCity());
40+
$info->setAdditionalInformation('pix_buyer_state', $additionalData->getBilletBuyerState());
41+
$info->setAdditionalInformation('pix_buyer_home_phone', $additionalData->getBilletBuyerHomePhone());
42+
$info->setAdditionalInformation('pix_buyer_mobile_phone', $additionalData->getBilletBuyerMobilePhone());
43+
44+
return $this;
45+
}
46+
}

etc/events.xml

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<event name="payment_method_assign_data_mundipagg_billet">
1616
<observer name="mundipagg_payment_method_assign_data_mundipagg_billet" instance="MundiPagg\MundiPagg\Observer\BilletDataAssignObserver" />
1717
</event>
18+
<event name="payment_method_assign_data_mundipagg_pix">
19+
<observer name="mundipagg_payment_method_assign_data_mundipagg_pix" instance="MundiPagg\MundiPagg\Observer\PixDataAssignObserver" />
20+
</event>
1821
<event name="sales_order_place_before">
1922
<observer name="mundipagg_payment_sales_order_place_before_mundipagg_creditcard" instance="MundiPagg\MundiPagg\Observer\CreditCardOrderPlaceBeforeObserver" />
2023
<observer name="mundipagg_payment_sales_order_place_before" instance="MundiPagg\MundiPagg\Observer\OrderPlaceBeforeObserver" />

view/frontend/layout/checkout_onepage_success.xml

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
template="payment/billet.phtml"
1717
before="order.success.additional.info"
1818
cacheable="false" />
19+
20+
<block class="MundiPagg\MundiPagg\Block\Payment\Pix"
21+
name="checkout.mundipagg.pix.link"
22+
template="payment/pix.phtml"
23+
before="order.success.additional.info"
24+
cacheable="false" />
1925
</referenceContainer>
2026
</body>
2127
</page>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
$pixInfo = $this->getPixInfo();
3+
if (!empty($pixInfo) && $this->getInfo()->getOrder()->getStatus() == 'pending'):
4+
?>
5+
<span><?php echo __($this->getTitle()) ?></span>
6+
<hr />
7+
<div class="pix">
8+
<img width="130" src="<?= $pixInfo['qr_code_url']?>" />
9+
<span style="word-wrap: break-word;"><?= $pixInfo['qr_code']?></span>
10+
</div>
11+
<?php else: ?>
12+
<span><?php echo __($this->getTitle()) ?></span>
13+
<?php endif ?>
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
$pixInfo = $this->getPixInfo();
3+
if (!empty($pixInfo)):
4+
?>
5+
<hr />
6+
<div style="text-align: center">
7+
<img width="180" src="<?= $pixInfo['qr_code_url']?>" />
8+
<p><?= $pixInfo['qr_code']?></p>
9+
</div>
10+
<?php endif ?>

0 commit comments

Comments
 (0)