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: * @package Worldline\Connect\Sdk\V1\Merchant\Tokens
30: */
31: class TokensClient extends ApiResource
32: {
33: /**
34: * @var ExceptionFactory|null
35: */
36: private ?ExceptionFactory $responseExceptionFactory = null;
37:
38: /**
39: * Resource /{merchantId}/tokens - Create token
40: *
41: * @param CreateTokenRequest $body
42: * @param CallContext|null $callContext
43: *
44: * @return CreateTokenResponse
45: * @throws IdempotenceException
46: * @throws ValidationException
47: * @throws AuthorizationException
48: * @throws ReferenceException
49: * @throws PlatformException
50: * @throws ApiException
51: * @throws InvalidResponseException
52: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/tokens/create.html Create token
53: */
54: public function create(CreateTokenRequest $body, ?CallContext $callContext = null): CreateTokenResponse
55: {
56: $responseClassMap = new ResponseClassMap();
57: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\CreateTokenResponse';
58: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
59: try {
60: return $this->getCommunicator()->post(
61: $responseClassMap,
62: $this->instantiateUri('/v1/{merchantId}/tokens'),
63: $this->getClientMetaInfo(),
64: $body,
65: null,
66: $callContext
67: );
68: } catch (ErrorResponseException $e) {
69: throw $this->getResponseExceptionFactory()->createException(
70: $e->getHttpStatusCode(),
71: $e->getErrorResponse(),
72: $callContext
73: );
74: }
75: }
76:
77: /**
78: * Resource /{merchantId}/tokens/{tokenId} - Get token
79: *
80: * @param string $tokenId
81: * @param CallContext|null $callContext
82: *
83: * @return TokenResponse
84: * @throws IdempotenceException
85: * @throws ValidationException
86: * @throws AuthorizationException
87: * @throws ReferenceException
88: * @throws PlatformException
89: * @throws ApiException
90: * @throws InvalidResponseException
91: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/tokens/get.html Get token
92: */
93: public function get(string $tokenId, ?CallContext $callContext = null): TokenResponse
94: {
95: $this->context['tokenId'] = $tokenId;
96: $responseClassMap = new ResponseClassMap();
97: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\TokenResponse';
98: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
99: try {
100: return $this->getCommunicator()->get(
101: $responseClassMap,
102: $this->instantiateUri('/v1/{merchantId}/tokens/{tokenId}'),
103: $this->getClientMetaInfo(),
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}/tokens/{tokenId} - Update token
118: *
119: * @param string $tokenId
120: * @param UpdateTokenRequest $body
121: * @param CallContext|null $callContext
122: *
123: * @return void
124: * @throws IdempotenceException
125: * @throws ValidationException
126: * @throws AuthorizationException
127: * @throws ReferenceException
128: * @throws PlatformException
129: * @throws ApiException
130: * @throws InvalidResponseException
131: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/tokens/update.html Update token
132: */
133: public function update(string $tokenId, UpdateTokenRequest $body, ?CallContext $callContext = null): void
134: {
135: $this->context['tokenId'] = $tokenId;
136: $responseClassMap = new ResponseClassMap();
137: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
138: try {
139: $this->getCommunicator()->put(
140: $responseClassMap,
141: $this->instantiateUri('/v1/{merchantId}/tokens/{tokenId}'),
142: $this->getClientMetaInfo(),
143: $body,
144: null,
145: $callContext
146: );
147: } catch (ErrorResponseException $e) {
148: throw $this->getResponseExceptionFactory()->createException(
149: $e->getHttpStatusCode(),
150: $e->getErrorResponse(),
151: $callContext
152: );
153: }
154: }
155:
156: /**
157: * Resource /{merchantId}/tokens/{tokenId} - Delete token
158: *
159: * @param string $tokenId
160: * @param DeleteTokenParams $query
161: * @param CallContext|null $callContext
162: *
163: * @return void
164: * @throws IdempotenceException
165: * @throws ValidationException
166: * @throws AuthorizationException
167: * @throws ReferenceException
168: * @throws PlatformException
169: * @throws ApiException
170: * @throws InvalidResponseException
171: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/tokens/delete.html Delete token
172: */
173: public function delete(string $tokenId, DeleteTokenParams $query, ?CallContext $callContext = null): void
174: {
175: $this->context['tokenId'] = $tokenId;
176: $responseClassMap = new ResponseClassMap();
177: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
178: try {
179: $this->getCommunicator()->delete(
180: $responseClassMap,
181: $this->instantiateUri('/v1/{merchantId}/tokens/{tokenId}'),
182: $this->getClientMetaInfo(),
183: $query,
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}/tokens/{tokenId}/approvesepadirectdebit - Approve SEPA DD mandate
197: *
198: * @param string $tokenId
199: * @param ApproveTokenRequest $body
200: * @param CallContext|null $callContext
201: *
202: * @return void
203: * @throws IdempotenceException
204: * @throws ValidationException
205: * @throws AuthorizationException
206: * @throws ReferenceException
207: * @throws PlatformException
208: * @throws ApiException
209: * @throws InvalidResponseException
210: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/tokens/approvesepadirectdebit.html Approve SEPA DD mandate
211: */
212: public function approvesepadirectdebit(string $tokenId, ApproveTokenRequest $body, ?CallContext $callContext = null): void
213: {
214: $this->context['tokenId'] = $tokenId;
215: $responseClassMap = new ResponseClassMap();
216: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
217: try {
218: $this->getCommunicator()->post(
219: $responseClassMap,
220: $this->instantiateUri('/v1/{merchantId}/tokens/{tokenId}/approvesepadirectdebit'),
221: $this->getClientMetaInfo(),
222: $body,
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: * @return ExceptionFactory
237: */
238: private function getResponseExceptionFactory(): ExceptionFactory
239: {
240: if (is_null($this->responseExceptionFactory)) {
241: $this->responseExceptionFactory = new ExceptionFactory();
242: }
243: return $this->responseExceptionFactory;
244: }
245: }
246: