Skip to content

Commit

Permalink
Merge pull request #3 from CloudBeds/jsonobject-implements-jsonserial…
Browse files Browse the repository at this point in the history
…izable

JSONObjects implements JsonSerializable
  • Loading branch information
cb-vova authored Mar 30, 2020
2 parents db48b88 + c17bb8a commit 1015ed8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
],
"require": {
"php": ">=5.6",
"ext-curl": "*"
"ext-curl": "*",
"ext-json": "*"
},
"autoload" : {
"files": ["source/paysafe.php"]
Expand Down
11 changes: 7 additions & 4 deletions source/Paysafe/JSONObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

namespace Paysafe;

class JSONObject {
use JsonSerializable;

class JSONObject implements JsonSerializable{

protected static $fieldTypes = array();
private $properties = array();
Expand All @@ -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));
}

Expand Down Expand Up @@ -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());
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/paysafe/MerchantAccountServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 1015ed8

Please sign in to comment.