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