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

AdyenHppConfigProvider.php 5.01 KB
Newer Older
1 2
<?php
/**
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *                       ######
 *                       ######
 * ############    ####( ######  #####. ######  ############   ############
 * #############  #####( ######  #####. ######  #############  #############
 *        ######  #####( ######  #####. ######  #####  ######  #####  ######
 * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
 * ###### ######  #####( ######  #####. ######  #####          #####  ######
 * #############  #############  #############  #############  #####  ######
 *  ############   ############  #############   ############  #####  ######
 *                                      ######
 *                               #############
 *                               ############
 *
 * Adyen Payment module (https://www.adyen.com/)
 *
 * Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
 * See LICENSE.txt for license details.
 *
 * Author: Adyen <magento@adyen.com>
22
 */
23

24
namespace Adyen\Payment\Model\Ui;
25 26 27

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Payment\Helper\Data as PaymentHelper;
28
use Magento\Directory\Helper\Data;
29 30 31

class AdyenHppConfigProvider implements ConfigProviderInterface
{
32 33
    const CODE = 'adyen_hpp';

34 35 36
    /**
     * @var PaymentHelper
     */
attilak's avatar
attilak committed
37
    protected $paymentHelper;
38 39 40 41

    /**
     * @var \Adyen\Payment\Helper\Data
     */
attilak's avatar
attilak committed
42
    protected $adyenHelper;
43

44
    /**
45 46 47
     * Request object
     *
     * @var \Magento\Framework\App\RequestInterface
48
     */
attilak's avatar
attilak committed
49
    protected $request;
50 51

    /**
52
     * @var \Magento\Framework\UrlInterface
53
     */
attilak's avatar
attilak committed
54
    protected $urlBuilder;
55

56 57 58
    /**
     * @var \Magento\Customer\Model\Session
     */
attilak's avatar
attilak committed
59
    protected $customerSession;
60

61 62 63
    /**
     * @var \Magento\Checkout\Model\Session
     */
attilak's avatar
attilak committed
64 65
    protected $session;

66 67 68
    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
attilak's avatar
attilak committed
69
    protected $storeManager;
70

71 72 73 74 75
    /**
     * @var \Adyen\Payment\Model\Gender
     */
    protected $gender;

76
    /**
77 78
     * AdyenHppConfigProvider constructor.
     *
79
     * @param PaymentHelper $paymentHelper
80
     * @param \Adyen\Payment\Helper\Data $adyenHelper
81 82 83
     * @param \Magento\Framework\App\RequestInterface $request
     * @param \Magento\Framework\UrlInterface $urlBuilder
     * @param \Magento\Customer\Model\Session $customerSession
84
     * @param \Magento\Checkout\Model\Session $session
85
     * @param \Adyen\Payment\Model\Gender
86 87
     */
    public function __construct(
88
        PaymentHelper $paymentHelper,
89 90
        \Adyen\Payment\Helper\Data $adyenHelper,
        \Magento\Framework\App\RequestInterface $request,
91
        \Magento\Framework\UrlInterface $urlBuilder,
92
        \Magento\Customer\Model\Session $customerSession,
attilak's avatar
attilak committed
93
        \Magento\Checkout\Model\Session $session,
94 95
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Adyen\Payment\Model\Gender $gender
96
    ) {
attilak's avatar
attilak committed
97 98 99 100 101 102 103
        $this->paymentHelper = $paymentHelper;
        $this->adyenHelper = $adyenHelper;
        $this->request = $request;
        $this->urlBuilder = $urlBuilder;
        $this->customerSession = $customerSession;
        $this->session = $session;
        $this->storeManager = $storeManager;
104
        $this->gender = $gender;
105 106
    }

107
    /**
108
     * Set configuration for AdyenHPP payment method
109
     *
110 111
     * @return array
     */
112 113
    public function getConfig()
    {
114
        // set to active
115 116
        $config = [
            'payment' => [
117 118
                self::CODE => [
                    'isActive' => true,
attilak's avatar
attilak committed
119
                    'redirectUrl' => $this->urlBuilder->getUrl(
120
                        'adyen/process/redirect',
attilak's avatar
attilak committed
121
                        ['_secure' => $this->getRequest()->isSecure()]
122
                    )
123 124 125
                ]
            ]
        ];
126

127
        $genderConfig = "";
128 129
        $dob = "";

130
        // get customer
attilak's avatar
attilak committed
131
        if ($this->customerSession->isLoggedIn()) {
132
            $genderConfig = $this->gender->getAdyenGenderFromMagentoGender(
attilak's avatar
attilak committed
133
                $this->customerSession->getCustomerData()->getGender()
134 135 136
            );

            // format to calendar date
attilak's avatar
attilak committed
137
            $dob = $this->customerSession->getCustomerData()->getDob();
138
            if ($dob) {
139 140 141
                $dob = strtotime($dob);
                $dob = date('m/d/Y', $dob);
            }
142
        }
143

144 145 146
        $adyenHppConfig['locale'] = $this->adyenHelper->getCurrentLocaleCode(
            $this->storeManager->getStore()->getId()
        );
attilak's avatar
attilak committed
147

148
        // add to config
149 150
        $adyenHppConfig['gender'] = $genderConfig;
        $adyenHppConfig['dob'] = $dob;
151 152

        // gender types
153
        $adyenHppConfig['genderTypes'] =  $this->gender->getGenderTypes();
154

155 156 157
        $adyenHppConfig['ratePayId'] = $this->adyenHelper->getRatePayId();
        $adyenHppConfig['deviceIdentToken'] = hash("sha256", $this->session->getQuoteId() . date('c'));
        $adyenHppConfig['nordicCountries'] = ['SE', 'NO', 'DK', 'FI'];
158

159
        $config['payment']['adyenHpp'] = $adyenHppConfig;
160 161
        return $config;
    }
162 163 164 165 166 167

    /**
     * Retrieve request object
     *
     * @return \Magento\Framework\App\RequestInterface
     */
attilak's avatar
attilak committed
168
    protected function getRequest()
169
    {
attilak's avatar
attilak committed
170
        return $this->request;
171
    }
172
}