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\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: * Refunds client.
26: *
27: * @package Worldline\Connect\Sdk\V1\Merchant\Refunds
28: */
29: class RefundsClient extends ApiResource
30: {
31: /**
32: * @var ExceptionFactory|null
33: */
34: private ?ExceptionFactory $responseExceptionFactory = null;
35:
36: /**
37: * Resource /{merchantId}/refunds - Find refunds
38: *
39: * @param FindRefundsParams $query
40: * @param CallContext|null $callContext
41: *
42: * @return FindRefundsResponse
43: * @throws IdempotenceException
44: * @throws ValidationException
45: * @throws AuthorizationException
46: * @throws ReferenceException
47: * @throws PlatformException
48: * @throws ApiException
49: * @throws InvalidResponseException
50: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/refunds/find.html Find refunds
51: */
52: public function find(FindRefundsParams $query, ?CallContext $callContext = null): FindRefundsResponse
53: {
54: $responseClassMap = new ResponseClassMap();
55: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\FindRefundsResponse';
56: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
57: try {
58: return $this->getCommunicator()->get(
59: $responseClassMap,
60: $this->instantiateUri('/v1/{merchantId}/refunds'),
61: $this->getClientMetaInfo(),
62: $query,
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}/refunds/{refundId} - Get refund
76: *
77: * @param string $refundId
78: * @param CallContext|null $callContext
79: *
80: * @return RefundResponse
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/refunds/get.html Get refund
89: */
90: public function get(string $refundId, ?CallContext $callContext = null): RefundResponse
91: {
92: $this->context['refundId'] = $refundId;
93: $responseClassMap = new ResponseClassMap();
94: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\RefundResponse';
95: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
96: try {
97: return $this->getCommunicator()->get(
98: $responseClassMap,
99: $this->instantiateUri('/v1/{merchantId}/refunds/{refundId}'),
100: $this->getClientMetaInfo(),
101: null,
102: $callContext
103: );
104: } catch (ErrorResponseException $e) {
105: throw $this->getResponseExceptionFactory()->createException(
106: $e->getHttpStatusCode(),
107: $e->getErrorResponse(),
108: $callContext
109: );
110: }
111: }
112:
113: /**
114: * Resource /{merchantId}/refunds/{refundId}/approve - Approve refund
115: *
116: * @param string $refundId
117: * @param ApproveRefundRequest $body
118: * @param CallContext|null $callContext
119: *
120: * @return void
121: * @throws IdempotenceException
122: * @throws ValidationException
123: * @throws AuthorizationException
124: * @throws ReferenceException
125: * @throws PlatformException
126: * @throws ApiException
127: * @throws InvalidResponseException
128: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/refunds/approve.html Approve refund
129: */
130: public function approve(string $refundId, ApproveRefundRequest $body, ?CallContext $callContext = null): void
131: {
132: $this->context['refundId'] = $refundId;
133: $responseClassMap = new ResponseClassMap();
134: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
135: try {
136: $this->getCommunicator()->post(
137: $responseClassMap,
138: $this->instantiateUri('/v1/{merchantId}/refunds/{refundId}/approve'),
139: $this->getClientMetaInfo(),
140: $body,
141: null,
142: $callContext
143: );
144: } catch (ErrorResponseException $e) {
145: throw $this->getResponseExceptionFactory()->createException(
146: $e->getHttpStatusCode(),
147: $e->getErrorResponse(),
148: $callContext
149: );
150: }
151: }
152:
153: /**
154: * Resource /{merchantId}/refunds/{refundId}/cancel - Cancel refund
155: *
156: * @param string $refundId
157: * @param CallContext|null $callContext
158: *
159: * @return void
160: * @throws IdempotenceException
161: * @throws ValidationException
162: * @throws AuthorizationException
163: * @throws ReferenceException
164: * @throws PlatformException
165: * @throws ApiException
166: * @throws InvalidResponseException
167: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/refunds/cancel.html Cancel refund
168: */
169: public function cancel(string $refundId, ?CallContext $callContext = null): void
170: {
171: $this->context['refundId'] = $refundId;
172: $responseClassMap = new ResponseClassMap();
173: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
174: try {
175: $this->getCommunicator()->post(
176: $responseClassMap,
177: $this->instantiateUri('/v1/{merchantId}/refunds/{refundId}/cancel'),
178: $this->getClientMetaInfo(),
179: null,
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}/refunds/{refundId}/cancelapproval - Undo approve refund
194: *
195: * @param string $refundId
196: * @param CallContext|null $callContext
197: *
198: * @return void
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/refunds/cancelapproval.html Undo approve refund
207: */
208: public function cancelapproval(string $refundId, ?CallContext $callContext = null): void
209: {
210: $this->context['refundId'] = $refundId;
211: $responseClassMap = new ResponseClassMap();
212: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
213: try {
214: $this->getCommunicator()->post(
215: $responseClassMap,
216: $this->instantiateUri('/v1/{merchantId}/refunds/{refundId}/cancelapproval'),
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: * @return ExceptionFactory
233: */
234: private function getResponseExceptionFactory(): ExceptionFactory
235: {
236: if (is_null($this->responseExceptionFactory)) {
237: $this->responseExceptionFactory = new ExceptionFactory();
238: }
239: return $this->responseExceptionFactory;
240: }
241: }
242: