1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the PayBreak/paybreak-sdk-php package. |
4
|
|
|
* |
5
|
|
|
* (c) PayBreak <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace PayBreak\Sdk\Gateways; |
12
|
|
|
|
13
|
|
|
use PayBreak\Sdk\Entities\PartialRefundEntity; |
14
|
|
|
use PayBreak\Sdk\SdkException; |
15
|
|
|
use PayBreak\ApiClient\ErrorResponseException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Partial Refund Gateway |
19
|
|
|
* |
20
|
|
|
* @package PayBreak\Sdk\Gateways |
21
|
|
|
*/ |
22
|
|
|
class PartialRefundGateway extends AbstractGateway |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* List Partial Refunds |
26
|
|
|
* |
27
|
|
|
* @author LH |
28
|
|
|
* @param $token |
29
|
|
|
* @return array |
30
|
|
|
* @throws SdkException |
31
|
|
|
*/ |
32
|
|
|
public function listPartialRefunds($token) |
33
|
|
|
{ |
34
|
|
|
return $this->fetchCollection( |
35
|
|
|
$token, |
36
|
|
|
'/v4/partial-refunds', |
37
|
|
|
'\PayBreak\Sdk\Entities\PartialRefundEntity' |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get Partial Refund |
43
|
|
|
* |
44
|
|
|
* @author LH |
45
|
|
|
* @param $token |
46
|
|
|
* @param $id |
47
|
|
|
* @return static |
48
|
|
|
* @throws SdkException |
49
|
|
|
*/ |
50
|
|
|
public function getPartialRefund($token, $id) |
51
|
|
|
{ |
52
|
|
|
return PartialRefundEntity::make($this->fetchDocument('/v4/partial-refunds/' . $id, $token, 'Partial Refund')); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @author LH |
57
|
|
|
* @param $token |
58
|
|
|
* @param $id |
59
|
|
|
* @param $refundAmount |
60
|
|
|
* @param $effectiveDate |
61
|
|
|
* @param $description |
62
|
|
|
* @throws SdkException |
63
|
|
|
*/ |
64
|
|
|
public function requestPartialRefund($token, $id, $refundAmount, $effectiveDate, $description) |
65
|
|
|
{ |
66
|
|
|
$api = $this->getApiFactory()->makeApiClient($token); |
67
|
|
|
|
68
|
|
|
try { |
69
|
|
|
$api->post( |
70
|
|
|
'/v4/applications/' . $id . '/request-partial-refund', |
71
|
|
|
[ |
72
|
|
|
'refund_amount' => $refundAmount, |
73
|
|
|
'effective_date' => $effectiveDate, |
74
|
|
|
'description' => $description, |
75
|
|
|
] |
76
|
|
|
); |
77
|
|
|
} catch (ErrorResponseException $e) { |
78
|
|
|
$this->logWarning('PartialRefundGateway::requestPartialRefund[' . $e->getCode() . ']: ' . $e->getMessage()); |
79
|
|
|
throw new SdkException($e->getMessage()); |
80
|
|
|
} catch (\Exception $e) { |
81
|
|
|
$this->logError('PartialRefundGateway::requestPartialRefund[' . $e->getCode() . ']: ' . $e->getMessage()); |
82
|
|
|
throw new SdkException('Problem requesting a partial refund on Provider API'); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|