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\Mandates;
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\CreateMandateRequest;
16: use Worldline\Connect\Sdk\V1\Domain\CreateMandateResponse;
17: use Worldline\Connect\Sdk\V1\Domain\GetMandateResponse;
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: * Mandates client.
26: *
27: * @package Worldline\Connect\Sdk\V1\Merchant\Mandates
28: */
29: class MandatesClient extends ApiResource
30: {
31: /**
32: * @var ExceptionFactory|null
33: */
34: private ?ExceptionFactory $responseExceptionFactory = null;
35:
36: /**
37: * Resource /{merchantId}/mandates - Create mandate
38: *
39: * @param CreateMandateRequest $body
40: * @param CallContext|null $callContext
41: *
42: * @return CreateMandateResponse
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/mandates/create.html Create mandate
51: */
52: public function create(CreateMandateRequest $body, ?CallContext $callContext = null): CreateMandateResponse
53: {
54: $responseClassMap = new ResponseClassMap();
55: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\CreateMandateResponse';
56: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
57: try {
58: return $this->getCommunicator()->post(
59: $responseClassMap,
60: $this->instantiateUri('/v1/{merchantId}/mandates'),
61: $this->getClientMetaInfo(),
62: $body,
63: null,
64: $callContext
65: );
66: } catch (ErrorResponseException $e) {
67: throw $this->getResponseExceptionFactory()->createException(
68: $e->getHttpStatusCode(),
69: $e->getErrorResponse(),
70: $callContext
71: );
72: }
73: }
74:
75: /**
76: * Resource /{merchantId}/mandates/{uniqueMandateReference} - Create mandate with mandatereference
77: *
78: * @param string $uniqueMandateReference
79: * @param CreateMandateRequest $body
80: * @param CallContext|null $callContext
81: *
82: * @return CreateMandateResponse
83: * @throws IdempotenceException
84: * @throws ValidationException
85: * @throws AuthorizationException
86: * @throws ReferenceException
87: * @throws PlatformException
88: * @throws ApiException
89: * @throws InvalidResponseException
90: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/mandates/createWithMandateReference.html Create mandate with mandatereference
91: */
92: public function createWithMandateReference(string $uniqueMandateReference, CreateMandateRequest $body, ?CallContext $callContext = null): CreateMandateResponse
93: {
94: $this->context['uniqueMandateReference'] = $uniqueMandateReference;
95: $responseClassMap = new ResponseClassMap();
96: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\CreateMandateResponse';
97: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
98: try {
99: return $this->getCommunicator()->put(
100: $responseClassMap,
101: $this->instantiateUri('/v1/{merchantId}/mandates/{uniqueMandateReference}'),
102: $this->getClientMetaInfo(),
103: $body,
104: null,
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}/mandates/{uniqueMandateReference} - Get mandate
118: *
119: * @param string $uniqueMandateReference
120: * @param CallContext|null $callContext
121: *
122: * @return GetMandateResponse
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/mandates/get.html Get mandate
131: */
132: public function get(string $uniqueMandateReference, ?CallContext $callContext = null): GetMandateResponse
133: {
134: $this->context['uniqueMandateReference'] = $uniqueMandateReference;
135: $responseClassMap = new ResponseClassMap();
136: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\GetMandateResponse';
137: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
138: try {
139: return $this->getCommunicator()->get(
140: $responseClassMap,
141: $this->instantiateUri('/v1/{merchantId}/mandates/{uniqueMandateReference}'),
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}/mandates/{uniqueMandateReference}/block - Block mandate
157: *
158: * @param string $uniqueMandateReference
159: * @param CallContext|null $callContext
160: *
161: * @return GetMandateResponse
162: * @throws IdempotenceException
163: * @throws ValidationException
164: * @throws AuthorizationException
165: * @throws ReferenceException
166: * @throws PlatformException
167: * @throws ApiException
168: * @throws InvalidResponseException
169: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/mandates/block.html Block mandate
170: */
171: public function block(string $uniqueMandateReference, ?CallContext $callContext = null): GetMandateResponse
172: {
173: $this->context['uniqueMandateReference'] = $uniqueMandateReference;
174: $responseClassMap = new ResponseClassMap();
175: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\GetMandateResponse';
176: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
177: try {
178: return $this->getCommunicator()->post(
179: $responseClassMap,
180: $this->instantiateUri('/v1/{merchantId}/mandates/{uniqueMandateReference}/block'),
181: $this->getClientMetaInfo(),
182: null,
183: null,
184: $callContext
185: );
186: } catch (ErrorResponseException $e) {
187: throw $this->getResponseExceptionFactory()->createException(
188: $e->getHttpStatusCode(),
189: $e->getErrorResponse(),
190: $callContext
191: );
192: }
193: }
194:
195: /**
196: * Resource /{merchantId}/mandates/{uniqueMandateReference}/unblock - Unblock mandate
197: *
198: * @param string $uniqueMandateReference
199: * @param CallContext|null $callContext
200: *
201: * @return GetMandateResponse
202: * @throws IdempotenceException
203: * @throws ValidationException
204: * @throws AuthorizationException
205: * @throws ReferenceException
206: * @throws PlatformException
207: * @throws ApiException
208: * @throws InvalidResponseException
209: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/mandates/unblock.html Unblock mandate
210: */
211: public function unblock(string $uniqueMandateReference, ?CallContext $callContext = null): GetMandateResponse
212: {
213: $this->context['uniqueMandateReference'] = $uniqueMandateReference;
214: $responseClassMap = new ResponseClassMap();
215: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\GetMandateResponse';
216: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
217: try {
218: return $this->getCommunicator()->post(
219: $responseClassMap,
220: $this->instantiateUri('/v1/{merchantId}/mandates/{uniqueMandateReference}/unblock'),
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}/mandates/{uniqueMandateReference}/revoke - Revoke mandate
237: *
238: * @param string $uniqueMandateReference
239: * @param CallContext|null $callContext
240: *
241: * @return GetMandateResponse
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/mandates/revoke.html Revoke mandate
250: */
251: public function revoke(string $uniqueMandateReference, ?CallContext $callContext = null): GetMandateResponse
252: {
253: $this->context['uniqueMandateReference'] = $uniqueMandateReference;
254: $responseClassMap = new ResponseClassMap();
255: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\GetMandateResponse';
256: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
257: try {
258: return $this->getCommunicator()->post(
259: $responseClassMap,
260: $this->instantiateUri('/v1/{merchantId}/mandates/{uniqueMandateReference}/revoke'),
261: $this->getClientMetaInfo(),
262: null,
263: null,
264: $callContext
265: );
266: } catch (ErrorResponseException $e) {
267: throw $this->getResponseExceptionFactory()->createException(
268: $e->getHttpStatusCode(),
269: $e->getErrorResponse(),
270: $callContext
271: );
272: }
273: }
274:
275: /**
276: * @return ExceptionFactory
277: */
278: private function getResponseExceptionFactory(): ExceptionFactory
279: {
280: if (is_null($this->responseExceptionFactory)) {
281: $this->responseExceptionFactory = new ExceptionFactory();
282: }
283: return $this->responseExceptionFactory;
284: }
285: }
286: