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.13 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 32

class AdyenHppConfigProvider implements ConfigProviderInterface
{

33 34
    const CODE = 'adyen_hpp';

35 36 37 38 39 40 41 42 43 44
    /**
     * @var PaymentHelper
     */
    protected $_paymentHelper;

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

45
    /**
46 47 48
     * Request object
     *
     * @var \Magento\Framework\App\RequestInterface
49
     */
50
    protected $_request;
51 52

    /**
53
     * @var \Magento\Framework\UrlInterface
54
     */
55
    protected $_urlBuilder;
56

57 58 59 60 61
    /**
     * @var \Magento\Customer\Model\Session
     */
    protected $_customerSession;

62 63 64 65
    /**
     * @var \Magento\Checkout\Model\Session
     */
    protected $_session;
66

67
    /**
68 69
     * AdyenHppConfigProvider constructor.
     *
70
     * @param PaymentHelper $paymentHelper
71
     * @param \Adyen\Payment\Helper\Data $adyenHelper
72 73 74
     * @param \Magento\Framework\App\RequestInterface $request
     * @param \Magento\Framework\UrlInterface $urlBuilder
     * @param \Magento\Customer\Model\Session $customerSession
75
     * @param \Magento\Checkout\Model\Session $session
76 77
     */
    public function __construct(
78
        PaymentHelper $paymentHelper,
79 80
        \Adyen\Payment\Helper\Data $adyenHelper,
        \Magento\Framework\App\RequestInterface $request,
81
        \Magento\Framework\UrlInterface $urlBuilder,
82 83
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Checkout\Model\Session $session
84
    ) {
85 86
        $this->_paymentHelper = $paymentHelper;
        $this->_adyenHelper = $adyenHelper;
87 88
        $this->_request = $request;
        $this->_urlBuilder = $urlBuilder;
89
        $this->_customerSession = $customerSession;
90
        $this->_session = $session;
91 92
    }

93
    /**
94
     * Set configuration for AdyenHPP payment method
95
     *
96 97
     * @return array
     */
98 99
    public function getConfig()
    {
100
        // set to active
101 102
        $config = [
            'payment' => [
103 104 105
                self::CODE => [
                    'isActive' => true,
                    'redirectUrl' => $this->_urlBuilder->getUrl(
106 107 108
                        'adyen/process/redirect',
                        ['_secure' => $this->_getRequest()->isSecure()]
                    )
109 110 111
                ]
            ]
        ];
112

113 114 115
        $gender = "";
        $dob = "";

116 117 118 119 120 121 122 123
        // get customer
        if ($this->_customerSession->isLoggedIn()) {
            $gender = \Adyen\Payment\Model\Gender::getAdyenGenderFromMagentoGender(
                $this->_customerSession->getCustomerData()->getGender()
            );

            // format to calendar date
            $dob = $this->_customerSession->getCustomerData()->getDob();
124
            if ($dob) {
125 126 127
                $dob = strtotime($dob);
                $dob = date('m/d/Y', $dob);
            }
128
        }
129

130 131 132 133 134 135 136
        // add to config
        $config['payment'] ['adyenHpp']['gender'] = $gender;
        $config['payment'] ['adyenHpp']['dob'] = $dob;

        // gender types
        $config['payment'] ['adyenHpp']['genderTypes'] = \Adyen\Payment\Model\Gender::getGenderTypes();

137 138
        $paymentMethodSelectionOnAdyen =
            $this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen');
139

140
        $config['payment'] ['adyenHpp']['isPaymentMethodSelectionOnAdyen'] = $paymentMethodSelectionOnAdyen;
141 142
        $config['payment'] ['adyenHpp']['showGender'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_gender');
        $config['payment'] ['adyenHpp']['showDob'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_dob');
143
        $config['payment'] ['adyenHpp']['showTelephone'] = $this->_adyenHelper->getAdyenHppConfigDataFlag(
144 145
            'show_telephone'
        );
146
        $config['payment'] ['adyenHpp']['ratePayId'] = $this->_adyenHelper->getRatePayId();
147 148
        $config['payment'] ['adyenHpp']['deviceIdentToken'] = md5($this->_session->getQuoteId() . date('c'));
        $config['payment'] ['adyenHpp']['nordicCountries'] = ['SE', 'NO', 'DK', 'FI'];
149

150 151
        return $config;
    }
152 153 154 155 156 157 158 159 160 161

    /**
     * Retrieve request object
     *
     * @return \Magento\Framework\App\RequestInterface
     */
    protected function _getRequest()
    {
        return $this->_request;
    }
162
}