|
| 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 | +} |
0 commit comments