1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | namespace Worldline\Connect\Sdk\V1\Merchant\Payouts; |
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\DeclinedPayoutException; |
16: | use Worldline\Connect\Sdk\V1\Domain\ApprovePayoutRequest; |
17: | use Worldline\Connect\Sdk\V1\Domain\CreatePayoutRequest; |
18: | use Worldline\Connect\Sdk\V1\Domain\FindPayoutsResponse; |
19: | use Worldline\Connect\Sdk\V1\Domain\PayoutResponse; |
20: | use Worldline\Connect\Sdk\V1\ExceptionFactory; |
21: | use Worldline\Connect\Sdk\V1\IdempotenceException; |
22: | use Worldline\Connect\Sdk\V1\PlatformException; |
23: | use Worldline\Connect\Sdk\V1\ReferenceException; |
24: | use Worldline\Connect\Sdk\V1\ValidationException; |
25: | |
26: | |
27: | |
28: | |
29: | class PayoutsClient extends ApiResource |
30: | { |
31: | |
32: | private $responseExceptionFactory = null; |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | public function create(CreatePayoutRequest $body, CallContext $callContext = null) |
52: | { |
53: | $responseClassMap = new ResponseClassMap(); |
54: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\PayoutResponse'; |
55: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\PayoutErrorResponse'; |
56: | try { |
57: | return $this->getCommunicator()->post( |
58: | $responseClassMap, |
59: | $this->instantiateUri('/v1/{merchantId}/payouts'), |
60: | $this->getClientMetaInfo(), |
61: | $body, |
62: | null, |
63: | $callContext |
64: | ); |
65: | } catch (ErrorResponseException $e) { |
66: | throw $this->getResponseExceptionFactory()->createException( |
67: | $e->getHttpStatusCode(), |
68: | $e->getErrorResponse(), |
69: | $callContext |
70: | ); |
71: | } |
72: | } |
73: | |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: | |
86: | |
87: | |
88: | |
89: | |
90: | public function find(FindPayoutsParams $query, CallContext $callContext = null) |
91: | { |
92: | $responseClassMap = new ResponseClassMap(); |
93: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\FindPayoutsResponse'; |
94: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
95: | try { |
96: | return $this->getCommunicator()->get( |
97: | $responseClassMap, |
98: | $this->instantiateUri('/v1/{merchantId}/payouts'), |
99: | $this->getClientMetaInfo(), |
100: | $query, |
101: | $callContext |
102: | ); |
103: | } catch (ErrorResponseException $e) { |
104: | throw $this->getResponseExceptionFactory()->createException( |
105: | $e->getHttpStatusCode(), |
106: | $e->getErrorResponse(), |
107: | $callContext |
108: | ); |
109: | } |
110: | } |
111: | |
112: | |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | |
123: | |
124: | |
125: | |
126: | |
127: | |
128: | public function get($payoutId, CallContext $callContext = null) |
129: | { |
130: | $this->context['payoutId'] = $payoutId; |
131: | $responseClassMap = new ResponseClassMap(); |
132: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\PayoutResponse'; |
133: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
134: | try { |
135: | return $this->getCommunicator()->get( |
136: | $responseClassMap, |
137: | $this->instantiateUri('/v1/{merchantId}/payouts/{payoutId}'), |
138: | $this->getClientMetaInfo(), |
139: | null, |
140: | $callContext |
141: | ); |
142: | } catch (ErrorResponseException $e) { |
143: | throw $this->getResponseExceptionFactory()->createException( |
144: | $e->getHttpStatusCode(), |
145: | $e->getErrorResponse(), |
146: | $callContext |
147: | ); |
148: | } |
149: | } |
150: | |
151: | |
152: | |
153: | |
154: | |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | |
161: | |
162: | |
163: | |
164: | |
165: | |
166: | |
167: | |
168: | public function approve($payoutId, ApprovePayoutRequest $body, CallContext $callContext = null) |
169: | { |
170: | $this->context['payoutId'] = $payoutId; |
171: | $responseClassMap = new ResponseClassMap(); |
172: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\PayoutResponse'; |
173: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
174: | try { |
175: | return $this->getCommunicator()->post( |
176: | $responseClassMap, |
177: | $this->instantiateUri('/v1/{merchantId}/payouts/{payoutId}/approve'), |
178: | $this->getClientMetaInfo(), |
179: | $body, |
180: | null, |
181: | $callContext |
182: | ); |
183: | } catch (ErrorResponseException $e) { |
184: | throw $this->getResponseExceptionFactory()->createException( |
185: | $e->getHttpStatusCode(), |
186: | $e->getErrorResponse(), |
187: | $callContext |
188: | ); |
189: | } |
190: | } |
191: | |
192: | |
193: | |
194: | |
195: | |
196: | |
197: | |
198: | |
199: | |
200: | |
201: | |
202: | |
203: | |
204: | |
205: | |
206: | |
207: | |
208: | public function cancel($payoutId, CallContext $callContext = null) |
209: | { |
210: | $this->context['payoutId'] = $payoutId; |
211: | $responseClassMap = new ResponseClassMap(); |
212: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
213: | try { |
214: | return $this->getCommunicator()->post( |
215: | $responseClassMap, |
216: | $this->instantiateUri('/v1/{merchantId}/payouts/{payoutId}/cancel'), |
217: | $this->getClientMetaInfo(), |
218: | null, |
219: | null, |
220: | $callContext |
221: | ); |
222: | } catch (ErrorResponseException $e) { |
223: | throw $this->getResponseExceptionFactory()->createException( |
224: | $e->getHttpStatusCode(), |
225: | $e->getErrorResponse(), |
226: | $callContext |
227: | ); |
228: | } |
229: | } |
230: | |
231: | |
232: | |
233: | |
234: | |
235: | |
236: | |
237: | |
238: | |
239: | |
240: | |
241: | |
242: | |
243: | |
244: | |
245: | |
246: | |
247: | public function cancelapproval($payoutId, CallContext $callContext = null) |
248: | { |
249: | $this->context['payoutId'] = $payoutId; |
250: | $responseClassMap = new ResponseClassMap(); |
251: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
252: | try { |
253: | return $this->getCommunicator()->post( |
254: | $responseClassMap, |
255: | $this->instantiateUri('/v1/{merchantId}/payouts/{payoutId}/cancelapproval'), |
256: | $this->getClientMetaInfo(), |
257: | null, |
258: | null, |
259: | $callContext |
260: | ); |
261: | } catch (ErrorResponseException $e) { |
262: | throw $this->getResponseExceptionFactory()->createException( |
263: | $e->getHttpStatusCode(), |
264: | $e->getErrorResponse(), |
265: | $callContext |
266: | ); |
267: | } |
268: | } |
269: | |
270: | |
271: | private function getResponseExceptionFactory() |
272: | { |
273: | if (is_null($this->responseExceptionFactory)) { |
274: | $this->responseExceptionFactory = new ExceptionFactory(); |
275: | } |
276: | return $this->responseExceptionFactory; |
277: | } |
278: | } |
279: | |