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