Skip to content

Commit

Permalink
JSONObjects implements JsonSerializable
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa-campoy committed Mar 27, 2020
1 parent db48b88 commit c17bb8a
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 c17bb8a

Please sign in to comment.