Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONObjects implements JsonSerializable #3

Merged
merged 1 commit into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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