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: class RefundsClient extends ApiResource
28: {
29: /** @var ExceptionFactory|null */
30: private $responseExceptionFactory = null;
31:
32: /**
33: * Resource /{merchantId}/refunds - Find refunds
34: *
35: * @param FindRefundsParams $query
36: * @param CallContext $callContext
37: * @return FindRefundsResponse
38: *
39: * @throws IdempotenceException
40: * @throws ValidationException
41: * @throws AuthorizationException
42: * @throws ReferenceException
43: * @throws PlatformException
44: * @throws ApiException
45: * @throws InvalidResponseException
46: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/refunds/find.html Find refunds
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: * Resource /{merchantId}/refunds/{refundId} - Get refund
72: *
73: * @param string $refundId
74: * @param CallContext $callContext
75: * @return RefundResponse
76: *
77: * @throws IdempotenceException
78: * @throws ValidationException
79: * @throws AuthorizationException
80: * @throws ReferenceException
81: * @throws PlatformException
82: * @throws ApiException
83: * @throws InvalidResponseException
84: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/refunds/get.html Get refund
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: * Resource /{merchantId}/refunds/{refundId}/approve - Approve refund
111: *
112: * @param string $refundId
113: * @param ApproveRefundRequest $body
114: * @param CallContext $callContext
115: * @return null
116: *
117: * @throws IdempotenceException
118: * @throws ValidationException
119: * @throws AuthorizationException
120: * @throws ReferenceException
121: * @throws PlatformException
122: * @throws ApiException
123: * @throws InvalidResponseException
124: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/refunds/approve.html Approve refund
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: * Resource /{merchantId}/refunds/{refundId}/cancel - Cancel refund
151: *
152: * @param string $refundId
153: * @param CallContext $callContext
154: * @return null
155: *
156: * @throws IdempotenceException
157: * @throws ValidationException
158: * @throws AuthorizationException
159: * @throws ReferenceException
160: * @throws PlatformException
161: * @throws ApiException
162: * @throws InvalidResponseException
163: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/refunds/cancel.html Cancel refund
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: * Resource /{merchantId}/refunds/{refundId}/cancelapproval - Undo approve refund
190: *
191: * @param string $refundId
192: * @param CallContext $callContext
193: * @return null
194: *
195: * @throws IdempotenceException
196: * @throws ValidationException
197: * @throws AuthorizationException
198: * @throws ReferenceException
199: * @throws PlatformException
200: * @throws ApiException
201: * @throws InvalidResponseException
202: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/refunds/cancelapproval.html Undo approve refund
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: /** @return ExceptionFactory */
228: private function getResponseExceptionFactory()
229: {
230: if (is_null($this->responseExceptionFactory)) {
231: $this->responseExceptionFactory = new ExceptionFactory();
232: }
233: return $this->responseExceptionFactory;
234: }
235: }
236: