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: class CapturesClient extends ApiResource
32: {
33: /** @var ExceptionFactory|null */
34: private $responseExceptionFactory = null;
35:
36: /**
37: * Resource /{merchantId}/captures/{captureId} - Get capture
38: *
39: * @param string $captureId
40: * @param CallContext $callContext
41: * @return CaptureResponse
42: *
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/captures/get.html Get capture
51: */
52: public function get($captureId, CallContext $callContext = null)
53: {
54: $this->context['captureId'] = $captureId;
55: $responseClassMap = new ResponseClassMap();
56: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\CaptureResponse';
57: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
58: try {
59: return $this->getCommunicator()->get(
60: $responseClassMap,
61: $this->instantiateUri('/v1/{merchantId}/captures/{captureId}'),
62: $this->getClientMetaInfo(),
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}/captures/{captureId}/refund - Create Refund
77: *
78: * @param string $captureId
79: * @param RefundRequest $body
80: * @param CallContext $callContext
81: * @return RefundResponse
82: *
83: * @throws DeclinedRefundException
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/captures/refund.html Create Refund
92: */
93: public function refund($captureId, RefundRequest $body, CallContext $callContext = null)
94: {
95: $this->context['captureId'] = $captureId;
96: $responseClassMap = new ResponseClassMap();
97: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\RefundResponse';
98: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\RefundErrorResponse';
99: try {
100: return $this->getCommunicator()->post(
101: $responseClassMap,
102: $this->instantiateUri('/v1/{merchantId}/captures/{captureId}/refund'),
103: $this->getClientMetaInfo(),
104: $body,
105: null,
106: $callContext
107: );
108: } catch (ErrorResponseException $e) {
109: throw $this->getResponseExceptionFactory()->createException(
110: $e->getHttpStatusCode(),
111: $e->getErrorResponse(),
112: $callContext
113: );
114: }
115: }
116:
117: /**
118: * Resource /{merchantId}/captures/{captureId}/disputes - Get disputes
119: *
120: * @param string $captureId
121: * @param CallContext $callContext
122: * @return DisputesResponse
123: *
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/captures/disputes.html Get disputes
132: */
133: public function disputes($captureId, CallContext $callContext = null)
134: {
135: $this->context['captureId'] = $captureId;
136: $responseClassMap = new ResponseClassMap();
137: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\DisputesResponse';
138: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
139: try {
140: return $this->getCommunicator()->get(
141: $responseClassMap,
142: $this->instantiateUri('/v1/{merchantId}/captures/{captureId}/disputes'),
143: $this->getClientMetaInfo(),
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}/captures/{captureId}/dispute - Create dispute
158: *
159: * @param string $captureId
160: * @param CreateDisputeRequest $body
161: * @param CallContext $callContext
162: * @return DisputeResponse
163: *
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/captures/dispute.html Create dispute
172: */
173: public function dispute($captureId, CreateDisputeRequest $body, CallContext $callContext = null)
174: {
175: $this->context['captureId'] = $captureId;
176: $responseClassMap = new ResponseClassMap();
177: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\DisputeResponse';
178: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
179: try {
180: return $this->getCommunicator()->post(
181: $responseClassMap,
182: $this->instantiateUri('/v1/{merchantId}/captures/{captureId}/dispute'),
183: $this->getClientMetaInfo(),
184: $body,
185: null,
186: $callContext
187: );
188: } catch (ErrorResponseException $e) {
189: throw $this->getResponseExceptionFactory()->createException(
190: $e->getHttpStatusCode(),
191: $e->getErrorResponse(),
192: $callContext
193: );
194: }
195: }
196:
197: /** @return ExceptionFactory */
198: private function getResponseExceptionFactory()
199: {
200: if (is_null($this->responseExceptionFactory)) {
201: $this->responseExceptionFactory = new ExceptionFactory();
202: }
203: return $this->responseExceptionFactory;
204: }
205: }
206: