1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | namespace Worldline\Connect\Sdk\V1; |
7: | |
8: | use Worldline\Connect\Sdk\Domain\DataObject; |
9: | use Worldline\Connect\Sdk\V1\Domain\PayoutErrorResponse; |
10: | use Worldline\Connect\Sdk\V1\Domain\PayoutResult; |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | class DeclinedPayoutException extends ResponseException |
18: | { |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | public function __construct($httpStatusCode, DataObject $response, $message = null) |
25: | { |
26: | if (is_null($message)) { |
27: | $message = DeclinedPayoutException::buildMessage($response); |
28: | } |
29: | parent::__construct($httpStatusCode, $response, $message); |
30: | } |
31: | |
32: | private static function buildMessage(DataObject $response) |
33: | { |
34: | if ($response instanceof PayoutErrorResponse && $response->payoutResult != null) { |
35: | $payoutResult = $response->payoutResult; |
36: | return "declined payout '$payoutResult->id' with status '$payoutResult->status'"; |
37: | } |
38: | return 'the Worldline Global Collect platform returned a declined payout response'; |
39: | } |
40: | |
41: | |
42: | |
43: | |
44: | public function getPayoutResult() |
45: | { |
46: | $responseVariables = get_object_vars($this->getResponse()); |
47: | if (!array_key_exists('payoutResult', $responseVariables)) { |
48: | return new PayoutResult(); |
49: | } |
50: | $payoutResult = $responseVariables['payoutResult']; |
51: | if (!($payoutResult instanceof PayoutResult)) { |
52: | return new PayoutResult(); |
53: | } |
54: | return $payoutResult; |
55: | } |
56: | } |
57: | |