1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Service; |
4
|
|
|
|
5
|
|
|
use Adyen\AdyenException; |
6
|
|
|
use Adyen\Client; |
7
|
|
|
use Adyen\Environment; |
8
|
|
|
use Adyen\Service\Checkout; |
9
|
|
|
use Psr\Log\LoggerInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class AdyenService |
13
|
|
|
* @package App\Service |
14
|
|
|
*/ |
15
|
|
|
class AdyenService |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var SettingsService |
19
|
|
|
*/ |
20
|
|
|
protected $settingsService; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var LoggerInterface |
24
|
|
|
*/ |
25
|
|
|
protected $logger; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var $merchantAccount |
29
|
|
|
*/ |
30
|
|
|
private $merchantAccount; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var $clientKey |
34
|
|
|
*/ |
35
|
|
|
private $clientKey; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var $paypalId |
39
|
|
|
*/ |
40
|
|
|
private $paypalId; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var Client |
44
|
|
|
*/ |
45
|
|
|
protected $checkout; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* AdyenService constructor. |
49
|
|
|
* |
50
|
|
|
* @param string $apiKey |
51
|
|
|
* @param string $merchantAccount |
52
|
|
|
* @param string $clientKey |
53
|
|
|
* @param string $paypalId |
54
|
|
|
* @param SettingsService $settingsService |
55
|
|
|
* @throws AdyenException |
56
|
|
|
*/ |
57
|
|
|
public function __construct( |
58
|
|
|
string $apiKey, |
59
|
|
|
string $merchantAccount, |
60
|
|
|
string $clientKey, |
61
|
|
|
string $paypalId, |
62
|
|
|
SettingsService $settingsService |
63
|
|
|
) { |
64
|
|
|
$client = new Client(); |
65
|
|
|
$client->setXApiKey($apiKey); |
66
|
|
|
$client->setEnvironment(Environment::TEST); |
67
|
|
|
|
68
|
|
|
$this->checkout = new Checkout($client); |
|
|
|
|
69
|
|
|
$this->merchantAccount = $merchantAccount; |
70
|
|
|
$this->clientKey = $clientKey; |
71
|
|
|
$this->settingsService = $settingsService; |
72
|
|
|
$this->paypalId = $paypalId; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function getClientKey(): string |
79
|
|
|
{ |
80
|
|
|
return $this->clientKey; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
public function getPayPalId(): string |
87
|
|
|
{ |
88
|
|
|
return $this->paypalId; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return mixed |
93
|
|
|
* @throws AdyenException |
94
|
|
|
*/ |
95
|
|
|
public function getPaymentMethods() |
96
|
|
|
{ |
97
|
|
|
$params = [ |
98
|
|
|
"allowedPaymentMethods" => ["paypal","card"], |
99
|
|
|
"merchantAccount" => $this->merchantAccount, |
100
|
|
|
"countryCode" => $this->settingsService->getSetting('settings-customer-country'), |
101
|
|
|
"shopperLocale" => $this->settingsService->getSetting('settings-customer-locale'), |
102
|
|
|
"amount" => [ |
103
|
|
|
"currency" => $this->settingsService->getSetting('settings-customer-currency'), |
104
|
|
|
"value" => 100 * $this->settingsService->getSetting('settings-item-price'), |
105
|
|
|
], |
106
|
|
|
"channel" => "Web" |
107
|
|
|
]; |
108
|
|
|
|
109
|
|
|
return $this->checkout->paymentMethods($params); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param $data |
114
|
|
|
* @return mixed |
115
|
|
|
* @throws AdyenException |
116
|
|
|
*/ |
117
|
|
|
public function makePayment($data) |
118
|
|
|
{ |
119
|
|
|
$params = [ |
120
|
|
|
"amount" => $data['amount'], |
121
|
|
|
"reference" => rand(1, 1000000), |
122
|
|
|
"paymentMethod" => $data['paymentMethod'], |
123
|
|
|
"merchantAccount" => $this->merchantAccount, |
124
|
|
|
]; |
125
|
|
|
|
126
|
|
|
return $this->checkout->payments($params); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param $data |
131
|
|
|
* @return mixed |
132
|
|
|
* @throws AdyenException |
133
|
|
|
*/ |
134
|
|
|
public function paymentDetails($data) |
135
|
|
|
{ |
136
|
|
|
return $this->checkout->paymentsDetails($data); |
|
|
|
|
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..