1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | namespace Worldline\Connect\Sdk\V1\Merchant\Refunds; |
7: | |
8: | use Worldline\Connect\Sdk\ApiResource; |
9: | use Worldline\Connect\Sdk\CallContext; |
10: | use Worldline\Connect\Sdk\Communication\ErrorResponseException; |
11: | use Worldline\Connect\Sdk\Communication\InvalidResponseException; |
12: | use Worldline\Connect\Sdk\Communication\ResponseClassMap; |
13: | use Worldline\Connect\Sdk\V1\ApiException; |
14: | use Worldline\Connect\Sdk\V1\AuthorizationException; |
15: | use Worldline\Connect\Sdk\V1\Domain\ApproveRefundRequest; |
16: | use Worldline\Connect\Sdk\V1\Domain\FindRefundsResponse; |
17: | use Worldline\Connect\Sdk\V1\Domain\RefundResponse; |
18: | use Worldline\Connect\Sdk\V1\ExceptionFactory; |
19: | use Worldline\Connect\Sdk\V1\IdempotenceException; |
20: | use Worldline\Connect\Sdk\V1\PlatformException; |
21: | use Worldline\Connect\Sdk\V1\ReferenceException; |
22: | use Worldline\Connect\Sdk\V1\ValidationException; |
23: | |
24: | |
25: | |
26: | |
27: | class RefundsClient extends ApiResource |
28: | { |
29: | |
30: | private $responseExceptionFactory = null; |
31: | |
32: | |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | public function find(FindRefundsParams $query, CallContext $callContext = null) |
49: | { |
50: | $responseClassMap = new ResponseClassMap(); |
51: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\FindRefundsResponse'; |
52: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
53: | try { |
54: | return $this->getCommunicator()->get( |
55: | $responseClassMap, |
56: | $this->instantiateUri('/v1/{merchantId}/refunds'), |
57: | $this->getClientMetaInfo(), |
58: | $query, |
59: | $callContext |
60: | ); |
61: | } catch (ErrorResponseException $e) { |
62: | throw $this->getResponseExceptionFactory()->createException( |
63: | $e->getHttpStatusCode(), |
64: | $e->getErrorResponse(), |
65: | $callContext |
66: | ); |
67: | } |
68: | } |
69: | |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: | |
86: | public function get($refundId, CallContext $callContext = null) |
87: | { |
88: | $this->context['refundId'] = $refundId; |
89: | $responseClassMap = new ResponseClassMap(); |
90: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\RefundResponse'; |
91: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
92: | try { |
93: | return $this->getCommunicator()->get( |
94: | $responseClassMap, |
95: | $this->instantiateUri('/v1/{merchantId}/refunds/{refundId}'), |
96: | $this->getClientMetaInfo(), |
97: | null, |
98: | $callContext |
99: | ); |
100: | } catch (ErrorResponseException $e) { |
101: | throw $this->getResponseExceptionFactory()->createException( |
102: | $e->getHttpStatusCode(), |
103: | $e->getErrorResponse(), |
104: | $callContext |
105: | ); |
106: | } |
107: | } |
108: | |
109: | |
110: | |
111: | |
112: | |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | |
123: | |
124: | |
125: | |
126: | public function approve($refundId, ApproveRefundRequest $body, CallContext $callContext = null) |
127: | { |
128: | $this->context['refundId'] = $refundId; |
129: | $responseClassMap = new ResponseClassMap(); |
130: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
131: | try { |
132: | return $this->getCommunicator()->post( |
133: | $responseClassMap, |
134: | $this->instantiateUri('/v1/{merchantId}/refunds/{refundId}/approve'), |
135: | $this->getClientMetaInfo(), |
136: | $body, |
137: | null, |
138: | $callContext |
139: | ); |
140: | } catch (ErrorResponseException $e) { |
141: | throw $this->getResponseExceptionFactory()->createException( |
142: | $e->getHttpStatusCode(), |
143: | $e->getErrorResponse(), |
144: | $callContext |
145: | ); |
146: | } |
147: | } |
148: | |
149: | |
150: | |
151: | |
152: | |
153: | |
154: | |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | |
161: | |
162: | |
163: | |
164: | |
165: | public function cancel($refundId, CallContext $callContext = null) |
166: | { |
167: | $this->context['refundId'] = $refundId; |
168: | $responseClassMap = new ResponseClassMap(); |
169: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
170: | try { |
171: | return $this->getCommunicator()->post( |
172: | $responseClassMap, |
173: | $this->instantiateUri('/v1/{merchantId}/refunds/{refundId}/cancel'), |
174: | $this->getClientMetaInfo(), |
175: | null, |
176: | null, |
177: | $callContext |
178: | ); |
179: | } catch (ErrorResponseException $e) { |
180: | throw $this->getResponseExceptionFactory()->createException( |
181: | $e->getHttpStatusCode(), |
182: | $e->getErrorResponse(), |
183: | $callContext |
184: | ); |
185: | } |
186: | } |
187: | |
188: | |
189: | |
190: | |
191: | |
192: | |
193: | |
194: | |
195: | |
196: | |
197: | |
198: | |
199: | |
200: | |
201: | |
202: | |
203: | |
204: | public function cancelapproval($refundId, CallContext $callContext = null) |
205: | { |
206: | $this->context['refundId'] = $refundId; |
207: | $responseClassMap = new ResponseClassMap(); |
208: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
209: | try { |
210: | return $this->getCommunicator()->post( |
211: | $responseClassMap, |
212: | $this->instantiateUri('/v1/{merchantId}/refunds/{refundId}/cancelapproval'), |
213: | $this->getClientMetaInfo(), |
214: | null, |
215: | null, |
216: | $callContext |
217: | ); |
218: | } catch (ErrorResponseException $e) { |
219: | throw $this->getResponseExceptionFactory()->createException( |
220: | $e->getHttpStatusCode(), |
221: | $e->getErrorResponse(), |
222: | $callContext |
223: | ); |
224: | } |
225: | } |
226: | |
227: | |
228: | private function getResponseExceptionFactory() |
229: | { |
230: | if (is_null($this->responseExceptionFactory)) { |
231: | $this->responseExceptionFactory = new ExceptionFactory(); |
232: | } |
233: | return $this->responseExceptionFactory; |
234: | } |
235: | } |
236: | |