Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pix informations to graphql #227

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Model/Graphql/PixDataProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

namespace Pagarme\Pagarme\Model\Graphql;

use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;

/**
* Format input into value expected when setting payment method
*/
class PixDataProvider implements AdditionalDataProviderInterface
{
private const PATH_ADDITIONAL_DATA = 'pagarme_pix';

/**
* Format input into value expected when setting payment method
*
* @param array $args
* @return array
*/
public function getData(array $args): array
{
if (!empty($args[self::PATH_ADDITIONAL_DATA])) {
return $args[self::PATH_ADDITIONAL_DATA];
}

return [];
}
}
63 changes: 63 additions & 0 deletions Plugin/GraphQl/PlaceOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);

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;

class PlaceOrder
{

/**
* @var OrderRepositoryInterface
*/
private $orderRepository;

/**
* @var \Magento\Sales\Model\OrderFactory
*/
private $orderFactory;

/**
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
* @param \Magento\Sales\Model\OrderFactory $orderFactory
*/
public function __construct(
OrderRepositoryInterface $orderRepository,
OrderFactory $orderFactory
) {
$this->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;
}
}
13 changes: 13 additions & 0 deletions etc/graphql/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\QuoteGraphQl\Model\Resolver\PlaceOrder">
<plugin disabled="false" name="Pagarme_Pagarme_Plugin_GraphQl_PlaceOrder" sortOrder="10" type="Pagarme\Pagarme\Plugin\GraphQl\PlaceOrder"/>
</type>
<type name="Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool">
<arguments>
<argument name="dataProviders" xsi:type="array">
<item name="pagarme_pix" xsi:type="object">Pagarme\Pagarme\Model\Graphql\PixDataProvider</item>
</argument>
</arguments>
</type>
</config>
8 changes: 8 additions & 0 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type PlaceOrderOutput {
pagarme_pix: PagarmePix
}

type PagarmePix {
qr_code: String,
qr_code_url: String
}
Loading