diff --git a/Gateway/Http/Client/Curl.php b/Gateway/Http/Client/Curl.php index 7d79f5f4..b48e28db 100644 --- a/Gateway/Http/Client/Curl.php +++ b/Gateway/Http/Client/Curl.php @@ -57,16 +57,6 @@ class Curl implements ClientInterface */ private $logger; - /** - * @var array - */ - private $allowedFields = [ - 'orderId', - 'customerInfo', - 'merchantInfo', - 'transaction', - ]; - /** * Curl constructor. * @@ -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 + [ @@ -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 * diff --git a/Gateway/Http/TransferFactory.php b/Gateway/Http/TransferFactory.php index 7664e4a4..09662011 100644 --- a/Gateway/Http/TransferFactory.php +++ b/Gateway/Http/TransferFactory.php @@ -54,6 +54,16 @@ class TransferFactory implements TransferFactoryInterface */ private $urlParams = []; + /** + * @var array + */ + private $allowedFields = [ + 'orderId', + 'customerInfo', + 'merchantInfo', + 'transaction', + ]; + /** * TransferFactory constructor. * @@ -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)) @@ -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. *