1: <?php
2: /*
3: * This class was auto-generated from the API references found at
4: * https://apireference.connect.worldline-solutions.com/
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: * Payouts client.
28: */
29: class PayoutsClient extends ApiResource
30: {
31: /** @var ExceptionFactory|null */
32: private $responseExceptionFactory = null;
33:
34: /**
35: * Resource /{merchantId}/payouts - Create payout
36: *
37: * @param CreatePayoutRequest $body
38: * @param CallContext $callContext
39: * @return PayoutResponse
40: *
41: * @throws DeclinedPayoutException
42: * @throws IdempotenceException
43: * @throws ValidationException
44: * @throws AuthorizationException
45: * @throws ReferenceException
46: * @throws PlatformException
47: * @throws ApiException
48: * @throws InvalidResponseException
49: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/payouts/create.html Create payout
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: * Resource /{merchantId}/payouts - Find payouts
76: *
77: * @param FindPayoutsParams $query
78: * @param CallContext $callContext
79: * @return FindPayoutsResponse
80: *
81: * @throws IdempotenceException
82: * @throws ValidationException
83: * @throws AuthorizationException
84: * @throws ReferenceException
85: * @throws PlatformException
86: * @throws ApiException
87: * @throws InvalidResponseException
88: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/payouts/find.html Find payouts
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: * Resource /{merchantId}/payouts/{payoutId} - Get payout
114: *
115: * @param string $payoutId
116: * @param CallContext $callContext
117: * @return PayoutResponse
118: *
119: * @throws IdempotenceException
120: * @throws ValidationException
121: * @throws AuthorizationException
122: * @throws ReferenceException
123: * @throws PlatformException
124: * @throws ApiException
125: * @throws InvalidResponseException
126: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/payouts/get.html Get payout
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: * Resource /{merchantId}/payouts/{payoutId}/approve - Approve payout
153: *
154: * @param string $payoutId
155: * @param ApprovePayoutRequest $body
156: * @param CallContext $callContext
157: * @return PayoutResponse
158: *
159: * @throws IdempotenceException
160: * @throws ValidationException
161: * @throws AuthorizationException
162: * @throws ReferenceException
163: * @throws PlatformException
164: * @throws ApiException
165: * @throws InvalidResponseException
166: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/payouts/approve.html Approve payout
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: * Resource /{merchantId}/payouts/{payoutId}/cancel - Cancel payout
194: *
195: * @param string $payoutId
196: * @param CallContext $callContext
197: * @return null
198: *
199: * @throws IdempotenceException
200: * @throws ValidationException
201: * @throws AuthorizationException
202: * @throws ReferenceException
203: * @throws PlatformException
204: * @throws ApiException
205: * @throws InvalidResponseException
206: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/payouts/cancel.html Cancel payout
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: * Resource /{merchantId}/payouts/{payoutId}/cancelapproval - Undo approve payout
233: *
234: * @param string $payoutId
235: * @param CallContext $callContext
236: * @return null
237: *
238: * @throws IdempotenceException
239: * @throws ValidationException
240: * @throws AuthorizationException
241: * @throws ReferenceException
242: * @throws PlatformException
243: * @throws ApiException
244: * @throws InvalidResponseException
245: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/payouts/cancelapproval.html Undo approve payout
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: /** @return ExceptionFactory */
271: private function getResponseExceptionFactory()
272: {
273: if (is_null($this->responseExceptionFactory)) {
274: $this->responseExceptionFactory = new ExceptionFactory();
275: }
276: return $this->responseExceptionFactory;
277: }
278: }
279: