We will be off on April 7th (Monday) for public holiday in our country

NotificationColumn.php 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
<?php
/**
 *                       ######
 *                       ######
 * ############    ####( ######  #####. ######  ############   ############
 * #############  #####( ######  #####. ######  #############  #############
 *        ######  #####( ######  #####. ######  #####  ######  #####  ######
 * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
 * ###### ######  #####( ######  #####. ######  #####          #####  ######
 * #############  #############  #############  #############  #####  ######
 *  ############   ############  #############   ############  #####  ######
 *                                      ######
 *                               #############
 *                               ############
 *
 * Adyen Payment module (https://www.adyen.com/)
 *
 * Copyright (c) 2020 Adyen BV (https://www.adyen.com/)
 * See LICENSE.txt for license details.
 *
 * Author: Adyen <magento@adyen.com>
 */

namespace Adyen\Payment\Ui\Component\Listing\Column;

class NotificationColumn extends \Magento\Ui\Component\Listing\Columns\Column
{

    /**
     * @var \Magento\Sales\Api\Data\OrderInterface
     */
    protected $orderInterface;

    /**
     * @var \Magento\Backend\Helper\Data
     */
    protected $backendHelper;

    /**
     * @var \Adyen\Payment\Helper\Data
     */
    protected $adyenHelper;

    public function __construct(
        \Magento\Sales\Api\Data\OrderInterface $orderInterface,
        \Magento\Backend\Helper\Data $backendHelper,
        \Adyen\Payment\Helper\Data $adyenHelper,
        \Magento\Framework\View\Element\UiComponent\ContextInterface $context,
        \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory,
        array $components = [],
        array $data = []
    ) {
        $this->orderInterface = $orderInterface;
        $this->backendHelper = $backendHelper;
        $this->adyenHelper = $adyenHelper;
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }


    /**
     * Style and format Adyen notification columns
     *
     * @param array $dataSource
     * @return array
     */
    public function prepareDataSource(array $dataSource)
    {

        if (empty($dataSource['data']['items'])) {
            return $dataSource;
        }

        foreach ($dataSource['data']['items'] as & $item) {

            $class = "grid-severity-critical";
            if ($item["success"] == "true") {
                $class = "grid-severity-notice";
            }
            $item["success"] = sprintf('<span class="%s">%s</span>', $class, $item["success"]);

            //Setting Status "fake" column value based on processing and done values
            if ($item["processing"] == 0) {
                if ($item["done"] == 0) {
                    $item["status"] = __("Queued");
                } else {
                    $item["status"] = __("Processed");
                }
            } else {
                $item["status"] = __("In progress");
            }

            //Adding anchor link to order number and PSP reference if order number exists
            $this->orderInterface->unsetData();
            $order = $this->orderInterface->loadByIncrementId($item["merchant_reference"]);
            if ($order->getId()) {

                $orderUrl = $this->backendHelper->getUrl("sales/order/view", ["order_id" => $order->getId()]);
                $item["merchant_reference"] = sprintf(
                    '<a href="%s">%s</a>',
                    $orderUrl,
                    $item["merchant_reference"]
                );
                $item["pspreference"] = sprintf(
                    '<a href="%s" target="_blank">%s</a>',
                    $this->adyenHelper->getPspReferenceSearchUrl(
                        $item["pspreference"],
                        $item["live"]
                    ),
                    $item["pspreference"]
                );

            }

        }

        return $dataSource;
    }
}