diff --git a/composer.json b/composer.json index 4a893b1..aad4fb6 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ ], "require": { "php": ">=5.6", - "ext-curl": "*" + "ext-curl": "*", + "ext-json": "*" }, "autoload" : { "files": ["source/paysafe.php"] diff --git a/source/Paysafe/JSONObject.php b/source/Paysafe/JSONObject.php index ef3a8ce..c10586a 100644 --- a/source/Paysafe/JSONObject.php +++ b/source/Paysafe/JSONObject.php @@ -21,7 +21,9 @@ namespace Paysafe; -class JSONObject { +use JsonSerializable; + +class JSONObject implements JsonSerializable{ protected static $fieldTypes = array(); private $properties = array(); @@ -37,7 +39,7 @@ public function setOptionalFields($fields) { if (!is_array($fields)) { throw new PaysafeException('Invalid optional fields. Array expected.'); } - if (($diff = array_diff($fields, array_keys(static::$fieldTypes)))) { + if ($diff = array_diff($fields, array_keys(static::$fieldTypes))) { throw new PaysafeException('Invalid optional fields. Unknown fields: ' . join(', ', $diff)); } @@ -202,7 +204,8 @@ private function cast($name, $value, $type) { /** * - * @return json encoded copy of this object + * @return string|false encoded copy of this object + * @throws PaysafeException */ public function toJson() { return json_encode($this->jsonSerialize()); @@ -225,7 +228,7 @@ final public function jsonSerialize() { } public function checkRequiredFields() { - if (($diff = array_diff($this->requiredFields, array_keys($this->properties)))) { + if ($diff = array_diff($this->requiredFields, array_keys($this->properties))) { throw new PaysafeException('Missing required properties: ' . join(', ', $diff), 500); } } diff --git a/tests/paysafe/MerchantAccountServiceTest.php b/tests/paysafe/MerchantAccountServiceTest.php index a80d749..a8b84cb 100644 --- a/tests/paysafe/MerchantAccountServiceTest.php +++ b/tests/paysafe/MerchantAccountServiceTest.php @@ -101,7 +101,7 @@ public function testCreateMerchantAccountMissingRequiredFields() $this->expectException(PaysafeException::class); $this->expectExceptionCode(500); - $this->expectExceptionMessage('Missing required properties: name, currency, region, legalEntity, productCode, category, phone, yearlyVolumeRange, averageTransactionAmount, merchantDescriptor, caAccountDetails'); + $this->expectExceptionMessage('Missing required properties: name, currency, region, legalEntity, productCode, category, phone, yearlyVolumeRange, averageTransactionAmount, merchantDescriptor'); $mas->createMerchantAccount(new MerchantAccount()); }