diff --git a/Model/Graphql/PixDataProvider.php b/Model/Graphql/PixDataProvider.php new file mode 100644 index 00000000..b02926fe --- /dev/null +++ b/Model/Graphql/PixDataProvider.php @@ -0,0 +1,29 @@ +orderRepository = $orderRepository; + $this->orderFactory = $orderFactory; + } + + /** + * @param \Magento\QuoteGraphQl\Model\Resolver\PlaceOrder $subject + * @param mixed $result + * @return mixed + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterResolve( + \Magento\QuoteGraphQl\Model\Resolver\PlaceOrder $subject, + $result + ) { + $order = $this->orderFactory->create()->loadByIncrementId($result['order']['order_number']); + $payment = $order->getPayment(); + + + if (strpos($payment->getMethod(), "pagarme_pix") === false) { + return $result; + } + + $lastTransId = $payment->getLastTransId(); + $orderId = substr($lastTransId, 0, 19); + + Magento2CoreSetup::bootstrap(); + $orderService= new \Pagarme\Core\Payment\Services\OrderService(); + $result['pagarme_pix'] = $orderService->getPixQrCodeInfoFromOrder(new OrderId($orderId)); + + return $result; + } +} diff --git a/etc/graphql/di.xml b/etc/graphql/di.xml new file mode 100644 index 00000000..5cc41018 --- /dev/null +++ b/etc/graphql/di.xml @@ -0,0 +1,13 @@ + + + + + + + + + Pagarme\Pagarme\Model\Graphql\PixDataProvider + + + + \ No newline at end of file diff --git a/etc/schema.graphqls b/etc/schema.graphqls new file mode 100644 index 00000000..62af28f2 --- /dev/null +++ b/etc/schema.graphqls @@ -0,0 +1,8 @@ +type PlaceOrderOutput { + pagarme_pix: PagarmePix +} + +type PagarmePix { + qr_code: String, + qr_code_url: String +} \ No newline at end of file