From a7a328877421702c2bf950d60ec25e9c1579a763 Mon Sep 17 00:00:00 2001 From: RafaMelazzo Date: Wed, 16 Aug 2023 09:41:46 -0300 Subject: [PATCH 1/3] Added pix informations to graphql --- Model/Graphql/PixDataProvider.php | 29 +++++++++++++++++ Plugin/GraphQl/PlaceOrder.php | 52 +++++++++++++++++++++++++++++++ etc/graphql/di.xml | 13 ++++++++ etc/schema.graphqls | 8 +++++ 4 files changed, 102 insertions(+) create mode 100644 Model/Graphql/PixDataProvider.php create mode 100644 Plugin/GraphQl/PlaceOrder.php create mode 100644 etc/graphql/di.xml create mode 100644 etc/schema.graphqls 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; + } + + 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; + } +} \ No newline at end of file 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 From 0ca80d2d75488d6613dd8e6a7f5b980d3b62a67d Mon Sep 17 00:00:00 2001 From: RafaMelazzo Date: Wed, 16 Aug 2023 10:12:38 -0300 Subject: [PATCH 2/3] Remove the unused function parameter "$subject" --- Plugin/GraphQl/PlaceOrder.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Plugin/GraphQl/PlaceOrder.php b/Plugin/GraphQl/PlaceOrder.php index 7be6c48f..1412931d 100644 --- a/Plugin/GraphQl/PlaceOrder.php +++ b/Plugin/GraphQl/PlaceOrder.php @@ -4,6 +4,7 @@ namespace Pagarme\Pagarme\Plugin\GraphQl; use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Sales\Model\OrderFactory; use Pagarme\Core\Kernel\ValueObjects\Id\OrderId; use Pagarme\Pagarme\Concrete\Magento2CoreSetup; @@ -20,16 +21,24 @@ class PlaceOrder */ private $orderFactory; + /** + * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository + * @param \Magento\Sales\Model\OrderFactory $orderFactory + */ public function __construct( OrderRepositoryInterface $orderRepository, - \Magento\Sales\Model\OrderFactory $orderFactory + OrderFactory $orderFactory ) { $this->orderRepository = $orderRepository; $this->orderFactory = $orderFactory; } + /** + * @param \Magento\QuoteGraphQl\Model\Resolver\PlaceOrder $subject + * @param mixed $result + * @return mixed + */ public function afterResolve( - \Magento\QuoteGraphQl\Model\Resolver\PlaceOrder $subject, $result ) { $order = $this->orderFactory->create()->loadByIncrementId($result['order']['order_number']); From 66413e6459b4b91c3825f52a8fa0b822f16179e1 Mon Sep 17 00:00:00 2001 From: Mateus Picoloto Date: Wed, 16 Aug 2023 16:46:27 -0300 Subject: [PATCH 3/3] fix: adding subject parameter in plugin --- Plugin/GraphQl/PlaceOrder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Plugin/GraphQl/PlaceOrder.php b/Plugin/GraphQl/PlaceOrder.php index 1412931d..9ee628e8 100644 --- a/Plugin/GraphQl/PlaceOrder.php +++ b/Plugin/GraphQl/PlaceOrder.php @@ -37,8 +37,10 @@ public function __construct( * @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']); @@ -58,4 +60,4 @@ public function afterResolve( return $result; } -} \ No newline at end of file +}