1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | namespace Worldline\Connect\Sdk\V1\Merchant\Tokens; |
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\ApproveTokenRequest; |
16: | use Worldline\Connect\Sdk\V1\Domain\CreateTokenRequest; |
17: | use Worldline\Connect\Sdk\V1\Domain\CreateTokenResponse; |
18: | use Worldline\Connect\Sdk\V1\Domain\TokenResponse; |
19: | use Worldline\Connect\Sdk\V1\Domain\UpdateTokenRequest; |
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: | |
28: | |
29: | class TokensClient extends ApiResource |
30: | { |
31: | |
32: | private $responseExceptionFactory = null; |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | public function create(CreateTokenRequest $body, CallContext $callContext = null) |
51: | { |
52: | $responseClassMap = new ResponseClassMap(); |
53: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\CreateTokenResponse'; |
54: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
55: | try { |
56: | return $this->getCommunicator()->post( |
57: | $responseClassMap, |
58: | $this->instantiateUri('/v1/{merchantId}/tokens'), |
59: | $this->getClientMetaInfo(), |
60: | $body, |
61: | null, |
62: | $callContext |
63: | ); |
64: | } catch (ErrorResponseException $e) { |
65: | throw $this->getResponseExceptionFactory()->createException( |
66: | $e->getHttpStatusCode(), |
67: | $e->getErrorResponse(), |
68: | $callContext |
69: | ); |
70: | } |
71: | } |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: | |
86: | |
87: | |
88: | |
89: | public function get($tokenId, CallContext $callContext = null) |
90: | { |
91: | $this->context['tokenId'] = $tokenId; |
92: | $responseClassMap = new ResponseClassMap(); |
93: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\TokenResponse'; |
94: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
95: | try { |
96: | return $this->getCommunicator()->get( |
97: | $responseClassMap, |
98: | $this->instantiateUri('/v1/{merchantId}/tokens/{tokenId}'), |
99: | $this->getClientMetaInfo(), |
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: | |
129: | public function update($tokenId, UpdateTokenRequest $body, CallContext $callContext = null) |
130: | { |
131: | $this->context['tokenId'] = $tokenId; |
132: | $responseClassMap = new ResponseClassMap(); |
133: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
134: | try { |
135: | return $this->getCommunicator()->put( |
136: | $responseClassMap, |
137: | $this->instantiateUri('/v1/{merchantId}/tokens/{tokenId}'), |
138: | $this->getClientMetaInfo(), |
139: | $body, |
140: | null, |
141: | $callContext |
142: | ); |
143: | } catch (ErrorResponseException $e) { |
144: | throw $this->getResponseExceptionFactory()->createException( |
145: | $e->getHttpStatusCode(), |
146: | $e->getErrorResponse(), |
147: | $callContext |
148: | ); |
149: | } |
150: | } |
151: | |
152: | |
153: | |
154: | |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | |
161: | |
162: | |
163: | |
164: | |
165: | |
166: | |
167: | |
168: | |
169: | public function delete($tokenId, DeleteTokenParams $query, CallContext $callContext = null) |
170: | { |
171: | $this->context['tokenId'] = $tokenId; |
172: | $responseClassMap = new ResponseClassMap(); |
173: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
174: | try { |
175: | return $this->getCommunicator()->delete( |
176: | $responseClassMap, |
177: | $this->instantiateUri('/v1/{merchantId}/tokens/{tokenId}'), |
178: | $this->getClientMetaInfo(), |
179: | $query, |
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: | |
208: | public function approvesepadirectdebit($tokenId, ApproveTokenRequest $body, CallContext $callContext = null) |
209: | { |
210: | $this->context['tokenId'] = $tokenId; |
211: | $responseClassMap = new ResponseClassMap(); |
212: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
213: | try { |
214: | return $this->getCommunicator()->post( |
215: | $responseClassMap, |
216: | $this->instantiateUri('/v1/{merchantId}/tokens/{tokenId}/approvesepadirectdebit'), |
217: | $this->getClientMetaInfo(), |
218: | $body, |
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: | private function getResponseExceptionFactory() |
233: | { |
234: | if (is_null($this->responseExceptionFactory)) { |
235: | $this->responseExceptionFactory = new ExceptionFactory(); |
236: | } |
237: | return $this->responseExceptionFactory; |
238: | } |
239: | } |
240: | |