Skip to content

Commit

Permalink
Merge pull request #181 from bunq/feature/fix_double_wrapped_objects
Browse files Browse the repository at this point in the history
Fix decoding of double-wrapped objects. Updated OAuth endpoints.
  • Loading branch information
andrederoos authored Sep 13, 2019
2 parents feaf376 + 96f4941 commit 69df09e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/Model/Core/BunqModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ private static function determineFieldContents(ReflectionProperty $property, $co
/** @var BunqModel $modelClassNameQualified */
$modelClassNameQualified = ModelUtil::determineModelClassNameQualified($fieldType);

$parentClassName = $property->getDeclaringClass()->getName();
$additionalWrappingKey = BunqModelWrapper::determineWrappingKey($parentClassName, $property->getName());

if (!is_null($additionalWrappingKey)) {
if (isset($contents[$additionalWrappingKey])) {
return $modelClassNameQualified::createFromResponseArray($contents[$additionalWrappingKey]);
}
}

return $modelClassNameQualified::createFromResponseArray($contents);
}
} else {
Expand Down
43 changes: 43 additions & 0 deletions src/Model/Core/BunqModelWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace bunq\Model\Core;

use bunq\Model\Generated\Endpoint\BunqMeTabResultInquiry;
use bunq\Model\Generated\Endpoint\Payment;
use JsonSerializable;

/**
* Base class for all endpoints, responsible for parsing json received from the server.
*/
abstract class BunqModelWrapper implements JsonSerializable
{
/**
* Field constants.
*/
const FIELD_PAYMENT = 'payment';

/**
* The double wrapping map.
*/
const MODEL_WRAPPING_MAP = [
BunqMeTabResultInquiry::class => [
self::FIELD_PAYMENT => Payment::OBJECT_TYPE_GET
]
];

/**
* @param $className
* @param $propertyName
*
* @return string|null
*/
public static function determineWrappingKey($className, $propertyName)
{
if (isset(self::MODEL_WRAPPING_MAP[$className])) {
if (isset(self::MODEL_WRAPPING_MAP[$className][$propertyName])) {
return self::MODEL_WRAPPING_MAP[$className][$propertyName];
}
}

return null;
}
}
4 changes: 2 additions & 2 deletions src/Model/Core/OauthAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class OauthAccessToken extends BunqModel
/**
* Token constants.
*/
const TOKEN_URI_FORMAT_SANDBOX = 'https://api.oauth.sandbox.bunq.com/v1/token?';
const TOKEN_URI_FORMAT_PRODUCTION = 'https://api.oauth.bunq.com/v1/token?';
const TOKEN_URI_FORMAT_SANDBOX = 'https://api.oauth.sandbox.bunq.com/v1/token?%s';
const TOKEN_URI_FORMAT_PRODUCTION = 'https://api.oauth.bunq.com/v1/token?%s';

/**
* Error constants.
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Core/OauthAuthorizationUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class OauthAuthorizationUri extends BunqModel
/**
* Uri constants.
*/
const AUTH_URI_FORMAT_PRODUCTION = 'https://oauth.bunq.com/auth?';
const AUTH_URI_FORMAT_SANDBOX = 'https://oauth.sandbox.bunq.com/auth?';
const AUTH_URI_FORMAT_PRODUCTION = 'https://oauth.bunq.com/auth?%s';
const AUTH_URI_FORMAT_SANDBOX = 'https://oauth.sandbox.bunq.com/auth?%s';

/**
* Field constants.
Expand Down

0 comments on commit 69df09e

Please sign in to comment.