1: | <?php |
2: | |
3: | |
4: | |
5: | namespace Worldline\Acquiring\Sdk\V1\Acquirer\Merchant\Refunds; |
6: | |
7: | use Worldline\Acquiring\Sdk\ApiResource; |
8: | use Worldline\Acquiring\Sdk\CallContext; |
9: | use Worldline\Acquiring\Sdk\Communication\ErrorResponseException; |
10: | use Worldline\Acquiring\Sdk\Communication\InvalidResponseException; |
11: | use Worldline\Acquiring\Sdk\Communication\ResponseClassMap; |
12: | use Worldline\Acquiring\Sdk\V1\ApiException; |
13: | use Worldline\Acquiring\Sdk\V1\AuthorizationException; |
14: | use Worldline\Acquiring\Sdk\V1\Domain\ApiActionResponseForRefund; |
15: | use Worldline\Acquiring\Sdk\V1\Domain\ApiCaptureRequestForRefund; |
16: | use Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentReversalRequest; |
17: | use Worldline\Acquiring\Sdk\V1\Domain\ApiRefundRequest; |
18: | use Worldline\Acquiring\Sdk\V1\Domain\ApiRefundResource; |
19: | use Worldline\Acquiring\Sdk\V1\Domain\ApiRefundResponse; |
20: | use Worldline\Acquiring\Sdk\V1\ExceptionFactory; |
21: | use Worldline\Acquiring\Sdk\V1\PlatformException; |
22: | use Worldline\Acquiring\Sdk\V1\ReferenceException; |
23: | use Worldline\Acquiring\Sdk\V1\ValidationException; |
24: | |
25: | |
26: | |
27: | |
28: | class RefundsClient 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: | public function processStandaloneRefund(ApiRefundRequest $body, CallContext $callContext = null) |
49: | { |
50: | $responseClassMap = new ResponseClassMap(); |
51: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiRefundResponse'; |
52: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentErrorResponse'; |
53: | try { |
54: | return $this->getCommunicator()->post( |
55: | $responseClassMap, |
56: | $this->instantiateUri('/processing/v1/{acquirerId}/{merchantId}/refunds'), |
57: | $body, |
58: | null, |
59: | $callContext |
60: | ); |
61: | } catch (ErrorResponseException $e) { |
62: | throw $this->getResponseExceptionFactory()->createException( |
63: | $e->getHttpStatusCode(), |
64: | $e->getErrorResponse(), |
65: | $callContext |
66: | ); |
67: | } |
68: | } |
69: | |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: | |
86: | public function getRefund($refundId, GetRefundParams $query, CallContext $callContext = null) |
87: | { |
88: | $this->context['refundId'] = $refundId; |
89: | $responseClassMap = new ResponseClassMap(); |
90: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiRefundResource'; |
91: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentErrorResponse'; |
92: | try { |
93: | return $this->getCommunicator()->get( |
94: | $responseClassMap, |
95: | $this->instantiateUri('/processing/v1/{acquirerId}/{merchantId}/refunds/{refundId}'), |
96: | $query, |
97: | $callContext |
98: | ); |
99: | } catch (ErrorResponseException $e) { |
100: | throw $this->getResponseExceptionFactory()->createException( |
101: | $e->getHttpStatusCode(), |
102: | $e->getErrorResponse(), |
103: | $callContext |
104: | ); |
105: | } |
106: | } |
107: | |
108: | |
109: | |
110: | |
111: | |
112: | |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | |
123: | |
124: | public function captureRefund($refundId, ApiCaptureRequestForRefund $body, CallContext $callContext = null) |
125: | { |
126: | $this->context['refundId'] = $refundId; |
127: | $responseClassMap = new ResponseClassMap(); |
128: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiActionResponseForRefund'; |
129: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentErrorResponse'; |
130: | try { |
131: | return $this->getCommunicator()->post( |
132: | $responseClassMap, |
133: | $this->instantiateUri('/processing/v1/{acquirerId}/{merchantId}/refunds/{refundId}/captures'), |
134: | $body, |
135: | null, |
136: | $callContext |
137: | ); |
138: | } catch (ErrorResponseException $e) { |
139: | throw $this->getResponseExceptionFactory()->createException( |
140: | $e->getHttpStatusCode(), |
141: | $e->getErrorResponse(), |
142: | $callContext |
143: | ); |
144: | } |
145: | } |
146: | |
147: | |
148: | |
149: | |
150: | |
151: | |
152: | |
153: | |
154: | |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | |
161: | |
162: | |
163: | public function reverseRefundAuthorization($refundId, ApiPaymentReversalRequest $body, CallContext $callContext = null) |
164: | { |
165: | $this->context['refundId'] = $refundId; |
166: | $responseClassMap = new ResponseClassMap(); |
167: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiActionResponseForRefund'; |
168: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentErrorResponse'; |
169: | try { |
170: | return $this->getCommunicator()->post( |
171: | $responseClassMap, |
172: | $this->instantiateUri('/processing/v1/{acquirerId}/{merchantId}/refunds/{refundId}/authorization-reversals'), |
173: | $body, |
174: | null, |
175: | $callContext |
176: | ); |
177: | } catch (ErrorResponseException $e) { |
178: | throw $this->getResponseExceptionFactory()->createException( |
179: | $e->getHttpStatusCode(), |
180: | $e->getErrorResponse(), |
181: | $callContext |
182: | ); |
183: | } |
184: | } |
185: | |
186: | |
187: | private function getResponseExceptionFactory() |
188: | { |
189: | if (is_null($this->responseExceptionFactory)) { |
190: | $this->responseExceptionFactory = new ExceptionFactory(); |
191: | } |
192: | return $this->responseExceptionFactory; |
193: | } |
194: | } |
195: | |