1 | <?php |
||
2 | |||
3 | /** |
||
4 | * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify |
||
5 | * it under the terms of the GNU Lesser General Public License as published by |
||
6 | * the Free Software Foundation, either version 3 of the License, or |
||
7 | * (at your option) any later version. |
||
8 | * |
||
9 | * PAYONE Magento 2 Connector is distributed in the hope that it will be useful, |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
12 | * GNU Lesser General Public License for more details. |
||
13 | * |
||
14 | * You should have received a copy of the GNU Lesser General Public License |
||
15 | * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. |
||
16 | * |
||
17 | * PHP version 5 |
||
18 | * |
||
19 | * @category Payone |
||
20 | * @package Payone_Magento2_Plugin |
||
21 | * @author FATCHIP GmbH <[email protected]> |
||
22 | * @copyright 2003 - 2024 Payone GmbH |
||
23 | * @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
||
24 | * @link http://www.payone.de |
||
25 | */ |
||
26 | |||
27 | namespace Payone\Core\Block\Paypal; |
||
28 | |||
29 | use Magento\Framework\View\Element\Template; |
||
0 ignored issues
–
show
|
|||
30 | use Payone\Core\Model\Methods\PayoneMethod; |
||
31 | use Payone\Core\Model\PayoneConfig; |
||
32 | |||
33 | /** |
||
34 | * Block class for the PayPal Express V2 button |
||
35 | */ |
||
36 | class ExpressButtonV2 extends Base |
||
37 | { |
||
38 | /** |
||
39 | * Shortcut alias |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $alias = 'payone.block.paypal.expressbuttonv2'; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $sTemplate = 'paypal/express_buttonv2.phtml'; |
||
49 | |||
50 | /** |
||
51 | * PAYONE payment helper |
||
52 | * |
||
53 | * @var \Payone\Core\Helper\Payment |
||
54 | */ |
||
55 | protected $paymentHelper; |
||
56 | |||
57 | /** |
||
58 | * PAYONE API helper |
||
59 | * |
||
60 | * @var \Payone\Core\Helper\Api |
||
61 | */ |
||
62 | protected $apiHelper; |
||
63 | |||
64 | /** |
||
65 | * Payment helper object |
||
66 | * |
||
67 | * @var \Magento\Payment\Helper\Data |
||
0 ignored issues
–
show
The type
Magento\Payment\Helper\Data was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
68 | */ |
||
69 | protected $dataHelper; |
||
70 | |||
71 | /** |
||
72 | * @var \Magento\Checkout\Model\Session; |
||
0 ignored issues
–
show
The type
Magento\Checkout\Model\Session was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
73 | */ |
||
74 | protected $checkoutSession; |
||
75 | |||
76 | /** |
||
77 | * @var PayoneMethod |
||
78 | */ |
||
79 | protected $methodInstance = null; |
||
80 | |||
81 | /** |
||
82 | * Constructor |
||
83 | * |
||
84 | * @param \Magento\Framework\View\Element\Template\Context $context |
||
85 | * @param \Magento\Framework\Locale\ResolverInterface $localeResolver |
||
86 | * @param \Payone\Core\Helper\Payment $paymentHelper |
||
87 | * @param \Payone\Core\Helper\Api $apiHelper |
||
88 | * @param \Magento\Payment\Helper\Data $dataHelper |
||
89 | * @param \Magento\Checkout\Model\Session $checkoutSession |
||
90 | * @param array $data |
||
91 | */ |
||
92 | public function __construct( |
||
93 | \Magento\Framework\View\Element\Template\Context $context, |
||
0 ignored issues
–
show
The type
Magento\Framework\View\Element\Template\Context was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
94 | \Magento\Framework\Locale\ResolverInterface $localeResolver, |
||
0 ignored issues
–
show
The type
Magento\Framework\Locale\ResolverInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
95 | \Payone\Core\Helper\Payment $paymentHelper, |
||
96 | \Payone\Core\Helper\Api $apiHelper, |
||
97 | \Magento\Payment\Helper\Data $dataHelper, |
||
98 | \Magento\Checkout\Model\Session $checkoutSession, |
||
99 | array $data = [] |
||
100 | ) { |
||
101 | parent::__construct($context, $localeResolver, $data); |
||
102 | $this->paymentHelper = $paymentHelper; |
||
103 | $this->apiHelper = $apiHelper; |
||
104 | $this->dataHelper = $dataHelper; |
||
105 | $this->checkoutSession = $checkoutSession; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @return PayoneMethod |
||
110 | */ |
||
111 | public function getMethodInstance() |
||
112 | { |
||
113 | if ($this->methodInstance === null) { |
||
114 | $this->methodInstance = $this->dataHelper->getMethodInstance(PayoneConfig::METHOD_PAYPALV2); |
||
115 | } |
||
116 | return $this->methodInstance; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @return string |
||
121 | */ |
||
122 | public function getStoreCode() |
||
123 | { |
||
124 | return $this->checkoutSession->getQuote()->getStore()->getCode(); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @return int|mixed |
||
129 | */ |
||
130 | public function getQuoteId() |
||
131 | { |
||
132 | return $this->checkoutSession->getQuote()->getId(); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | public function getButtonColor() |
||
139 | { |
||
140 | return $this->getMethodInstance()->getCustomConfigParam('button_color'); |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @return string |
||
145 | */ |
||
146 | public function getButtonShape() |
||
147 | { |
||
148 | return $this->getMethodInstance()->getCustomConfigParam('button_shape'); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @return bool |
||
153 | */ |
||
154 | protected function showBNPLButton() |
||
155 | { |
||
156 | $blReturn = false; |
||
157 | if ($this->paymentHelper->getConfigParam('show_bnpl_button', PayoneConfig::METHOD_PAYPALV2, 'payone_payment')) { |
||
158 | $blReturn = true; |
||
159 | } |
||
160 | return $blReturn; |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * @return string |
||
165 | */ |
||
166 | protected function getIntent() |
||
167 | { |
||
168 | return "authorize"; // authorize = preauthorize // capture = authorize but Payone said to always use authorize |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * @return string |
||
173 | */ |
||
174 | protected function getCurrency() |
||
175 | { |
||
176 | $sCurrency = $this->apiHelper->getCurrencyFromQuote($this->checkoutSession->getQuote()); |
||
177 | if (empty($sCurrency)) { |
||
178 | // currency will be empty when the first item is put into the basket |
||
179 | // read default currency settings from config and use them in that case |
||
180 | $sCurrency = $this->getDefaultCurrency(); |
||
181 | } |
||
182 | return $sCurrency; |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @return string |
||
187 | */ |
||
188 | protected function getDefaultCurrency() |
||
189 | { |
||
190 | $sCurrency = $this->apiHelper->getConfigParam('base', 'options', 'currency'); |
||
191 | if ($this->getConfigParam('currency', 'global', 'payone_general', $this->checkoutSession->getQuote()->getStore()->getCode()) == 'display') { |
||
192 | $sCurrency = $this->apiHelper->getConfigParam('default', 'options', 'currency'); |
||
193 | } |
||
194 | return $sCurrency; |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * @return string |
||
199 | */ |
||
200 | protected function getMerchantId() |
||
201 | { |
||
202 | $sMerchantId = "3QK84QGGJE5HW"; // Default for testmode (fixed) |
||
203 | |||
204 | $oMethodInstance = $this->getMethodInstance(); |
||
205 | if ($oMethodInstance && $oMethodInstance->getOperationMode() == 'live') { |
||
206 | $sMerchantId = $oMethodInstance->getCustomConfigParam('merchant_id'); // Get from config for live |
||
207 | } |
||
208 | return $sMerchantId; |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * @return string |
||
213 | */ |
||
214 | protected function getClientId() |
||
215 | { |
||
216 | $sClientId = "AUn5n-4qxBUkdzQBv6f8yd8F4AWdEvV6nLzbAifDILhKGCjOS62qQLiKbUbpIKH_O2Z3OL8CvX7ucZfh"; // Default for testmode (fixed) |
||
217 | |||
218 | $oMethodInstance = $this->getMethodInstance(); |
||
219 | if ($oMethodInstance && $oMethodInstance->getOperationMode() == 'live') { |
||
220 | $sClientId = "AVNBj3ypjSFZ8jE7shhaY2mVydsWsSrjmHk0qJxmgJoWgHESqyoG35jLOhH3GzgEPHmw7dMFnspH6vim"; // Livemode (fixed) |
||
221 | } |
||
222 | return $sClientId; |
||
223 | } |
||
224 | |||
225 | /** |
||
226 | * @return string |
||
227 | */ |
||
228 | public function getJavascriptUrl() |
||
229 | { |
||
230 | $sUrl = "https://www.paypal.com/sdk/js?client-id=".$this->getClientId()."&merchant-id=".$this->getMerchantId()."¤cy=".$this->getCurrency()."&intent=".$this->getIntent()."&locale=".$this->getLocale()."&commit=false&vault=false&disable-funding=card,sepa,bancontact"; |
||
231 | if ($this->showBNPLButton() === true) { |
||
232 | $sUrl .= "&enable-funding=paylater"; |
||
233 | } |
||
234 | return $sUrl; |
||
235 | } |
||
236 | } |
||
237 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths