We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Redirect.php 3.06 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
<?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\Block\Transparent;

26
use Adyen\Payment\Helper\Data;
27 28 29 30 31 32 33 34 35
use Adyen\Service\Validator\DataArrayValidator;
use Magento\Framework\View\Element\Template;

class Redirect extends Template
{
    /**
     * @var \Magento\Framework\UrlInterface
     */
    private $url;
36

37 38 39 40
    /**
     * @var \Adyen\Payment\Logger\AdyenLogger
     */
    protected $adyenLogger;
41 42 43 44 45 46

    /**
     * @var Data
     */
    protected $adyenHelper;

47 48
    /**
     * Redirect constructor.
49
     *
50 51 52 53 54 55 56 57
     * @param Template\Context $context
     * @param \Magento\Framework\UrlInterface $url
     * @param array $data
     */
    public function __construct(
        Template\Context $context,
        \Magento\Framework\UrlInterface $url,
        \Adyen\Payment\Logger\AdyenLogger $adyenLogger,
58
        Data $adyenHelper,
59 60 61 62
        array $data = []
    ) {
        $this->url = $url;
        $this->adyenLogger = $adyenLogger;
63
        $this->adyenHelper = $adyenHelper;
64 65 66 67 68
        parent::__construct($context, $data);
    }

    /**
     * Returns url for redirect.
69
     *
70 71 72 73
     * @return string|null
     */
    public function getRedirectUrl()
    {
74 75 76 77 78 79 80 81 82 83 84 85 86 87
        $pwaOrigin = $this->adyenHelper->getAdyenAbstractConfigData("payment_origin_url", $this->_storeManager->getStore()->getId());

        if ($pwaOrigin) {
            $returnUrl = $pwaOrigin . "/adyen/process/result";
        } else {
            $returnUrl = $this->url->getUrl("adyen/process/result");
        }

        if (!empty($this->getRequest()->getQueryValue())) {
            $query = http_build_query($this->getRequest()->getQueryValue(), '', '&');
            $returnUrl .= '?' . $query;
        }

        return $returnUrl;
88 89 90 91
    }

    /**
     * Returns params to be redirected.
92
     *
93 94 95 96 97 98 99 100 101 102 103 104 105
     * @return array
     */
    public function getPostParams()
    {
        $postParams = (array)$this->_request->getPostValue();
        $allowedPostParams = array('MD', 'PaRes');
        $postParams = DataArrayValidator::getArrayOnlyWithApprovedKeys($postParams, $allowedPostParams);
        $this->adyenLogger->addAdyenDebug(
            'Adyen 3DS1 PostParams forwarded to process redirect endpoint'
        );
        return $postParams;
    }
}