|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace SlevomatCsobGateway; |
|
4
|
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
|
6
|
|
|
use SlevomatCsobGateway\Api\HttpMethod; |
|
7
|
|
|
use SlevomatCsobGateway\Call\ApplePay\InitApplePayRequest; |
|
8
|
|
|
use SlevomatCsobGateway\Call\ApplePay\StartApplePayRequest; |
|
9
|
|
|
use SlevomatCsobGateway\Call\Button\PaymentButtonBrand; |
|
10
|
|
|
use SlevomatCsobGateway\Call\Button\PaymentButtonRequest; |
|
11
|
|
|
use SlevomatCsobGateway\Call\ClosePaymentRequest; |
|
12
|
|
|
use SlevomatCsobGateway\Call\CustomerInfoRequest; |
|
13
|
|
|
use SlevomatCsobGateway\Call\EchoRequest; |
|
14
|
|
|
use SlevomatCsobGateway\Call\InitPaymentRequest; |
|
15
|
|
|
use SlevomatCsobGateway\Call\Masterpass\BasicCheckoutRequest; |
|
16
|
|
|
use SlevomatCsobGateway\Call\Masterpass\BasicFinishRequest; |
|
17
|
|
|
use SlevomatCsobGateway\Call\Masterpass\StandardCheckoutRequest; |
|
18
|
|
|
use SlevomatCsobGateway\Call\Masterpass\StandardExtractRequest; |
|
19
|
|
|
use SlevomatCsobGateway\Call\Masterpass\StandardFinishRequest; |
|
20
|
|
|
use SlevomatCsobGateway\Call\OneClick\InitOneClickPaymentRequest; |
|
21
|
|
|
use SlevomatCsobGateway\Call\OneClick\OneClickEchoRequest; |
|
22
|
|
|
use SlevomatCsobGateway\Call\OneClick\StartOneClickPaymentRequest; |
|
23
|
|
|
use SlevomatCsobGateway\Call\PaymentStatusRequest; |
|
24
|
|
|
use SlevomatCsobGateway\Call\PayMethod; |
|
25
|
|
|
use SlevomatCsobGateway\Call\PayOperation; |
|
26
|
|
|
use SlevomatCsobGateway\Call\PostEchoRequest; |
|
27
|
|
|
use SlevomatCsobGateway\Call\ProcessPaymentRequest; |
|
28
|
|
|
use SlevomatCsobGateway\Call\ReceivePaymentRequest; |
|
29
|
|
|
use SlevomatCsobGateway\Call\RefundPaymentRequest; |
|
30
|
|
|
use SlevomatCsobGateway\Call\ReversePaymentRequest; |
|
31
|
|
|
|
|
32
|
|
|
class RequestFactory |
|
33
|
|
|
{ |
|
34
|
|
|
|
|
35
|
|
|
/** @var string */ |
|
36
|
|
|
private $merchantId; |
|
37
|
|
|
|
|
38
|
21 |
|
public function __construct(string $merchantId) |
|
39
|
|
|
{ |
|
40
|
21 |
|
$this->merchantId = $merchantId; |
|
41
|
21 |
|
} |
|
42
|
|
|
|
|
43
|
1 |
|
public function createInitPayment( |
|
44
|
|
|
string $orderId, |
|
45
|
|
|
PayOperation $payOperation, |
|
46
|
|
|
PayMethod $payMethod, |
|
47
|
|
|
bool $closePayment, |
|
48
|
|
|
string $returnUrl, |
|
49
|
|
|
HttpMethod $returnMethod, |
|
50
|
|
|
Cart $cart, |
|
51
|
|
|
?string $merchantData, |
|
52
|
|
|
?string $customerId, |
|
53
|
|
|
Language $language, |
|
54
|
|
|
?int $ttlSec = null, |
|
55
|
|
|
?int $logoVersion = null, |
|
56
|
|
|
?int $colorSchemeVersion = null, |
|
57
|
|
|
?DateTimeImmutable $customExpiry = null |
|
58
|
|
|
): InitPaymentRequest |
|
59
|
|
|
{ |
|
60
|
1 |
|
return new InitPaymentRequest( |
|
61
|
1 |
|
$this->merchantId, |
|
62
|
|
|
$orderId, |
|
63
|
|
|
$payOperation, |
|
64
|
|
|
$payMethod, |
|
65
|
|
|
$closePayment, |
|
66
|
|
|
$returnUrl, |
|
67
|
|
|
$returnMethod, |
|
68
|
|
|
$cart, |
|
69
|
|
|
$merchantData, |
|
70
|
|
|
$customerId, |
|
71
|
|
|
$language, |
|
72
|
|
|
$ttlSec, |
|
73
|
|
|
$logoVersion, |
|
74
|
|
|
$colorSchemeVersion, |
|
75
|
|
|
$customExpiry |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
public function createProcessPayment(string $payId): ProcessPaymentRequest |
|
80
|
|
|
{ |
|
81
|
1 |
|
return new ProcessPaymentRequest( |
|
82
|
1 |
|
$this->merchantId, |
|
83
|
|
|
$payId |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
1 |
|
public function createPaymentStatus(string $payId): PaymentStatusRequest |
|
88
|
|
|
{ |
|
89
|
1 |
|
return new PaymentStatusRequest( |
|
90
|
1 |
|
$this->merchantId, |
|
91
|
|
|
$payId |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
1 |
|
public function createReversePayment(string $payId): ReversePaymentRequest |
|
96
|
|
|
{ |
|
97
|
1 |
|
return new ReversePaymentRequest( |
|
98
|
1 |
|
$this->merchantId, |
|
99
|
|
|
$payId |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
1 |
|
public function createClosePayment(string $payId, ?int $totalAmount = null): ClosePaymentRequest |
|
104
|
|
|
{ |
|
105
|
1 |
|
return new ClosePaymentRequest( |
|
106
|
1 |
|
$this->merchantId, |
|
107
|
|
|
$payId, |
|
108
|
|
|
$totalAmount |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
1 |
|
public function createRefundPayment(string $payId, ?int $amount = null): RefundPaymentRequest |
|
113
|
|
|
{ |
|
114
|
1 |
|
return new RefundPaymentRequest( |
|
115
|
1 |
|
$this->merchantId, |
|
116
|
|
|
$payId, |
|
117
|
|
|
$amount |
|
118
|
|
|
); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
1 |
|
public function createEchoRequest(): EchoRequest |
|
122
|
|
|
{ |
|
123
|
1 |
|
return new EchoRequest( |
|
124
|
1 |
|
$this->merchantId |
|
125
|
|
|
); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
1 |
|
public function createPostEchoRequest(): PostEchoRequest |
|
129
|
|
|
{ |
|
130
|
1 |
|
return new PostEchoRequest( |
|
131
|
1 |
|
$this->merchantId |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
1 |
|
public function createCustomerInfo(string $customerId): CustomerInfoRequest |
|
136
|
|
|
{ |
|
137
|
1 |
|
return new CustomerInfoRequest( |
|
138
|
1 |
|
$this->merchantId, |
|
139
|
|
|
$customerId |
|
140
|
|
|
); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
1 |
|
public function createReceivePaymentRequest(): ReceivePaymentRequest |
|
144
|
|
|
{ |
|
145
|
1 |
|
return new ReceivePaymentRequest(); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
1 |
|
public function createOneclickInitPayment( |
|
149
|
|
|
string $origPayId, |
|
150
|
|
|
string $orderId, |
|
151
|
|
|
string $clientIp, |
|
152
|
|
|
?Price $price = null, |
|
153
|
|
|
?string $description = null |
|
154
|
|
|
): InitOneClickPaymentRequest |
|
155
|
|
|
{ |
|
156
|
1 |
|
return new InitOneClickPaymentRequest( |
|
157
|
1 |
|
$this->merchantId, |
|
158
|
|
|
$origPayId, |
|
159
|
|
|
$orderId, |
|
160
|
|
|
$clientIp, |
|
161
|
|
|
$price, |
|
162
|
|
|
$description |
|
163
|
|
|
); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
1 |
|
public function createOneclickStartPayment(string $payId): StartOneClickPaymentRequest |
|
167
|
|
|
{ |
|
168
|
1 |
|
return new StartOneClickPaymentRequest( |
|
169
|
1 |
|
$this->merchantId, |
|
170
|
|
|
$payId |
|
171
|
|
|
); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
1 |
|
public function createMasterpassBasicCheckoutRequest(string $payId, string $callbackUrl): BasicCheckoutRequest |
|
175
|
|
|
{ |
|
176
|
1 |
|
return new BasicCheckoutRequest( |
|
177
|
1 |
|
$this->merchantId, |
|
178
|
|
|
$payId, |
|
179
|
|
|
$callbackUrl |
|
180
|
|
|
); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param string $payId |
|
185
|
|
|
* @param mixed[] $callbackParams |
|
186
|
|
|
* @return \SlevomatCsobGateway\Call\Masterpass\BasicFinishRequest |
|
187
|
|
|
*/ |
|
188
|
1 |
|
public function createMasterpassBasicFinishRequest(string $payId, array $callbackParams): BasicFinishRequest |
|
189
|
|
|
{ |
|
190
|
1 |
|
return new BasicFinishRequest( |
|
191
|
1 |
|
$this->merchantId, |
|
192
|
|
|
$payId, |
|
193
|
|
|
$callbackParams |
|
194
|
|
|
); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
1 |
|
public function createMasterpassStandardCheckoutRequest(string $payId, string $callbackUrl, ?string $shippingLocationProfile = null): StandardCheckoutRequest |
|
198
|
|
|
{ |
|
199
|
1 |
|
return new StandardCheckoutRequest($this->merchantId, $payId, $callbackUrl, $shippingLocationProfile); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @param string $payId |
|
204
|
|
|
* @param mixed[] $callbackParams |
|
205
|
|
|
* @return \SlevomatCsobGateway\Call\Masterpass\StandardExtractRequest |
|
206
|
|
|
*/ |
|
207
|
1 |
|
public function createMasterpassStandardExtractRequest(string $payId, array $callbackParams): StandardExtractRequest |
|
208
|
|
|
{ |
|
209
|
1 |
|
return new StandardExtractRequest($this->merchantId, $payId, $callbackParams); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
1 |
|
public function createMasterpassStandardFinishRequest(string $payId, string $oauthToken, int $totalAmount): StandardFinishRequest |
|
213
|
|
|
{ |
|
214
|
1 |
|
return new StandardFinishRequest( |
|
215
|
1 |
|
$this->merchantId, |
|
216
|
|
|
$payId, |
|
217
|
|
|
$oauthToken, |
|
218
|
|
|
$totalAmount |
|
219
|
|
|
); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
1 |
|
public function createPaymentButtonRequest( |
|
223
|
|
|
string $orderId, |
|
224
|
|
|
string $clientIp, |
|
225
|
|
|
Price $totalPrice, |
|
226
|
|
|
string $returnUrl, |
|
227
|
|
|
HttpMethod $returnMethod, |
|
228
|
|
|
PaymentButtonBrand $brand, |
|
229
|
|
|
?string $merchantData, |
|
230
|
|
|
Language $language |
|
231
|
|
|
): PaymentButtonRequest |
|
232
|
|
|
{ |
|
233
|
1 |
|
return new PaymentButtonRequest( |
|
234
|
1 |
|
$this->merchantId, |
|
235
|
|
|
$orderId, |
|
236
|
|
|
$clientIp, |
|
237
|
|
|
$totalPrice, |
|
238
|
|
|
$returnUrl, |
|
239
|
|
|
$returnMethod, |
|
240
|
|
|
$brand, |
|
241
|
|
|
$merchantData, |
|
242
|
|
|
$language |
|
243
|
|
|
); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
1 |
|
public function createApplePayInitRequest( |
|
247
|
|
|
string $orderId, |
|
248
|
|
|
string $clientIp, |
|
249
|
|
|
Price $totalPrice, |
|
250
|
|
|
bool $closePayment, |
|
251
|
|
|
?string $merchantData, |
|
252
|
|
|
?int $ttlSec = null |
|
253
|
|
|
): InitApplePayRequest |
|
254
|
|
|
{ |
|
255
|
1 |
|
return new InitApplePayRequest( |
|
256
|
1 |
|
$this->merchantId, |
|
257
|
|
|
$orderId, |
|
258
|
|
|
$clientIp, |
|
259
|
|
|
$totalPrice, |
|
260
|
|
|
$closePayment, |
|
261
|
|
|
$merchantData, |
|
262
|
|
|
$ttlSec |
|
263
|
|
|
); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* @param string $payId |
|
268
|
|
|
* @param mixed[] $payload |
|
269
|
|
|
* @param int|null $totalAmount |
|
270
|
|
|
* @return \SlevomatCsobGateway\Call\ApplePay\StartApplePayRequest |
|
271
|
|
|
*/ |
|
272
|
1 |
|
public function createApplePayStartRequest(string $payId, array $payload, ?int $totalAmount = null): StartApplePayRequest |
|
273
|
|
|
{ |
|
274
|
1 |
|
return new StartApplePayRequest( |
|
275
|
1 |
|
$this->merchantId, |
|
276
|
|
|
$payId, |
|
277
|
|
|
$payload, |
|
278
|
|
|
$totalAmount |
|
279
|
|
|
); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
1 |
|
public function createOneClickEchoRequest(string $payId): OneClickEchoRequest |
|
283
|
|
|
{ |
|
284
|
1 |
|
return new OneClickEchoRequest( |
|
285
|
1 |
|
$this->merchantId, |
|
286
|
|
|
$payId |
|
287
|
|
|
); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
} |
|
291
|
|
|
|