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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2019 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\Ui;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Payment\Helper\Data as PaymentHelper;
class AdyenGooglePayConfigProvider implements ConfigProviderInterface
{
const CODE = 'adyen_google_pay';
const GOOGLE_PAY_VAULT_CODE = 'adyen_google_pay_vault';
const PRODUCTION = 'production';
/**
* @var PaymentHelper
*/
protected $paymentHelper;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $adyenHelper;
/**
* @var \Magento\Framework\UrlInterface
*/
protected $urlBuilder;
/**
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_request;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;
/**
* AdyenGooglePayConfigProvider constructor.
*
* @param PaymentHelper $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Framework\UrlInterface $urlBuilder
*/
public function __construct(
PaymentHelper $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Checkout\Model\Session $checkoutSession
) {
$this->paymentHelper = $paymentHelper;
$this->adyenHelper = $adyenHelper;
$this->_request = $request;
$this->urlBuilder = $urlBuilder;
$this->storeManager = $storeManager;
$this->checkoutSession = $checkoutSession;
}
/**
* Retrieve assoc array of checkout configuration
*
* @return array
*/
public function getConfig()
{
// set to active
$config = [
'payment' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->urlBuilder->getUrl(
'checkout/onepage/success/',
['_secure' => $this->_getRequest()->isSecure()]
)
]
]
];
$adyenGooglePayConfig['active'] = (bool)$this->adyenHelper->isAdyenGooglePayEnabled(
$this->storeManager->getStore()->getId()
);
$adyenGooglePayConfig['checkoutEnvironment'] = $this->getGooglePayEnvironment(
$this->storeManager->getStore()->getId()
);
$adyenGooglePayConfig['locale'] = $this->adyenHelper->getStoreLocale(
$this->storeManager->getStore()->getId()
);
$adyenGooglePayConfig['merchantAccount'] = $this->adyenHelper->getAdyenMerchantAccount(
"adyen_google_pay",
$this->storeManager->getStore()->getId()
);
$quote = $this->checkoutSession->getQuote();
$currency = $quote->getCurrency();
$adyenGooglePayConfig['format'] = $this->adyenHelper->decimalNumbers($currency);
$adyenGooglePayConfig['merchantIdentifier'] = $this->adyenHelper->getAdyenGooglePayMerchantIdentifier($this->storeManager->getStore()->getId());
$config['payment']['adyenGooglePay'] = $adyenGooglePayConfig;
return $config;
}
/**
* Retrieve request object
*
* @return \Magento\Framework\App\RequestInterface
*/
protected function _getRequest()
{
return $this->_request;
}
/**
* @param null $storeId
* @return mixed
*/
private function getGooglePayEnvironment($storeId = null)
{
if ($this->adyenHelper->isDemoMode($storeId)) {
return \Adyen\Payment\Helper\Data::TEST;
}
return self::PRODUCTION;
}
}