Skip to content

Commit 1015ed8

Browse files
authored
Merge pull request #3 from CloudBeds/jsonobject-implements-jsonserializable
JSONObjects implements JsonSerializable
2 parents db48b88 + c17bb8a commit 1015ed8

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
],
1616
"require": {
1717
"php": ">=5.6",
18-
"ext-curl": "*"
18+
"ext-curl": "*",
19+
"ext-json": "*"
1920
},
2021
"autoload" : {
2122
"files": ["source/paysafe.php"]

source/Paysafe/JSONObject.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
namespace Paysafe;
2323

24-
class JSONObject {
24+
use JsonSerializable;
25+
26+
class JSONObject implements JsonSerializable{
2527

2628
protected static $fieldTypes = array();
2729
private $properties = array();
@@ -37,7 +39,7 @@ public function setOptionalFields($fields) {
3739
if (!is_array($fields)) {
3840
throw new PaysafeException('Invalid optional fields. Array expected.');
3941
}
40-
if (($diff = array_diff($fields, array_keys(static::$fieldTypes)))) {
42+
if ($diff = array_diff($fields, array_keys(static::$fieldTypes))) {
4143
throw new PaysafeException('Invalid optional fields. Unknown fields: ' . join(', ', $diff));
4244
}
4345

@@ -202,7 +204,8 @@ private function cast($name, $value, $type) {
202204

203205
/**
204206
*
205-
* @return json encoded copy of this object
207+
* @return string|false encoded copy of this object
208+
* @throws PaysafeException
206209
*/
207210
public function toJson() {
208211
return json_encode($this->jsonSerialize());
@@ -225,7 +228,7 @@ final public function jsonSerialize() {
225228
}
226229

227230
public function checkRequiredFields() {
228-
if (($diff = array_diff($this->requiredFields, array_keys($this->properties)))) {
231+
if ($diff = array_diff($this->requiredFields, array_keys($this->properties))) {
229232
throw new PaysafeException('Missing required properties: ' . join(', ', $diff), 500);
230233
}
231234
}

tests/paysafe/MerchantAccountServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function testCreateMerchantAccountMissingRequiredFields()
101101

102102
$this->expectException(PaysafeException::class);
103103
$this->expectExceptionCode(500);
104-
$this->expectExceptionMessage('Missing required properties: name, currency, region, legalEntity, productCode, category, phone, yearlyVolumeRange, averageTransactionAmount, merchantDescriptor, caAccountDetails');
104+
$this->expectExceptionMessage('Missing required properties: name, currency, region, legalEntity, productCode, category, phone, yearlyVolumeRange, averageTransactionAmount, merchantDescriptor');
105105

106106
$mas->createMerchantAccount(new MerchantAccount());
107107
}

0 commit comments

Comments
 (0)