1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Payone\Core\Model\ApplePay; |
4
|
|
|
|
5
|
|
|
use Payone\Core\Model\PayoneConfig; |
6
|
|
|
|
7
|
|
|
class SessionHandler |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Magento 2 Curl library |
11
|
|
|
* |
12
|
|
|
* @var \Magento\Framework\HTTP\Client\Curl |
|
|
|
|
13
|
|
|
*/ |
14
|
|
|
protected $curl; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Payone shop helper object |
18
|
|
|
* |
19
|
|
|
* @var \Payone\Core\Helper\Shop |
20
|
|
|
*/ |
21
|
|
|
protected $shopHelper; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Payone Apple Pay helper object |
25
|
|
|
* |
26
|
|
|
* @var \Payone\Core\Helper\ApplePay |
27
|
|
|
*/ |
28
|
|
|
protected $applePayHelper; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Request URL for collecting the Apple Pay session |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $applePaySessionUrl = "https://apple-pay-gateway-cert.apple.com/paymentservices/startSession"; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Constructor |
39
|
|
|
* |
40
|
|
|
* @param \Magento\Framework\HTTP\Client\Curl $curl |
41
|
|
|
* @param \Payone\Core\Helper\Shop $shopHelper |
42
|
|
|
* @param \Payone\Core\Helper\ApplePay $applePayHelper |
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
\Magento\Framework\HTTP\Client\Curl $curl, |
46
|
|
|
\Payone\Core\Helper\Shop $shopHelper, |
47
|
|
|
\Payone\Core\Helper\ApplePay $applePayHelper |
48
|
|
|
) { |
49
|
|
|
$this->curl = $curl; |
50
|
|
|
$this->shopHelper = $shopHelper; |
51
|
|
|
$this->applePayHelper = $applePayHelper; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns shop domain |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
protected function getShopDomain() |
60
|
|
|
{ |
61
|
|
|
$aUrl = parse_url($this->shopHelper->getStoreBaseUrl()); |
62
|
|
|
if (!empty($aUrl['host'])) { |
63
|
|
|
return $aUrl['host']; |
64
|
|
|
} |
65
|
|
|
return ""; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns path to certificate file |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
* @throws \Exception |
73
|
|
|
*/ |
74
|
|
|
protected function getCertificateFilePath() |
75
|
|
|
{ |
76
|
|
|
$sCertFile = $this->shopHelper->getConfigParam("certificate_file", PayoneConfig::METHOD_APPLEPAY, "payment"); |
77
|
|
|
$sCertFilePath = $this->applePayHelper->getApplePayUploadPath().$sCertFile; |
78
|
|
|
|
79
|
|
|
if ($this->applePayHelper->hasCertificateFile() === false) { |
80
|
|
|
throw new \Exception("Certificate file not configured or missing"); |
81
|
|
|
} |
82
|
|
|
return $sCertFilePath; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns path to private key file |
87
|
|
|
* |
88
|
|
|
* @return string |
89
|
|
|
* @throws \Exception |
90
|
|
|
*/ |
91
|
|
|
protected function getPrivateKeyFilePath() |
92
|
|
|
{ |
93
|
|
|
$sPrivateKeyFile = $this->shopHelper->getConfigParam("private_key_file", PayoneConfig::METHOD_APPLEPAY, "payment"); |
94
|
|
|
$sPrivateKeyFilePath = $this->applePayHelper->getApplePayUploadPath().$sPrivateKeyFile; |
95
|
|
|
|
96
|
|
|
if ($this->applePayHelper->hasPrivateKeyFile() === false) { |
97
|
|
|
throw new \Exception("Private key file not configured or missing"); |
98
|
|
|
} |
99
|
|
|
return $sPrivateKeyFilePath; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Requests apple pay session and returns it |
104
|
|
|
* |
105
|
|
|
* @return bool|string |
106
|
|
|
* @throws \Exception |
107
|
|
|
*/ |
108
|
|
|
public function getApplePaySession() |
109
|
|
|
{ |
110
|
|
|
$aRequest = [ |
111
|
|
|
'merchantIdentifier' => $this->shopHelper->getConfigParam("merchant_id", PayoneConfig::METHOD_APPLEPAY, "payment"), |
112
|
|
|
'displayName' => 'PAYONE Apple Pay Magento2', |
113
|
|
|
'initiative' => 'web', |
114
|
|
|
'initiativeContext' => $this->getShopDomain(), |
115
|
|
|
]; |
116
|
|
|
|
117
|
|
|
$this->curl->setOption(CURLOPT_SSL_VERIFYHOST, 0); |
118
|
|
|
$this->curl->setOption(CURLOPT_SSL_VERIFYPEER, 0); |
119
|
|
|
$this->curl->setOption(CURLOPT_RETURNTRANSFER, 1); |
120
|
|
|
$this->curl->setOption(CURLOPT_RETURNTRANSFER, 1); |
121
|
|
|
$this->curl->setOption(CURLOPT_SSLCERT, $this->getCertificateFilePath()); |
122
|
|
|
$this->curl->setOption(CURLOPT_SSLKEY, $this->getPrivateKeyFilePath()); |
123
|
|
|
|
124
|
|
|
$sKeyPass = $this->shopHelper->getConfigParam("private_key_password", PayoneConfig::METHOD_APPLEPAY, "payment"); |
125
|
|
|
if (!empty($sKeyPass)) { |
126
|
|
|
$this->curl->setOption( CURLOPT_KEYPASSWD, $sKeyPass); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$this->curl->post($this->applePaySessionUrl, json_encode($aRequest)); |
130
|
|
|
return $this->curl->getBody(); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
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