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

Display PBC fields in order grid #126

Closed
wants to merge 9 commits into from
Closed
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
2 changes: 1 addition & 1 deletion Gateway/Command/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function execute(array $commandSubject)

$paymentLinkId = $payment->getAdditionalInformation(Method::PAYMENT_LINK_ID);
$storeId = $commandSubject['payment']->getOrder()->getStoreId();
$this->paymentLinkService->cancelPaymentLink((string)$storeId, $paymentLinkId);
$this->paymentLinkService->cancelPaymentLink($storeId, $paymentLinkId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs reverting. I think it was accidently removed.

$message = __('Canceled Rvvup Payment Link online');
$orderPayment->getOrder()->addCommentToStatusHistory($message, false, false);

Expand Down
40 changes: 27 additions & 13 deletions Observer/Model/ProcessOrder/CardsMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Api\Data\OrderStatusHistoryInterfaceFactory;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order\Payment;
use Magento\Sales\Model\ResourceModel\Order\Payment as PaymentResource;
use Psr\Log\LoggerInterface;

class CardsMetadata implements ObserverInterface
Expand All @@ -25,21 +28,27 @@ class CardsMetadata implements ObserverInterface
/** @var OrderManagementInterface $orderManagement */
private $orderManagement;

/** @var PaymentResource */
private $paymentResource;

/**
* @param OrderRepositoryInterface $orderRepository
* @param OrderRepositoryInterface $orderRepository
* @param OrderStatusHistoryInterfaceFactory $orderStatusHistoryFactory
* @param OrderManagementInterface $orderManagement
* @param LoggerInterface $logger
* @param OrderManagementInterface $orderManagement
* @param PaymentResource $paymentResource
* @param LoggerInterface $logger
*/
public function __construct(
OrderRepositoryInterface $orderRepository,
OrderStatusHistoryInterfaceFactory $orderStatusHistoryFactory,
OrderManagementInterface $orderManagement,
LoggerInterface $logger
OrderRepositoryInterface $orderRepository,
OrderStatusHistoryInterfaceFactory $orderStatusHistoryFactory,
OrderManagementInterface $orderManagement,
PaymentResource $paymentResource,
LoggerInterface $logger
) {
$this->orderRepository = $orderRepository;
$this->orderStatusHistoryFactory = $orderStatusHistoryFactory;
$this->orderManagement = $orderManagement;
$this->paymentResource = $paymentResource;
$this->logger = $logger;
}

Expand All @@ -53,7 +62,7 @@ public function execute(Observer $observer)
{
$orderId = $observer->getData('order_id');
$rvvupData = $observer->getData('rvvup_data');
$payment = $rvvupData['payments'][0];
$paymentData = $rvvupData['payments'][0];
$order = $this->orderRepository->get($orderId);
if ($order->getPayment()->getMethod() == 'rvvup_CARD') {
$data = [];
Expand All @@ -67,9 +76,11 @@ public function execute(Observer $observer)
'acquirerResponseMessage'
];

$payment = $order->getPayment();
foreach ($keys as $key) {
$this->populateCardData($data, $payment, $key);
$this->populateCardData($data, $paymentData, $key, $payment);
}
$this->paymentResource->save($payment);

if (!empty($data)) {
try {
Expand All @@ -91,14 +102,17 @@ public function execute(Observer $observer)

/**
* @param array $data
* @param array $payment
* @param array $paymentData
* @param string $key
* @param Payment $payment
* @return void
* @throws LocalizedException
*/
private function populateCardData(array &$data, array $payment, string $key): void
private function populateCardData(array &$data, array $paymentData, string $key, Payment $payment): void
{
if (isset($payment[$key])) {
$value = $this->mapCardValue($payment[$key]);
if (isset($paymentData[$key])) {
$value = $this->mapCardValue($paymentData[$key]);
$payment->setAdditionalInformation('rvvup_' . $key, $paymentData[$key]);
$data[$key] = $key . ': ' . $value;
}
}
Expand Down
10 changes: 10 additions & 0 deletions Service/VirtualCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ private function processResponse(string $orderId, array $body): void
$order = $this->orderRepository->get($orderId);
$payment = $this->paymentLinkService->getQuotePaymentByOrder($order);
$payment->setAdditionalInformation(Method::MOTO_ID, $motoId);

if ($payment->getAdditionalInformation(Method::PAYMENT_LINK_ID)) {
$paymentLinkId = $payment->getAdditionalInformation(Method::PAYMENT_LINK_ID);
} elseif ($order->getPayment()->getAdditionalInformation(Method::PAYMENT_LINK_ID)) {
$paymentLinkId = $order->getPayment()->getAdditionalInformation(Method::PAYMENT_LINK_ID);
}
if (isset($paymentLinkId)) {
$this->paymentLinkService->cancelPaymentLink((string)$order->getStoreId(), $paymentLinkId);
}

$this->paymentResource->save($payment);
} catch (\Exception $e) {
$this->logger->error(
Expand Down
130 changes: 130 additions & 0 deletions Ui/Component/Listing/Column/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
declare(strict_types=1);

namespace Rvvup\Payments\Ui\Component\Listing\Column;

use Magento\Framework\App\CacheInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\View\Asset\Repository;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;

class Data extends Column
{
private const RVVUP_PAYMENTS_IMAGES_GREEN_SVG = 'Rvvup_Payments::images/green.svg';
private const RVVUP_PAYMENTS_IMAGES_GREY_SVG = 'Rvvup_Payments::images/grey.svg';
private const RVVUP_PAYMENTS_IMAGES_RED_SVG = 'Rvvup_Payments::images/red.svg';

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

/** @var CacheInterface */
private $cache;

/** @var Repository */
private $assetRepo;

/**
* @var RequestInterface
*/
protected $request;

/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param OrderRepositoryInterface $orderRepository
* @param CacheInterface $cache
* @param Repository $assetRepo
* @param RequestInterface $request
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
OrderRepositoryInterface $orderRepository,
CacheInterface $cache,
Repository $assetRepo,
RequestInterface $request,
array $components = [],
array $data = []
) {
$this->orderRepository = $orderRepository;
$this->cache = $cache;
$this->assetRepo = $assetRepo;
$this->request = $request;
parent::__construct($context, $uiComponentFactory, $components, $data);
}

public function prepareDataSource(array $dataSource): array
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
if (isset($item['payment_method'])) {
$field = $this->getData('name');
$id = $item["entity_id"] . '_' . $field;

if ($this->cache->load($id) != null) {
$value = $this->cache->load($id);
$item[$field . '_src'] = $value;
continue;
}

if (strpos($item['payment_method'], 'rvvup_CARD') === 0) {
$order = $this->orderRepository->get($item["entity_id"]);
$payment = $order->getPayment();
$value = $payment->getAdditionalInformation($field) ?? '';
$value = $this->getImagePath($field, $value);
$item[$field . '_src'] = $value;
$this->cache->save($value, $id);
} else {
$this->cache->save('', $id);
}
}
}
}
return $dataSource;
}

/**
* @param string $field
* @param string $value
* @return string
*/
private function getImagePath(string $field, string $value): string
{
if ($field === 'rvvup_eci') {
if ($value == '05' || $value == '02') {
$value = $this->getViewFileUrl(self::RVVUP_PAYMENTS_IMAGES_GREEN_SVG);
} else {
$value = $this->getViewFileUrl(self::RVVUP_PAYMENTS_IMAGES_GREY_SVG);
}
} else {
switch ($value) {
case 2:
$value = $this->getViewFileUrl(self::RVVUP_PAYMENTS_IMAGES_GREEN_SVG);
break;
case 4:
$value = $this->getViewFileUrl(self::RVVUP_PAYMENTS_IMAGES_RED_SVG);
break;
case 0:
case 1:
default:
$value = $this->getViewFileUrl(self::RVVUP_PAYMENTS_IMAGES_GREY_SVG);
}
}
return $value;
}

/**
* @param string $fileId
* @return string
*/
public function getViewFileUrl(string $fileId): string
{
$params = array_merge(['_secure' => $this->request->isSecure()], []);
return $this->assetRepo->getUrlWithParams($fileId, $params);
}
}
46 changes: 46 additions & 0 deletions view/adminhtml/ui_component/sales_order_grid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="sales_order_columns">
<column name="rvvup_cvvResponseCode"
component="Magento_PageBuilder/js/grid/columns/preview-image"
class="Rvvup\Payments\Ui\Component\Listing\Column\Data">
<settings>
<label translate="true">Rvvup CVV</label>
<hasPreview>1</hasPreview>
<sortable>false</sortable>
<draggable>false</draggable>
</settings>
</column>
<column name="rvvup_avsPostCodeResponseCode"
component="Magento_PageBuilder/js/grid/columns/preview-image"
class="Rvvup\Payments\Ui\Component\Listing\Column\Data">
<settings>
<label translate="true">Rvvup PostCode Avs</label>
<hasPreview>1</hasPreview>
<sortable>false</sortable>
<draggable>false</draggable>
</settings>
</column>
<column name="rvvup_avsAddressResponseCode"
component="Magento_PageBuilder/js/grid/columns/preview-image"
class="Rvvup\Payments\Ui\Component\Listing\Column\Data">
<settings>
<label translate="true">Rvvup Address Avs</label>
<hasPreview>1</hasPreview>
<sortable>false</sortable>
<draggable>false</draggable>
</settings>
</column>
<column name="rvvup_eci"
component="Magento_PageBuilder/js/grid/columns/preview-image"
class="Rvvup\Payments\Ui\Component\Listing\Column\Data">
<settings>
<label translate="true">Rvvup Eci</label>
<hasPreview>1</hasPreview>
<sortable>false</sortable>
<draggable>false</draggable>
</settings>
</column>
</columns>
</listing>
4 changes: 4 additions & 0 deletions view/adminhtml/web/images/green.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions view/adminhtml/web/images/grey.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions view/adminhtml/web/images/red.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading