wp-pay-gateways /
adyen
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Service exception |
||
| 4 | * |
||
| 5 | * @author Pronamic <[email protected]> |
||
| 6 | * @copyright 2005-2019 Pronamic |
||
| 7 | * @license GPL-3.0-or-later |
||
| 8 | * @package Pronamic\WordPress\Pay\Gateways\OmniKassa2 |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Pronamic\WordPress\Pay\Gateways\Adyen; |
||
| 12 | |||
| 13 | use Exception; |
||
| 14 | use InvalidArgumentException; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Service exception |
||
| 18 | * |
||
| 19 | * @link https://docs.adyen.com/developers/api-reference/common-api/serviceexception |
||
| 20 | * |
||
| 21 | * @author Remco Tolsma |
||
| 22 | * @version 1.0.0 |
||
| 23 | * @since 1.0.0 |
||
| 24 | */ |
||
| 25 | class ServiceException extends Exception { |
||
| 26 | /** |
||
| 27 | * The HTTP response status code. |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $status; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The Adyen code that is mapped to the error message. |
||
| 35 | * |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $error_code; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * The type of error that was encountered. |
||
| 42 | * |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | private $error_type; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Construct service exception. |
||
| 49 | * |
||
| 50 | * @param string $status Status. |
||
| 51 | * @param string $error_code Error code. |
||
| 52 | * @param string $message Message. |
||
| 53 | * @param string $error_type Error type. |
||
| 54 | */ |
||
| 55 | 1 | public function __construct( $status, $error_code, $message, $error_type ) { |
|
| 56 | 1 | parent::__construct( $message, $error_code ); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 57 | |||
| 58 | 1 | $this->status = $status; |
|
| 59 | 1 | $this->error_code = $error_code; |
|
| 60 | 1 | $this->error_type = $error_type; |
|
| 61 | 1 | } |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Get status. |
||
| 65 | * |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | 1 | public function get_status() { |
|
| 69 | 1 | return $this->status; |
|
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Get error code. |
||
| 74 | * |
||
| 75 | * @return string |
||
| 76 | */ |
||
| 77 | 1 | public function get_error_code() { |
|
| 78 | 1 | return $this->error_code; |
|
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Get message. |
||
| 83 | * |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | 1 | public function get_message() { |
|
| 87 | 1 | return $this->getMessage(); |
|
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Get error type. |
||
| 92 | * |
||
| 93 | * @return string |
||
| 94 | */ |
||
| 95 | 1 | public function get_error_type() { |
|
| 96 | 1 | return $this->error_type; |
|
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Create service exception from object. |
||
| 101 | * |
||
| 102 | * @param object $object Object. |
||
| 103 | * @return ServiceException |
||
| 104 | * @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties. |
||
| 105 | */ |
||
| 106 | 1 | public static function from_object( $object ) { |
|
| 107 | 1 | if ( ! isset( $object->status ) ) { |
|
| 108 | throw new InvalidArgumentException( 'Object must contain `status` property.' ); |
||
| 109 | } |
||
| 110 | |||
| 111 | 1 | if ( ! isset( $object->errorCode ) ) { |
|
| 112 | throw new InvalidArgumentException( 'Object must contain `errorCode` property.' ); |
||
| 113 | } |
||
| 114 | |||
| 115 | 1 | if ( ! isset( $object->message ) ) { |
|
| 116 | throw new InvalidArgumentException( 'Object must contain `message` property.' ); |
||
| 117 | } |
||
| 118 | |||
| 119 | 1 | if ( ! isset( $object->errorType ) ) { |
|
| 120 | throw new InvalidArgumentException( 'Object must contain `errorType` property.' ); |
||
| 121 | } |
||
| 122 | |||
| 123 | 1 | return new self( |
|
| 124 | 1 | $object->status, |
|
| 125 | 1 | $object->errorCode, |
|
| 126 | 1 | $object->message, |
|
| 127 | 1 | $object->errorType |
|
| 128 | ); |
||
| 129 | } |
||
| 130 | } |
||
| 131 |