1: | <?php |
2: | |
3: | |
4: | |
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: | |
27: | |
28: | class CapturesClient extends ApiResource |
29: | { |
30: | |
31: | private $responseExceptionFactory = null; |
32: | |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | |
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: | |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: | |
86: | |
87: | |
88: | |
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: | |
115: | private function getResponseExceptionFactory() |
116: | { |
117: | if (is_null($this->responseExceptionFactory)) { |
118: | $this->responseExceptionFactory = new ExceptionFactory(); |
119: | } |
120: | return $this->responseExceptionFactory; |
121: | } |
122: | } |
123: | |