Skip to content

Commit

Permalink
Merged in VB2C-346-to-2.3 (pull request #74)
Browse files Browse the repository at this point in the history
VB2C-346: error returned by Vipps was not logged
  • Loading branch information
Serhiy Shkolyarenko committed Feb 21, 2019
2 parents d9e1dc7 + 923692b commit 5220d97
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
30 changes: 1 addition & 29 deletions Gateway/Http/Client/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ class Curl implements ClientInterface
*/
private $logger;

/**
* @var array
*/
private $allowedFields = [
'orderId',
'customerInfo',
'merchantInfo',
'transaction',
];

/**
* Curl constructor.
*
Expand Down Expand Up @@ -125,7 +115,7 @@ private function place(TransferInterface $transfer)
/** @var MagentoCurl $adapter */
$adapter = $this->adapterFactory->create();
$options = $this->getBasicOptions();
$requestBody = $this->preparePostFields($transfer->getBody());
$requestBody = $transfer->getBody();
if ($transfer->getMethod() === Request::METHOD_PUT) {
$options = $options +
[
Expand All @@ -152,24 +142,6 @@ private function place(TransferInterface $transfer)
}
}

/**
* Remove all fields that are not marked as known.
*
* @param array $fields
* @return array
*/
private function preparePostFields($fields)
{
$allowedFields = $this->allowedFields;
$fields = array_filter(
$fields,
function ($key) use ($allowedFields) { return in_array($key, $allowedFields);},
ARRAY_FILTER_USE_KEY
);

return $fields;
}

/**
* @param $headers
*
Expand Down
32 changes: 29 additions & 3 deletions Gateway/Http/TransferFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ class TransferFactory implements TransferFactoryInterface
*/
private $urlParams = [];

/**
* @var array
*/
private $allowedFields = [
'orderId',
'customerInfo',
'merchantInfo',
'transaction',
];

/**
* TransferFactory constructor.
*
Expand Down Expand Up @@ -91,9 +101,7 @@ public function create(array $request)
ClientInterface::HEADER_PARAM_X_REQUEST_ID => $request['requestId'] ?? $this->generateRequestId()
]);

if (isset($request['requestId'])) {
unset($request['requestId']);
}
$request = $this->filterPostFields($request);

$this->transferBuilder
->setBody($this->getBody($request))
Expand All @@ -103,6 +111,24 @@ public function create(array $request)
return $this->transferBuilder->build();
}

/**
* Remove all fields that are not marked as allowed.
*
* @param array $fields
* @return array
*/
private function filterPostFields($fields)
{
$allowedFields = $this->allowedFields;
$fields = array_filter(
$fields,
function ($key) use ($allowedFields) { return in_array($key, $allowedFields);},
ARRAY_FILTER_USE_KEY
);

return $fields;
}

/**
* Generating Url.
*
Expand Down

0 comments on commit 5220d97

Please sign in to comment.