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\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: * Tokens client.
28: */
29: class TokensClient extends ApiResource
30: {
31: /** @var ExceptionFactory|null */
32: private $responseExceptionFactory = null;
33:
34: /**
35: * Resource /{merchantId}/tokens - Create token
36: *
37: * @param CreateTokenRequest $body
38: * @param CallContext $callContext
39: * @return CreateTokenResponse
40: *
41: * @throws IdempotenceException
42: * @throws ValidationException
43: * @throws AuthorizationException
44: * @throws ReferenceException
45: * @throws PlatformException
46: * @throws ApiException
47: * @throws InvalidResponseException
48: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/tokens/create.html Create token
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: * Resource /{merchantId}/tokens/{tokenId} - Get token
75: *
76: * @param string $tokenId
77: * @param CallContext $callContext
78: * @return TokenResponse
79: *
80: * @throws IdempotenceException
81: * @throws ValidationException
82: * @throws AuthorizationException
83: * @throws ReferenceException
84: * @throws PlatformException
85: * @throws ApiException
86: * @throws InvalidResponseException
87: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/tokens/get.html Get token
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: * Resource /{merchantId}/tokens/{tokenId} - Update token
114: *
115: * @param string $tokenId
116: * @param UpdateTokenRequest $body
117: * @param CallContext $callContext
118: * @return null
119: *
120: * @throws IdempotenceException
121: * @throws ValidationException
122: * @throws AuthorizationException
123: * @throws ReferenceException
124: * @throws PlatformException
125: * @throws ApiException
126: * @throws InvalidResponseException
127: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/tokens/update.html Update token
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: * Resource /{merchantId}/tokens/{tokenId} - Delete token
154: *
155: * @param string $tokenId
156: * @param DeleteTokenParams $query
157: * @param CallContext $callContext
158: * @return null
159: *
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/tokens/delete.html Delete token
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: * Resource /{merchantId}/tokens/{tokenId}/approvesepadirectdebit - Approve SEPA DD mandate
193: *
194: * @param string $tokenId
195: * @param ApproveTokenRequest $body
196: * @param CallContext $callContext
197: * @return null
198: *
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/tokens/approvesepadirectdebit.html Approve SEPA DD mandate
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: /** @return ExceptionFactory */
232: private function getResponseExceptionFactory()
233: {
234: if (is_null($this->responseExceptionFactory)) {
235: $this->responseExceptionFactory = new ExceptionFactory();
236: }
237: return $this->responseExceptionFactory;
238: }
239: }
240: