1: | <?php |
2: | |
3: | |
4: | |
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: | |
26: | |
27: | class MandatesClient extends ApiResource |
28: | { |
29: | |
30: | private $responseExceptionFactory = null; |
31: | |
32: | |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | public function create(CreateMandateRequest $body, CallContext $callContext = null) |
49: | { |
50: | $responseClassMap = new ResponseClassMap(); |
51: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\CreateMandateResponse'; |
52: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
53: | try { |
54: | return $this->getCommunicator()->post( |
55: | $responseClassMap, |
56: | $this->instantiateUri('/v1/{merchantId}/mandates'), |
57: | $this->getClientMetaInfo(), |
58: | $body, |
59: | null, |
60: | $callContext |
61: | ); |
62: | } catch (ErrorResponseException $e) { |
63: | throw $this->getResponseExceptionFactory()->createException( |
64: | $e->getHttpStatusCode(), |
65: | $e->getErrorResponse(), |
66: | $callContext |
67: | ); |
68: | } |
69: | } |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: | |
86: | |
87: | |
88: | public function createWithMandateReference($uniqueMandateReference, CreateMandateRequest $body, CallContext $callContext = null) |
89: | { |
90: | $this->context['uniqueMandateReference'] = $uniqueMandateReference; |
91: | $responseClassMap = new ResponseClassMap(); |
92: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\CreateMandateResponse'; |
93: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
94: | try { |
95: | return $this->getCommunicator()->put( |
96: | $responseClassMap, |
97: | $this->instantiateUri('/v1/{merchantId}/mandates/{uniqueMandateReference}'), |
98: | $this->getClientMetaInfo(), |
99: | $body, |
100: | null, |
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: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | |
123: | |
124: | |
125: | |
126: | |
127: | |
128: | public function get($uniqueMandateReference, CallContext $callContext = null) |
129: | { |
130: | $this->context['uniqueMandateReference'] = $uniqueMandateReference; |
131: | $responseClassMap = new ResponseClassMap(); |
132: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\GetMandateResponse'; |
133: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
134: | try { |
135: | return $this->getCommunicator()->get( |
136: | $responseClassMap, |
137: | $this->instantiateUri('/v1/{merchantId}/mandates/{uniqueMandateReference}'), |
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: | |
153: | |
154: | |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | |
161: | |
162: | |
163: | |
164: | |
165: | |
166: | |
167: | public function block($uniqueMandateReference, CallContext $callContext = null) |
168: | { |
169: | $this->context['uniqueMandateReference'] = $uniqueMandateReference; |
170: | $responseClassMap = new ResponseClassMap(); |
171: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\GetMandateResponse'; |
172: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
173: | try { |
174: | return $this->getCommunicator()->post( |
175: | $responseClassMap, |
176: | $this->instantiateUri('/v1/{merchantId}/mandates/{uniqueMandateReference}/block'), |
177: | $this->getClientMetaInfo(), |
178: | null, |
179: | null, |
180: | $callContext |
181: | ); |
182: | } catch (ErrorResponseException $e) { |
183: | throw $this->getResponseExceptionFactory()->createException( |
184: | $e->getHttpStatusCode(), |
185: | $e->getErrorResponse(), |
186: | $callContext |
187: | ); |
188: | } |
189: | } |
190: | |
191: | |
192: | |
193: | |
194: | |
195: | |
196: | |
197: | |
198: | |
199: | |
200: | |
201: | |
202: | |
203: | |
204: | |
205: | |
206: | |
207: | public function unblock($uniqueMandateReference, CallContext $callContext = null) |
208: | { |
209: | $this->context['uniqueMandateReference'] = $uniqueMandateReference; |
210: | $responseClassMap = new ResponseClassMap(); |
211: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\GetMandateResponse'; |
212: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
213: | try { |
214: | return $this->getCommunicator()->post( |
215: | $responseClassMap, |
216: | $this->instantiateUri('/v1/{merchantId}/mandates/{uniqueMandateReference}/unblock'), |
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: | |
233: | |
234: | |
235: | |
236: | |
237: | |
238: | |
239: | |
240: | |
241: | |
242: | |
243: | |
244: | |
245: | |
246: | |
247: | public function revoke($uniqueMandateReference, CallContext $callContext = null) |
248: | { |
249: | $this->context['uniqueMandateReference'] = $uniqueMandateReference; |
250: | $responseClassMap = new ResponseClassMap(); |
251: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\GetMandateResponse'; |
252: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
253: | try { |
254: | return $this->getCommunicator()->post( |
255: | $responseClassMap, |
256: | $this->instantiateUri('/v1/{merchantId}/mandates/{uniqueMandateReference}/revoke'), |
257: | $this->getClientMetaInfo(), |
258: | null, |
259: | null, |
260: | $callContext |
261: | ); |
262: | } catch (ErrorResponseException $e) { |
263: | throw $this->getResponseExceptionFactory()->createException( |
264: | $e->getHttpStatusCode(), |
265: | $e->getErrorResponse(), |
266: | $callContext |
267: | ); |
268: | } |
269: | } |
270: | |
271: | |
272: | private function getResponseExceptionFactory() |
273: | { |
274: | if (is_null($this->responseExceptionFactory)) { |
275: | $this->responseExceptionFactory = new ExceptionFactory(); |
276: | } |
277: | return $this->responseExceptionFactory; |
278: | } |
279: | } |
280: | |