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\Hostedcheckouts;
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\CreateHostedCheckoutRequest;
16: use Worldline\Connect\Sdk\V1\Domain\CreateHostedCheckoutResponse;
17: use Worldline\Connect\Sdk\V1\Domain\GetHostedCheckoutResponse;
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: * Hosted Checkouts client.
26: *
27: * @package Worldline\Connect\Sdk\V1\Merchant\Hostedcheckouts
28: */
29: class HostedcheckoutsClient extends ApiResource
30: {
31: /**
32: * @var ExceptionFactory|null
33: */
34: private ?ExceptionFactory $responseExceptionFactory = null;
35:
36: /**
37: * Resource /{merchantId}/hostedcheckouts - Create hosted checkout
38: *
39: * @param CreateHostedCheckoutRequest $body
40: * @param CallContext|null $callContext
41: *
42: * @return CreateHostedCheckoutResponse
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/hostedcheckouts/create.html Create hosted checkout
51: */
52: public function create(CreateHostedCheckoutRequest $body, ?CallContext $callContext = null): CreateHostedCheckoutResponse
53: {
54: $responseClassMap = new ResponseClassMap();
55: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\CreateHostedCheckoutResponse';
56: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
57: try {
58: return $this->getCommunicator()->post(
59: $responseClassMap,
60: $this->instantiateUri('/v1/{merchantId}/hostedcheckouts'),
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}/hostedcheckouts/{hostedCheckoutId} - Get hosted checkout status
77: *
78: * @param string $hostedCheckoutId
79: * @param CallContext|null $callContext
80: *
81: * @return GetHostedCheckoutResponse
82: * @throws IdempotenceException
83: * @throws ValidationException
84: * @throws AuthorizationException
85: * @throws ReferenceException
86: * @throws PlatformException
87: * @throws ApiException
88: * @throws InvalidResponseException
89: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/hostedcheckouts/get.html Get hosted checkout status
90: */
91: public function get(string $hostedCheckoutId, ?CallContext $callContext = null): GetHostedCheckoutResponse
92: {
93: $this->context['hostedCheckoutId'] = $hostedCheckoutId;
94: $responseClassMap = new ResponseClassMap();
95: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\GetHostedCheckoutResponse';
96: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
97: try {
98: return $this->getCommunicator()->get(
99: $responseClassMap,
100: $this->instantiateUri('/v1/{merchantId}/hostedcheckouts/{hostedCheckoutId}'),
101: $this->getClientMetaInfo(),
102: null,
103: $callContext
104: );
105: } catch (ErrorResponseException $e) {
106: throw $this->getResponseExceptionFactory()->createException(
107: $e->getHttpStatusCode(),
108: $e->getErrorResponse(),
109: $callContext
110: );
111: }
112: }
113:
114: /**
115: * Resource /{merchantId}/hostedcheckouts/{hostedCheckoutId} - Delete hosted checkout
116: *
117: * @param string $hostedCheckoutId
118: * @param CallContext|null $callContext
119: *
120: * @return void
121: * @throws IdempotenceException
122: * @throws ValidationException
123: * @throws AuthorizationException
124: * @throws ReferenceException
125: * @throws PlatformException
126: * @throws ApiException
127: * @throws InvalidResponseException
128: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/hostedcheckouts/delete.html Delete hosted checkout
129: */
130: public function delete(string $hostedCheckoutId, ?CallContext $callContext = null): void
131: {
132: $this->context['hostedCheckoutId'] = $hostedCheckoutId;
133: $responseClassMap = new ResponseClassMap();
134: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
135: try {
136: $this->getCommunicator()->delete(
137: $responseClassMap,
138: $this->instantiateUri('/v1/{merchantId}/hostedcheckouts/{hostedCheckoutId}'),
139: $this->getClientMetaInfo(),
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: * @return ExceptionFactory
154: */
155: private function getResponseExceptionFactory(): ExceptionFactory
156: {
157: if (is_null($this->responseExceptionFactory)) {
158: $this->responseExceptionFactory = new ExceptionFactory();
159: }
160: return $this->responseExceptionFactory;
161: }
162: }
163: