1: | <?php |
2: | |
3: | |
4: | |
5: | namespace Worldline\Acquiring\Sdk\V1\Acquirer\Merchant\Payments; |
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\ApiActionResponse; |
15: | use Worldline\Acquiring\Sdk\V1\Domain\ApiActionResponseForRefund; |
16: | use Worldline\Acquiring\Sdk\V1\Domain\ApiCaptureRequest; |
17: | use Worldline\Acquiring\Sdk\V1\Domain\ApiIncrementRequest; |
18: | use Worldline\Acquiring\Sdk\V1\Domain\ApiIncrementResponse; |
19: | use Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentRefundRequest; |
20: | use Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentRequest; |
21: | use Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentResource; |
22: | use Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentResponse; |
23: | use Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentReversalRequest; |
24: | use Worldline\Acquiring\Sdk\V1\Domain\ApiReversalResponse; |
25: | use Worldline\Acquiring\Sdk\V1\ExceptionFactory; |
26: | use Worldline\Acquiring\Sdk\V1\PlatformException; |
27: | use Worldline\Acquiring\Sdk\V1\ReferenceException; |
28: | use Worldline\Acquiring\Sdk\V1\ValidationException; |
29: | |
30: | |
31: | |
32: | |
33: | class PaymentsClient extends ApiResource |
34: | { |
35: | |
36: | private $responseExceptionFactory = null; |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | |
52: | |
53: | public function processPayment(ApiPaymentRequest $body, CallContext $callContext = null) |
54: | { |
55: | $responseClassMap = new ResponseClassMap(); |
56: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentResponse'; |
57: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentErrorResponse'; |
58: | try { |
59: | return $this->getCommunicator()->post( |
60: | $responseClassMap, |
61: | $this->instantiateUri('/processing/v1/{acquirerId}/{merchantId}/payments'), |
62: | $body, |
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: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: | |
86: | |
87: | |
88: | |
89: | |
90: | |
91: | public function getPaymentStatus($paymentId, GetPaymentStatusParams $query, CallContext $callContext = null) |
92: | { |
93: | $this->context['paymentId'] = $paymentId; |
94: | $responseClassMap = new ResponseClassMap(); |
95: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentResource'; |
96: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentErrorResponse'; |
97: | try { |
98: | return $this->getCommunicator()->get( |
99: | $responseClassMap, |
100: | $this->instantiateUri('/processing/v1/{acquirerId}/{merchantId}/payments/{paymentId}'), |
101: | $query, |
102: | $callContext |
103: | ); |
104: | } catch (ErrorResponseException $e) { |
105: | throw $this->getResponseExceptionFactory()->createException( |
106: | $e->getHttpStatusCode(), |
107: | $e->getErrorResponse(), |
108: | $callContext |
109: | ); |
110: | } |
111: | } |
112: | |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | |
123: | |
124: | |
125: | |
126: | |
127: | |
128: | |
129: | public function simpleCaptureOfPayment($paymentId, ApiCaptureRequest $body, CallContext $callContext = null) |
130: | { |
131: | $this->context['paymentId'] = $paymentId; |
132: | $responseClassMap = new ResponseClassMap(); |
133: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiActionResponse'; |
134: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentErrorResponse'; |
135: | try { |
136: | return $this->getCommunicator()->post( |
137: | $responseClassMap, |
138: | $this->instantiateUri('/processing/v1/{acquirerId}/{merchantId}/payments/{paymentId}/captures'), |
139: | $body, |
140: | null, |
141: | $callContext |
142: | ); |
143: | } catch (ErrorResponseException $e) { |
144: | throw $this->getResponseExceptionFactory()->createException( |
145: | $e->getHttpStatusCode(), |
146: | $e->getErrorResponse(), |
147: | $callContext |
148: | ); |
149: | } |
150: | } |
151: | |
152: | |
153: | |
154: | |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | |
161: | |
162: | |
163: | |
164: | |
165: | |
166: | |
167: | |
168: | public function reverseAuthorization($paymentId, ApiPaymentReversalRequest $body, CallContext $callContext = null) |
169: | { |
170: | $this->context['paymentId'] = $paymentId; |
171: | $responseClassMap = new ResponseClassMap(); |
172: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiReversalResponse'; |
173: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentErrorResponse'; |
174: | try { |
175: | return $this->getCommunicator()->post( |
176: | $responseClassMap, |
177: | $this->instantiateUri('/processing/v1/{acquirerId}/{merchantId}/payments/{paymentId}/authorization-reversals'), |
178: | $body, |
179: | null, |
180: | $callContext |
181: | ); |
182: | } catch (ErrorResponseException $e) { |
183: | throw $this->getResponseExceptionFactory()->createException( |
184: | $e->getHttpStatusCode(), |
185: | $e->getErrorResponse(), |
186: | $callContext |
187: | ); |
188: | } |
189: | } |
190: | |
191: | |
192: | |
193: | |
194: | |
195: | |
196: | |
197: | |
198: | |
199: | |
200: | |
201: | |
202: | |
203: | |
204: | |
205: | |
206: | |
207: | public function incrementPayment($paymentId, ApiIncrementRequest $body, CallContext $callContext = null) |
208: | { |
209: | $this->context['paymentId'] = $paymentId; |
210: | $responseClassMap = new ResponseClassMap(); |
211: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiIncrementResponse'; |
212: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentErrorResponse'; |
213: | try { |
214: | return $this->getCommunicator()->post( |
215: | $responseClassMap, |
216: | $this->instantiateUri('/processing/v1/{acquirerId}/{merchantId}/payments/{paymentId}/increments'), |
217: | $body, |
218: | null, |
219: | $callContext |
220: | ); |
221: | } catch (ErrorResponseException $e) { |
222: | throw $this->getResponseExceptionFactory()->createException( |
223: | $e->getHttpStatusCode(), |
224: | $e->getErrorResponse(), |
225: | $callContext |
226: | ); |
227: | } |
228: | } |
229: | |
230: | |
231: | |
232: | |
233: | |
234: | |
235: | |
236: | |
237: | |
238: | |
239: | |
240: | |
241: | |
242: | |
243: | |
244: | |
245: | |
246: | public function createRefund($paymentId, ApiPaymentRefundRequest $body, CallContext $callContext = null) |
247: | { |
248: | $this->context['paymentId'] = $paymentId; |
249: | $responseClassMap = new ResponseClassMap(); |
250: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiActionResponseForRefund'; |
251: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Acquiring\Sdk\V1\Domain\ApiPaymentErrorResponse'; |
252: | try { |
253: | return $this->getCommunicator()->post( |
254: | $responseClassMap, |
255: | $this->instantiateUri('/processing/v1/{acquirerId}/{merchantId}/payments/{paymentId}/refunds'), |
256: | $body, |
257: | null, |
258: | $callContext |
259: | ); |
260: | } catch (ErrorResponseException $e) { |
261: | throw $this->getResponseExceptionFactory()->createException( |
262: | $e->getHttpStatusCode(), |
263: | $e->getErrorResponse(), |
264: | $callContext |
265: | ); |
266: | } |
267: | } |
268: | |
269: | |
270: | private function getResponseExceptionFactory() |
271: | { |
272: | if (is_null($this->responseExceptionFactory)) { |
273: | $this->responseExceptionFactory = new ExceptionFactory(); |
274: | } |
275: | return $this->responseExceptionFactory; |
276: | } |
277: | } |
278: | |