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;
7:
8: use Worldline\Connect\Sdk\Domain\DataObject;
9: use Worldline\Connect\Sdk\V1\Domain\RefundErrorResponse;
10: use Worldline\Connect\Sdk\V1\Domain\RefundResult;
11:
12: /**
13: * Class DeclinedRefundException
14: *
15: * @package Worldline\Connect\Sdk\V1
16: */
17: class DeclinedRefundException extends ResponseException
18: {
19: /**
20: * @param int $httpStatusCode
21: * @param DataObject $response
22: * @param string $message
23: */
24: public function __construct($httpStatusCode, DataObject $response, $message = null)
25: {
26: if (is_null($message)) {
27: $message = DeclinedRefundException::buildMessage($response);
28: }
29: parent::__construct($httpStatusCode, $response, $message);
30: }
31:
32: private static function buildMessage(DataObject $response)
33: {
34: if ($response instanceof RefundErrorResponse && $response->refundResult != null) {
35: $refundResult = $response->refundResult;
36: return "declined refund '$refundResult->id' with status '$refundResult->status'";
37: }
38: return 'the Worldline Global Collect platform returned a declined refund response';
39: }
40:
41: /**
42: * @return RefundResult
43: */
44: public function getRefundResult()
45: {
46: $responseVariables = get_object_vars($this->getResponse());
47: if (!array_key_exists('refundResult', $responseVariables)) {
48: return new RefundResult();
49: }
50: $refundResult = $responseVariables['refundResult'];
51: if (!($refundResult instanceof RefundResult)) {
52: return new RefundResult();
53: }
54: return $refundResult;
55: }
56: }
57: