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\Captures;
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\DeclinedRefundException;
16: use Worldline\Connect\Sdk\V1\Domain\CaptureResponse;
17: use Worldline\Connect\Sdk\V1\Domain\CreateDisputeRequest;
18: use Worldline\Connect\Sdk\V1\Domain\DisputeResponse;
19: use Worldline\Connect\Sdk\V1\Domain\DisputesResponse;
20: use Worldline\Connect\Sdk\V1\Domain\RefundRequest;
21: use Worldline\Connect\Sdk\V1\Domain\RefundResponse;
22: use Worldline\Connect\Sdk\V1\ExceptionFactory;
23: use Worldline\Connect\Sdk\V1\IdempotenceException;
24: use Worldline\Connect\Sdk\V1\PlatformException;
25: use Worldline\Connect\Sdk\V1\ReferenceException;
26: use Worldline\Connect\Sdk\V1\ValidationException;
27:
28: /**
29: * Captures client.
30: *
31: * @package Worldline\Connect\Sdk\V1\Merchant\Captures
32: */
33: class CapturesClient extends ApiResource
34: {
35: /**
36: * @var ExceptionFactory|null
37: */
38: private ?ExceptionFactory $responseExceptionFactory = null;
39:
40: /**
41: * Resource /{merchantId}/captures/{captureId} - Get capture
42: *
43: * @param string $captureId
44: * @param CallContext|null $callContext
45: *
46: * @return CaptureResponse
47: * @throws IdempotenceException
48: * @throws ValidationException
49: * @throws AuthorizationException
50: * @throws ReferenceException
51: * @throws PlatformException
52: * @throws ApiException
53: * @throws InvalidResponseException
54: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/captures/get.html Get capture
55: */
56: public function get(string $captureId, ?CallContext $callContext = null): CaptureResponse
57: {
58: $this->context['captureId'] = $captureId;
59: $responseClassMap = new ResponseClassMap();
60: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\CaptureResponse';
61: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
62: try {
63: return $this->getCommunicator()->get(
64: $responseClassMap,
65: $this->instantiateUri('/v1/{merchantId}/captures/{captureId}'),
66: $this->getClientMetaInfo(),
67: null,
68: $callContext
69: );
70: } catch (ErrorResponseException $e) {
71: throw $this->getResponseExceptionFactory()->createException(
72: $e->getHttpStatusCode(),
73: $e->getErrorResponse(),
74: $callContext
75: );
76: }
77: }
78:
79: /**
80: * Resource /{merchantId}/captures/{captureId}/refund - Create Refund
81: *
82: * @param string $captureId
83: * @param RefundRequest $body
84: * @param CallContext|null $callContext
85: *
86: * @return RefundResponse
87: * @throws DeclinedRefundException
88: * @throws IdempotenceException
89: * @throws ValidationException
90: * @throws AuthorizationException
91: * @throws ReferenceException
92: * @throws PlatformException
93: * @throws ApiException
94: * @throws InvalidResponseException
95: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/captures/refund.html Create Refund
96: */
97: public function refund(string $captureId, RefundRequest $body, ?CallContext $callContext = null): RefundResponse
98: {
99: $this->context['captureId'] = $captureId;
100: $responseClassMap = new ResponseClassMap();
101: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\RefundResponse';
102: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\RefundErrorResponse';
103: try {
104: return $this->getCommunicator()->post(
105: $responseClassMap,
106: $this->instantiateUri('/v1/{merchantId}/captures/{captureId}/refund'),
107: $this->getClientMetaInfo(),
108: $body,
109: null,
110: $callContext
111: );
112: } catch (ErrorResponseException $e) {
113: throw $this->getResponseExceptionFactory()->createException(
114: $e->getHttpStatusCode(),
115: $e->getErrorResponse(),
116: $callContext
117: );
118: }
119: }
120:
121: /**
122: * Resource /{merchantId}/captures/{captureId}/disputes - Get disputes
123: *
124: * @param string $captureId
125: * @param CallContext|null $callContext
126: *
127: * @return DisputesResponse
128: * @throws IdempotenceException
129: * @throws ValidationException
130: * @throws AuthorizationException
131: * @throws ReferenceException
132: * @throws PlatformException
133: * @throws ApiException
134: * @throws InvalidResponseException
135: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/captures/disputes.html Get disputes
136: */
137: public function disputes(string $captureId, ?CallContext $callContext = null): DisputesResponse
138: {
139: $this->context['captureId'] = $captureId;
140: $responseClassMap = new ResponseClassMap();
141: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\DisputesResponse';
142: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
143: try {
144: return $this->getCommunicator()->get(
145: $responseClassMap,
146: $this->instantiateUri('/v1/{merchantId}/captures/{captureId}/disputes'),
147: $this->getClientMetaInfo(),
148: null,
149: $callContext
150: );
151: } catch (ErrorResponseException $e) {
152: throw $this->getResponseExceptionFactory()->createException(
153: $e->getHttpStatusCode(),
154: $e->getErrorResponse(),
155: $callContext
156: );
157: }
158: }
159:
160: /**
161: * Resource /{merchantId}/captures/{captureId}/dispute - Create dispute
162: *
163: * @param string $captureId
164: * @param CreateDisputeRequest $body
165: * @param CallContext|null $callContext
166: *
167: * @return DisputeResponse
168: * @throws IdempotenceException
169: * @throws ValidationException
170: * @throws AuthorizationException
171: * @throws ReferenceException
172: * @throws PlatformException
173: * @throws ApiException
174: * @throws InvalidResponseException
175: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/captures/dispute.html Create dispute
176: */
177: public function dispute(string $captureId, CreateDisputeRequest $body, ?CallContext $callContext = null): DisputeResponse
178: {
179: $this->context['captureId'] = $captureId;
180: $responseClassMap = new ResponseClassMap();
181: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\DisputeResponse';
182: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
183: try {
184: return $this->getCommunicator()->post(
185: $responseClassMap,
186: $this->instantiateUri('/v1/{merchantId}/captures/{captureId}/dispute'),
187: $this->getClientMetaInfo(),
188: $body,
189: null,
190: $callContext
191: );
192: } catch (ErrorResponseException $e) {
193: throw $this->getResponseExceptionFactory()->createException(
194: $e->getHttpStatusCode(),
195: $e->getErrorResponse(),
196: $callContext
197: );
198: }
199: }
200:
201: /**
202: * @return ExceptionFactory
203: */
204: private function getResponseExceptionFactory(): ExceptionFactory
205: {
206: if (is_null($this->responseExceptionFactory)) {
207: $this->responseExceptionFactory = new ExceptionFactory();
208: }
209: return $this->responseExceptionFactory;
210: }
211: }
212: