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\RefundRequest;
18: use Worldline\Connect\Sdk\V1\Domain\RefundResponse;
19: use Worldline\Connect\Sdk\V1\ExceptionFactory;
20: use Worldline\Connect\Sdk\V1\IdempotenceException;
21: use Worldline\Connect\Sdk\V1\PlatformException;
22: use Worldline\Connect\Sdk\V1\ReferenceException;
23: use Worldline\Connect\Sdk\V1\ValidationException;
24:
25: /**
26: * Captures client.
27: */
28: class CapturesClient extends ApiResource
29: {
30: /** @var ExceptionFactory|null */
31: private $responseExceptionFactory = null;
32:
33: /**
34: * Resource /{merchantId}/captures/{captureId} - Get capture
35: *
36: * @param string $captureId
37: * @param CallContext $callContext
38: * @return CaptureResponse
39: *
40: * @throws IdempotenceException
41: * @throws ValidationException
42: * @throws AuthorizationException
43: * @throws ReferenceException
44: * @throws PlatformException
45: * @throws ApiException
46: * @throws InvalidResponseException
47: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/captures/get.html Get capture
48: */
49: public function get($captureId, CallContext $callContext = null)
50: {
51: $this->context['captureId'] = $captureId;
52: $responseClassMap = new ResponseClassMap();
53: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\CaptureResponse';
54: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse';
55: try {
56: return $this->getCommunicator()->get(
57: $responseClassMap,
58: $this->instantiateUri('/v1/{merchantId}/captures/{captureId}'),
59: $this->getClientMetaInfo(),
60: null,
61: $callContext
62: );
63: } catch (ErrorResponseException $e) {
64: throw $this->getResponseExceptionFactory()->createException(
65: $e->getHttpStatusCode(),
66: $e->getErrorResponse(),
67: $callContext
68: );
69: }
70: }
71:
72: /**
73: * Resource /{merchantId}/captures/{captureId}/refund - Create Refund
74: *
75: * @param string $captureId
76: * @param RefundRequest $body
77: * @param CallContext $callContext
78: * @return RefundResponse
79: *
80: * @throws DeclinedRefundException
81: * @throws IdempotenceException
82: * @throws ValidationException
83: * @throws AuthorizationException
84: * @throws ReferenceException
85: * @throws PlatformException
86: * @throws ApiException
87: * @throws InvalidResponseException
88: * @link https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/php/captures/refund.html Create Refund
89: */
90: public function refund($captureId, RefundRequest $body, CallContext $callContext = null)
91: {
92: $this->context['captureId'] = $captureId;
93: $responseClassMap = new ResponseClassMap();
94: $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\RefundResponse';
95: $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\RefundErrorResponse';
96: try {
97: return $this->getCommunicator()->post(
98: $responseClassMap,
99: $this->instantiateUri('/v1/{merchantId}/captures/{captureId}/refund'),
100: $this->getClientMetaInfo(),
101: $body,
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: /** @return ExceptionFactory */
115: private function getResponseExceptionFactory()
116: {
117: if (is_null($this->responseExceptionFactory)) {
118: $this->responseExceptionFactory = new ExceptionFactory();
119: }
120: return $this->responseExceptionFactory;
121: }
122: }
123: