1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHP version 5.4 and 8 |
5
|
|
|
* |
6
|
|
|
* @category Payments |
7
|
|
|
* @package Payever\Payments |
8
|
|
|
* @author payever GmbH <[email protected]> |
9
|
|
|
* @copyright 2017-2021 payever GmbH |
10
|
|
|
* @license MIT <https://opensource.org/licenses/MIT> |
11
|
|
|
* @link https://docs.payever.org/shopsystems/api/getting-started |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Payever\ExternalIntegration\Payments; |
15
|
|
|
|
16
|
|
|
use Payever\ExternalIntegration\Core\Authorization\OauthToken; |
17
|
|
|
use Payever\ExternalIntegration\Core\CommonApiClient; |
18
|
|
|
use Payever\ExternalIntegration\Core\Http\RequestBuilder; |
19
|
|
|
use Payever\ExternalIntegration\Payments\Base\PaymentsApiClientInterface; |
20
|
|
|
use Payever\ExternalIntegration\Payments\Http\RequestEntity\AuthorizePaymentRequest; |
21
|
|
|
use Payever\ExternalIntegration\Payments\Http\RequestEntity\CancelPaymentRequest; |
22
|
|
|
use Payever\ExternalIntegration\Payments\Http\RequestEntity\CreatePaymentRequest; |
23
|
|
|
use Payever\ExternalIntegration\Payments\Http\RequestEntity\CreatePaymentV2Request; |
24
|
|
|
use Payever\ExternalIntegration\Payments\Http\RequestEntity\ListPaymentsRequest; |
25
|
|
|
use Payever\ExternalIntegration\Payments\Http\RequestEntity\RefundPaymentRequest; |
26
|
|
|
use Payever\ExternalIntegration\Payments\Http\RequestEntity\ShippingGoodsPaymentRequest; |
27
|
|
|
use Payever\ExternalIntegration\Payments\Http\RequestEntity\RefundItemsPaymentRequest; |
28
|
|
|
use Payever\ExternalIntegration\Payments\Http\RequestEntity\CancelItemsPaymentRequest; |
29
|
|
|
use Payever\ExternalIntegration\Payments\Http\RequestEntity\SubmitPaymentRequest; |
30
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\AuthorizePaymentResponse; |
31
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\CancelPaymentResponse; |
32
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\CollectPaymentsResponse; |
33
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\CreatePaymentResponse; |
34
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\GetTransactionResponse; |
35
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\LatePaymentsResponse; |
36
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\ListPaymentOptionsResponse; |
37
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\ListPaymentOptionsWithVariantsResponse; |
38
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\ListPaymentsResponse; |
39
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\RefundPaymentResponse; |
40
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\RemindPaymentResponse; |
41
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\RetrieveApiCallResponse; |
42
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\RetrievePaymentResponse; |
43
|
|
|
use Payever\ExternalIntegration\Payments\Http\ResponseEntity\ShippingGoodsPaymentResponse; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Class represents Payever Payments API Connector |
47
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
48
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
49
|
|
|
*/ |
50
|
|
|
class PaymentsApiClient extends CommonApiClient implements PaymentsApiClientInterface |
51
|
|
|
{ |
52
|
|
|
const SUB_URL_CREATE_PAYMENT = 'api/payment'; |
53
|
|
|
const SUB_URL_CREATE_PAYMENT_V2 = 'api/v2/payment'; |
54
|
|
|
const SUB_URL_CREATE_PAYMENT_SUBMIT = 'api/payment/submit'; |
55
|
|
|
const SUB_URL_RETRIEVE_PAYMENT = 'api/payment/%s'; |
56
|
|
|
const SUB_URL_LIST_PAYMENTS = 'api/payment'; |
57
|
|
|
const SUB_URL_REFUND_PAYMENT = 'api/payment/refund/%s'; |
58
|
|
|
const SUB_URL_AUTHORIZE_PAYMENT = 'api/payment/authorize/%s'; |
59
|
|
|
const SUB_URL_REMIND_PAYMENT = 'api/payment/remind/%s'; |
60
|
|
|
const SUB_URL_COLLECT_PAYMENTS = 'api/payment/collect/%s'; |
61
|
|
|
const SUB_URL_LATE_PAYMENTS = 'api/payment/late-payment/%s'; |
62
|
|
|
const SUB_URL_SHIPPING_GOODS_PAYMENT = 'api/payment/shipping-goods/%s'; |
63
|
|
|
const SUB_URL_CANCEL_PAYMENT = 'api/payment/cancel/%s'; |
64
|
|
|
const SUB_URL_RETRIEVE_API_CALL = 'api/%s'; |
65
|
|
|
const SUB_URL_LIST_PAYMENT_OPTIONS = 'api/shop/oauth/%s/payment-options/%s'; |
66
|
|
|
const SUB_URL_LIST_PAYMENT_OPTIONS_VARIANTS = 'api/shop/oauth/%s/payment-options/variants/%s'; |
67
|
|
|
const SUB_URL_TRANSACTION = 'api/rest/v1/transactions/%s'; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
* |
72
|
|
|
* @throws \Exception |
73
|
|
|
*/ |
74
|
|
|
public function createPaymentRequest(CreatePaymentRequest $createPaymentRequest) |
75
|
|
|
{ |
76
|
|
|
$this->configuration->assertLoaded(); |
77
|
|
|
|
78
|
|
|
if (!$createPaymentRequest->getChannel()) { |
79
|
|
|
$createPaymentRequest->setChannel( |
80
|
|
|
$this->configuration->getChannelSet() |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$request = RequestBuilder::post($this->getCreatePaymentURL()) |
85
|
|
|
->addRawHeader( |
86
|
|
|
$this->getToken(OauthToken::SCOPE_CREATE_PAYMENT)->getAuthorizationString() |
87
|
|
|
) |
88
|
|
|
->setRequestEntity($createPaymentRequest) |
89
|
|
|
->setResponseEntity(new CreatePaymentResponse()) |
90
|
|
|
->build(); |
91
|
|
|
|
92
|
|
|
return $this->executeRequest($request, OauthToken::SCOPE_CREATE_PAYMENT); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
* |
98
|
|
|
* @throws \Exception |
99
|
|
|
*/ |
100
|
|
|
public function createPaymentV2Request(CreatePaymentV2Request $createPaymentRequest) |
101
|
|
|
{ |
102
|
|
|
$this->configuration->assertLoaded(); |
103
|
|
|
|
104
|
|
|
$request = RequestBuilder::post($this->getCreatePaymentV2URL()) |
105
|
|
|
->addRawHeader( |
106
|
|
|
$this->getToken(OauthToken::SCOPE_CREATE_PAYMENT)->getAuthorizationString() |
107
|
|
|
) |
108
|
|
|
->contentTypeIsJson() |
109
|
|
|
->setRequestEntity($createPaymentRequest) |
110
|
|
|
->setResponseEntity(new CreatePaymentResponse()) |
111
|
|
|
->build(); |
112
|
|
|
|
113
|
|
|
return $this->executeRequest($request, OauthToken::SCOPE_CREATE_PAYMENT); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* {@inheritdoc} |
118
|
|
|
* |
119
|
|
|
* @throws \Exception |
120
|
|
|
*/ |
121
|
|
|
public function submitPaymentRequest(SubmitPaymentRequest $submitPaymentRequest) |
122
|
|
|
{ |
123
|
|
|
$this->configuration->assertLoaded(); |
124
|
|
|
|
125
|
|
|
if (!$submitPaymentRequest->getChannel()) { |
126
|
|
|
$submitPaymentRequest->setChannel( |
127
|
|
|
$this->configuration->getChannelSet() |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$request = RequestBuilder::post($this->getSubmitPaymentURL()) |
132
|
|
|
->addRawHeader( |
133
|
|
|
$this->getToken(OauthToken::SCOPE_CREATE_PAYMENT)->getAuthorizationString() |
134
|
|
|
) |
135
|
|
|
->contentTypeIsJson() |
136
|
|
|
->setRequestEntity($submitPaymentRequest) |
137
|
|
|
->setResponseEntity(new RetrievePaymentResponse()) |
138
|
|
|
->build(); |
139
|
|
|
|
140
|
|
|
return $this->executeRequest($request, OauthToken::SCOPE_CREATE_PAYMENT); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* {@inheritdoc} |
145
|
|
|
* |
146
|
|
|
* @throws \Exception |
147
|
|
|
*/ |
148
|
|
|
public function retrievePaymentRequest($paymentId) |
149
|
|
|
{ |
150
|
|
|
$this->configuration->assertLoaded(); |
151
|
|
|
|
152
|
|
|
$request = RequestBuilder::get($this->getRetrievePaymentURL($paymentId)) |
153
|
|
|
->addRawHeader( |
154
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_INFO)->getAuthorizationString() |
155
|
|
|
) |
156
|
|
|
->setResponseEntity(new RetrievePaymentResponse()) |
157
|
|
|
->build(); |
158
|
|
|
|
159
|
|
|
return $this->executeRequest($request, OauthToken::SCOPE_PAYMENT_INFO); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* {@inheritdoc} |
164
|
|
|
* |
165
|
|
|
* @throws \Exception |
166
|
|
|
*/ |
167
|
|
|
public function listPaymentsRequest(ListPaymentsRequest $listPaymentsRequest) |
168
|
|
|
{ |
169
|
|
|
$this->configuration->assertLoaded(); |
170
|
|
|
|
171
|
|
|
$request = RequestBuilder::get($this->getListPaymentsURL()) |
172
|
|
|
->addRawHeader( |
173
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
174
|
|
|
) |
175
|
|
|
->setRequestEntity($listPaymentsRequest) |
176
|
|
|
->setResponseEntity(new ListPaymentsResponse()) |
177
|
|
|
->build(); |
178
|
|
|
|
179
|
|
|
return $this->executeRequest($request); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* {@inheritdoc} |
184
|
|
|
* |
185
|
|
|
* @throws \Exception |
186
|
|
|
*/ |
187
|
|
|
public function refundPaymentRequest($paymentId, $amount) |
188
|
|
|
{ |
189
|
|
|
$this->configuration->assertLoaded(); |
190
|
|
|
|
191
|
|
|
$request = RequestBuilder::post($this->getRefundPaymentURL($paymentId)) |
192
|
|
|
->setParams([ |
193
|
|
|
'amount' => $amount, |
194
|
|
|
]) |
195
|
|
|
->addRawHeader( |
196
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
197
|
|
|
) |
198
|
|
|
->setRequestEntity(new RefundPaymentRequest()) |
199
|
|
|
->setResponseEntity(new RefundPaymentResponse()) |
200
|
|
|
->build(); |
201
|
|
|
|
202
|
|
|
return $this->executeRequest($request); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* {@inheritdoc} |
207
|
|
|
* |
208
|
|
|
* @throws \Exception |
209
|
|
|
*/ |
210
|
|
|
public function refundItemsPaymentRequest($paymentId, $items, $deliveryFee = null) |
211
|
|
|
{ |
212
|
|
|
$this->configuration->assertLoaded(); |
213
|
|
|
|
214
|
|
|
$refundPaymentRequest = new RefundItemsPaymentRequest(); |
215
|
|
|
$refundPaymentRequest->setPaymentItems($items); |
216
|
|
|
|
217
|
|
|
if ($deliveryFee) { |
218
|
|
|
$refundPaymentRequest->setDeliveryFee($deliveryFee); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
$request = RequestBuilder::post($this->getRefundPaymentURL($paymentId)) |
222
|
|
|
->addRawHeader( |
223
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
224
|
|
|
) |
225
|
|
|
->contentTypeIsJson() |
226
|
|
|
->setRequestEntity($refundPaymentRequest) |
227
|
|
|
->setResponseEntity(new RefundPaymentResponse()) |
228
|
|
|
->build(); |
229
|
|
|
|
230
|
|
|
return $this->executeRequest($request); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* {@inheritdoc} |
235
|
|
|
* |
236
|
|
|
* @throws \Exception |
237
|
|
|
*/ |
238
|
|
|
public function authorizePaymentRequest($paymentId, AuthorizePaymentRequest $paymentRequest = null) |
239
|
|
|
{ |
240
|
|
|
$this->configuration->assertLoaded(); |
241
|
|
|
|
242
|
|
|
$request = RequestBuilder::post($this->getAuthorizePaymentURL($paymentId)) |
243
|
|
|
->addRawHeader( |
244
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
245
|
|
|
) |
246
|
|
|
->setRequestEntity($paymentRequest ?: new AuthorizePaymentRequest()) |
247
|
|
|
->setResponseEntity(new AuthorizePaymentResponse()) |
248
|
|
|
->build(); |
249
|
|
|
|
250
|
|
|
return $this->executeRequest($request); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* {@inheritdoc} |
255
|
|
|
* |
256
|
|
|
* @throws \Exception |
257
|
|
|
* |
258
|
|
|
* @deprecated This request is only available for Santander DE Invoice and not used anywhere |
259
|
|
|
*/ |
260
|
|
|
public function remindPaymentRequest($paymentId) |
261
|
|
|
{ |
262
|
|
|
$this->configuration->assertLoaded(); |
263
|
|
|
|
264
|
|
|
$request = RequestBuilder::post($this->getRemindPaymentURL($paymentId)) |
265
|
|
|
->addRawHeader( |
266
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
267
|
|
|
) |
268
|
|
|
->setResponseEntity(new RemindPaymentResponse()) |
269
|
|
|
->build(); |
270
|
|
|
|
271
|
|
|
return $this->executeRequest($request); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* {@inheritdoc} |
276
|
|
|
* |
277
|
|
|
* @throws \Exception |
278
|
|
|
* |
279
|
|
|
* @deprecated This request is only available for Santander DE Invoice and not used anywhere |
280
|
|
|
*/ |
281
|
|
|
public function collectPaymentsRequest($paymentId) |
282
|
|
|
{ |
283
|
|
|
$this->configuration->assertLoaded(); |
284
|
|
|
|
285
|
|
|
$request = RequestBuilder::post($this->getCollectPaymentsURL($paymentId)) |
286
|
|
|
->addRawHeader( |
287
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
288
|
|
|
) |
289
|
|
|
->setResponseEntity(new CollectPaymentsResponse()) |
290
|
|
|
->build(); |
291
|
|
|
|
292
|
|
|
return $this->executeRequest($request); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* {@inheritdoc} |
297
|
|
|
* |
298
|
|
|
* @throws \Exception |
299
|
|
|
* |
300
|
|
|
* @deprecated This request is only available for Santander DE Invoice and not used anywhere |
301
|
|
|
*/ |
302
|
|
|
public function latePaymentsRequest($paymentId) |
303
|
|
|
{ |
304
|
|
|
$this->configuration->assertLoaded(); |
305
|
|
|
|
306
|
|
|
$request = RequestBuilder::post($this->getLatePaymentsURL($paymentId)) |
307
|
|
|
->addRawHeader( |
308
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
309
|
|
|
) |
310
|
|
|
->setResponseEntity(new LatePaymentsResponse()) |
311
|
|
|
->build(); |
312
|
|
|
|
313
|
|
|
return $this->executeRequest($request); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* {@inheritdoc} |
318
|
|
|
* |
319
|
|
|
* @throws \Exception |
320
|
|
|
*/ |
321
|
|
|
public function shippingGoodsPaymentRequest( |
322
|
|
|
$paymentId, |
323
|
|
|
ShippingGoodsPaymentRequest $paymentRequest = null |
324
|
|
|
) { |
325
|
|
|
$this->configuration->assertLoaded(); |
326
|
|
|
|
327
|
|
|
$request = RequestBuilder::post($this->getShippingGoodsPaymentURL($paymentId)) |
328
|
|
|
->addRawHeader( |
329
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
330
|
|
|
) |
331
|
|
|
->contentTypeIsJson() |
332
|
|
|
->setRequestEntity($paymentRequest ?: new ShippingGoodsPaymentRequest()) |
333
|
|
|
->setResponseEntity(new ShippingGoodsPaymentResponse()) |
334
|
|
|
->build(); |
335
|
|
|
|
336
|
|
|
return $this->executeRequest($request); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* {@inheritdoc} |
341
|
|
|
* |
342
|
|
|
* @throws \Exception |
343
|
|
|
*/ |
344
|
|
|
public function cancelPaymentRequest($paymentId, $amount = null) |
345
|
|
|
{ |
346
|
|
|
$this->configuration->assertLoaded(); |
347
|
|
|
|
348
|
|
|
$request = RequestBuilder::post($this->getCancelPaymentURL($paymentId)) |
349
|
|
|
->setParams([ |
350
|
|
|
'amount' => $amount, |
351
|
|
|
]) |
352
|
|
|
->addRawHeader( |
353
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
354
|
|
|
) |
355
|
|
|
->setRequestEntity(new CancelPaymentRequest()) |
356
|
|
|
->setResponseEntity(new CancelPaymentResponse()) |
357
|
|
|
->build(); |
358
|
|
|
|
359
|
|
|
return $this->executeRequest($request); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* {@inheritdoc} |
364
|
|
|
* |
365
|
|
|
* @throws \Exception |
366
|
|
|
*/ |
367
|
|
|
public function cancelItemsPaymentRequest($paymentId, $items, $deliveryFee = null) |
368
|
|
|
{ |
369
|
|
|
$this->configuration->assertLoaded(); |
370
|
|
|
|
371
|
|
|
$cancelPaymentRequest = new CancelItemsPaymentRequest(); |
372
|
|
|
$cancelPaymentRequest->setPaymentItems($items); |
373
|
|
|
|
374
|
|
|
if ($deliveryFee) { |
375
|
|
|
$cancelPaymentRequest->setDeliveryFee($deliveryFee); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
$request = RequestBuilder::post($this->getCancelPaymentURL($paymentId)) |
379
|
|
|
->addRawHeader( |
380
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
381
|
|
|
) |
382
|
|
|
->contentTypeIsJson() |
383
|
|
|
->setRequestEntity($cancelPaymentRequest) |
384
|
|
|
->setResponseEntity(new CancelPaymentResponse()) |
385
|
|
|
->build(); |
386
|
|
|
|
387
|
|
|
return $this->executeRequest($request); |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* {@inheritdoc} |
392
|
|
|
* |
393
|
|
|
* @throws \Exception |
394
|
|
|
*/ |
395
|
|
|
public function retrieveApiCallRequest($callId) |
396
|
|
|
{ |
397
|
|
|
$this->configuration->assertLoaded(); |
398
|
|
|
|
399
|
|
|
$request = RequestBuilder::get($this->getRetrieveApiCallURL($callId)) |
400
|
|
|
->addRawHeader( |
401
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
402
|
|
|
) |
403
|
|
|
->setResponseEntity(new RetrieveApiCallResponse()) |
404
|
|
|
->build(); |
405
|
|
|
|
406
|
|
|
return $this->executeRequest($request); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* {@inheritdoc} |
411
|
|
|
* |
412
|
|
|
* @throws \Exception |
413
|
|
|
*/ |
414
|
|
|
public function listPaymentOptionsRequest($params = [], $businessUuid = '', $channel = '') |
415
|
|
|
{ |
416
|
|
|
$businessUuid = $businessUuid ?: $this->getConfiguration()->getBusinessUuid(); |
417
|
|
|
$channel = $channel ?: $this->getConfiguration()->getChannelSet(); |
418
|
|
|
|
419
|
|
|
$request = RequestBuilder::get($this->getListPaymentOptionsURL($businessUuid, $channel, $params)) |
420
|
|
|
->addRawHeader( |
421
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_INFO)->getAuthorizationString() |
422
|
|
|
) |
423
|
|
|
->setResponseEntity(new ListPaymentOptionsResponse()) |
424
|
|
|
->build(); |
425
|
|
|
|
426
|
|
|
return $this->executeRequest($request, OauthToken::SCOPE_PAYMENT_INFO); |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* {@inheritdoc} |
431
|
|
|
* |
432
|
|
|
* @throws \Exception |
433
|
|
|
*/ |
434
|
|
|
public function listPaymentOptionsWithVariantsRequest($params = [], $businessUuid = '', $channel = '') |
435
|
|
|
{ |
436
|
|
|
$businessUuid = $businessUuid ?: $this->getConfiguration()->getBusinessUuid(); |
437
|
|
|
$channel = $channel ?: $this->getConfiguration()->getChannelSet(); |
438
|
|
|
|
439
|
|
|
$request = RequestBuilder::get($this->getListPaymentOptionsVariantsURL($businessUuid, $channel, $params)) |
440
|
|
|
->addRawHeader( |
441
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_INFO)->getAuthorizationString() |
442
|
|
|
) |
443
|
|
|
->setResponseEntity(new ListPaymentOptionsWithVariantsResponse()) |
444
|
|
|
->build(); |
445
|
|
|
|
446
|
|
|
return $this->executeRequest($request, OauthToken::SCOPE_PAYMENT_INFO); |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
/** |
450
|
|
|
* {@inheritdoc} |
451
|
|
|
* |
452
|
|
|
* @throws \Exception |
453
|
|
|
*/ |
454
|
|
|
public function getTransactionRequest($paymentId) |
455
|
|
|
{ |
456
|
|
|
$this->configuration->assertLoaded(); |
457
|
|
|
|
458
|
|
|
$request = RequestBuilder::get($this->getTransactionURL($paymentId)) |
459
|
|
|
->addRawHeader( |
460
|
|
|
$this->getToken(OauthToken::SCOPE_PAYMENT_ACTIONS)->getAuthorizationString() |
461
|
|
|
) |
462
|
|
|
->setResponseEntity(new GetTransactionResponse()) |
463
|
|
|
->build(); |
464
|
|
|
|
465
|
|
|
return $this->executeRequest($request); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* Returns URL for Create Payment path |
470
|
|
|
* |
471
|
|
|
* @return string |
472
|
|
|
*/ |
473
|
|
|
protected function getCreatePaymentURL() |
474
|
|
|
{ |
475
|
|
|
return $this->getBaseUrl() . self::SUB_URL_CREATE_PAYMENT; |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* Returns URL for Create Payment path |
480
|
|
|
* |
481
|
|
|
* @return string |
482
|
|
|
*/ |
483
|
|
|
protected function getCreatePaymentV2URL() |
484
|
|
|
{ |
485
|
|
|
return $this->getBaseUrl() . self::SUB_URL_CREATE_PAYMENT_V2; |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
/** |
489
|
|
|
* Returns URL for Submit Payment path |
490
|
|
|
* |
491
|
|
|
* @return string |
492
|
|
|
*/ |
493
|
|
|
protected function getSubmitPaymentURL() |
494
|
|
|
{ |
495
|
|
|
return $this->getBaseUrl() . self::SUB_URL_CREATE_PAYMENT_SUBMIT; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* Returns URL for Retrieve Payment path |
500
|
|
|
* |
501
|
|
|
* @param string $paymentId |
502
|
|
|
* |
503
|
|
|
* @return string |
504
|
|
|
*/ |
505
|
|
|
protected function getRetrievePaymentURL($paymentId) |
506
|
|
|
{ |
507
|
|
|
return $this->getBaseUrl() . sprintf(self::SUB_URL_RETRIEVE_PAYMENT, $paymentId); |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* Returns URL for List Payments path |
512
|
|
|
* |
513
|
|
|
* @return string |
514
|
|
|
*/ |
515
|
|
|
protected function getListPaymentsURL() |
516
|
|
|
{ |
517
|
|
|
return $this->getBaseUrl() . self::SUB_URL_LIST_PAYMENTS; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* Returns URL for Refund Payment path |
522
|
|
|
* |
523
|
|
|
* @param string $paymentId |
524
|
|
|
* |
525
|
|
|
* @return string |
526
|
|
|
*/ |
527
|
|
|
protected function getRefundPaymentURL($paymentId) |
528
|
|
|
{ |
529
|
|
|
return $this->getBaseUrl() . sprintf(self::SUB_URL_REFUND_PAYMENT, $paymentId); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* Returns URL for Authorize Payment path |
534
|
|
|
* |
535
|
|
|
* @param string $paymentId |
536
|
|
|
* |
537
|
|
|
* @return string |
538
|
|
|
*/ |
539
|
|
|
protected function getAuthorizePaymentURL($paymentId) |
540
|
|
|
{ |
541
|
|
|
return $this->getBaseUrl() . sprintf(self::SUB_URL_AUTHORIZE_PAYMENT, $paymentId); |
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
/** |
545
|
|
|
* Returns URL for Remind Payment path |
546
|
|
|
* |
547
|
|
|
* @param string $paymentId |
548
|
|
|
* |
549
|
|
|
* @return string |
550
|
|
|
*/ |
551
|
|
|
protected function getRemindPaymentURL($paymentId) |
552
|
|
|
{ |
553
|
|
|
return $this->getBaseUrl() . sprintf(self::SUB_URL_REMIND_PAYMENT, $paymentId); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
/** |
557
|
|
|
* Returns URL for Collect Payment path |
558
|
|
|
* |
559
|
|
|
* @param string $paymentId |
560
|
|
|
* |
561
|
|
|
* @return string |
562
|
|
|
*/ |
563
|
|
|
protected function getCollectPaymentsURL($paymentId) |
564
|
|
|
{ |
565
|
|
|
return $this->getBaseUrl() . sprintf(self::SUB_URL_COLLECT_PAYMENTS, $paymentId); |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
/** |
569
|
|
|
* Returns URL for Late Payments path |
570
|
|
|
* |
571
|
|
|
* @param string $paymentId |
572
|
|
|
* |
573
|
|
|
* @return string |
574
|
|
|
*/ |
575
|
|
|
protected function getLatePaymentsURL($paymentId) |
576
|
|
|
{ |
577
|
|
|
return $this->getBaseUrl() . sprintf(self::SUB_URL_LATE_PAYMENTS, $paymentId); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* Returns URL for Shipping Goods Payment path |
582
|
|
|
* |
583
|
|
|
* @param string $paymentId |
584
|
|
|
* |
585
|
|
|
* @return string |
586
|
|
|
*/ |
587
|
|
|
protected function getShippingGoodsPaymentURL($paymentId) |
588
|
|
|
{ |
589
|
|
|
return $this->getBaseUrl() . sprintf(self::SUB_URL_SHIPPING_GOODS_PAYMENT, $paymentId); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* Returns URL for Cancel Payment path |
594
|
|
|
* |
595
|
|
|
* @param string $paymentId |
596
|
|
|
* |
597
|
|
|
* @return string |
598
|
|
|
*/ |
599
|
|
|
protected function getCancelPaymentURL($paymentId) |
600
|
|
|
{ |
601
|
|
|
return $this->getBaseUrl() . sprintf(self::SUB_URL_CANCEL_PAYMENT, $paymentId); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
/** |
605
|
|
|
* Returns URL for Retrieve API Call path |
606
|
|
|
* |
607
|
|
|
* @param string $callId |
608
|
|
|
* |
609
|
|
|
* @return string |
610
|
|
|
*/ |
611
|
|
|
protected function getRetrieveApiCallURL($callId) |
612
|
|
|
{ |
613
|
|
|
return $this->getBaseUrl() . sprintf(self::SUB_URL_RETRIEVE_API_CALL, $callId); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
/** |
617
|
|
|
* Returns URL for Available Payment Options path |
618
|
|
|
* |
619
|
|
|
* @param string $businessUuid |
620
|
|
|
* @param string $channel |
621
|
|
|
* @param array $params |
622
|
|
|
* |
623
|
|
|
* @return string |
624
|
|
|
*/ |
625
|
|
|
protected function getListPaymentOptionsURL($businessUuid, $channel, $params = []) |
626
|
|
|
{ |
627
|
|
|
return $this->getBaseUrl() |
628
|
|
|
. sprintf(self::SUB_URL_LIST_PAYMENT_OPTIONS, $businessUuid, $channel) |
629
|
|
|
. (empty($params) ? '' : '?' . http_build_query($params)); |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
/** |
633
|
|
|
* Returns URL for Available Payment Options request |
634
|
|
|
* |
635
|
|
|
* @param string $businessUuid |
636
|
|
|
* @param string $channel |
637
|
|
|
* @param array $params |
638
|
|
|
* |
639
|
|
|
* @return string |
640
|
|
|
*/ |
641
|
|
|
protected function getListPaymentOptionsVariantsURL($businessUuid, $channel, $params = []) |
642
|
|
|
{ |
643
|
|
|
return $this->getBaseUrl() |
644
|
|
|
. sprintf(self::SUB_URL_LIST_PAYMENT_OPTIONS_VARIANTS, $businessUuid, $channel) |
645
|
|
|
. (empty($params) ? '' : '?' . http_build_query($params)); |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
/** |
649
|
|
|
* Returns URL to Transaction path |
650
|
|
|
* |
651
|
|
|
* @param int $paymentId |
652
|
|
|
* |
653
|
|
|
* @return string |
654
|
|
|
*/ |
655
|
|
|
protected function getTransactionURL($paymentId) |
656
|
|
|
{ |
657
|
|
|
return $this->getBaseUrl() . sprintf(self::SUB_URL_TRANSACTION, $paymentId); |
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
/** |
661
|
|
|
* Returns Base URL to payever Payments API |
662
|
|
|
* |
663
|
|
|
* @return string |
664
|
|
|
*/ |
665
|
|
|
public function getBaseUrl() |
666
|
|
|
{ |
667
|
|
|
return $this->getBaseEntrypoint(); |
668
|
|
|
} |
669
|
|
|
} |
670
|
|
|
|