diff --git a/CHANGELOG.md b/CHANGELOG.md index 054eea86..7a5622f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## unreleased +* Make Error\Validation jsonSerializable + ## 6.5.1 * Address PHP 8.1 Deprecation warnings diff --git a/lib/Braintree/Error/Validation.php b/lib/Braintree/Error/Validation.php index fc91ccc4..69bbf3d6 100644 --- a/lib/Braintree/Error/Validation.php +++ b/lib/Braintree/Error/Validation.php @@ -3,6 +3,7 @@ namespace Braintree\Error; use Braintree\Util; +use JsonSerializable; /** * error object returned as part of a validation error collection @@ -13,7 +14,7 @@ * // phpcs:ignore Generic.Files.LineLength * See our {@link https://developer.paypal.com/braintree/docs/reference/general/result-objects#error-results developer docs} for more information */ -class Validation +class Validation implements JsonSerializable { private $_attribute; private $_code; @@ -40,4 +41,19 @@ public function __get($name) $varName = "_$name"; return isset($this->$varName) ? $this->$varName : null; } + + /** + * Implementation of JsonSerializable + * + * @return array + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return array( + 'code' => $this->__get('code'), + 'attribute' => $this->__get('attribute'), + 'message' => $this->__get('message') + ); + } }