Skip to content

Commit

Permalink
Fix data before send to Authorize
Browse files Browse the repository at this point in the history
  • Loading branch information
Novikov Andrey committed Apr 16, 2018
1 parent 57acdf2 commit 17311ca
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Omnipay\Sberbank\Message;

use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Exception\RuntimeException;
use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;

Expand Down Expand Up @@ -165,11 +166,11 @@ public function sendData($data)
], $data)
);

$responseClassName = str_replace('Request', 'Response', get_class($this));
$responseClassName = str_replace('Request', 'Response', \get_class($this));
$reflection = new \ReflectionClass($responseClassName);
if (!$reflection->isInstantiable()) {
throw new RuntimeException(
'Class ' . str_replace('Request', 'Response', get_class($this)) . ' not found'
'Class ' . str_replace('Request', 'Response', \get_class($this)) . ' not found'
);
}

Expand Down
35 changes: 35 additions & 0 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Omnipay\Sberbank\Message;

use Omnipay\Common\Exception\RuntimeException;

/**
* Class AuthorizeRequest
* @package Omnipay\Sberbank\Message
Expand Down Expand Up @@ -226,4 +228,37 @@ public function setBindingId($value)
{
return $this->setParameter('bindingId', $value);
}

/**
* @param mixed $data
* @return object|\Omnipay\Common\Message\ResponseInterface
* @throws \ReflectionException
* @throws \Omnipay\Common\Exception\InvalidRequestException
*/
public function sendData($data)
{
$url = $this->getEndPoint() . $this->getMethod();
$this->validate('userName', 'password');
$data['currency'] = $this->getCurrencyNumeric();
$data['amount'] = $this->getAmountInteger();
$httpResponse = $this->httpClient->send(
$this->getHttpMethod(),
$url,
$this->getHeaders(),
array_merge([
'userName' => $this->getUserName(),
'password' => $this->getPassword()
], $data)
);

$responseClassName = str_replace('Request', 'Response', \get_class($this));
$reflection = new \ReflectionClass($responseClassName);
if (!$reflection->isInstantiable()) {
throw new RuntimeException(
'Class ' . str_replace('Request', 'Response', \get_class($this)) . ' not found'
);
}

return $reflection->newInstance($this, json_decode($httpResponse->getBody(true), true));
}
}
4 changes: 1 addition & 3 deletions src/Message/BindCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ public function getData()
{
$this->validate('bindingId');

$data = [
return [
'bindingId' => $this->getBindingId()
];

return $data;
}

/**
Expand Down
11 changes: 10 additions & 1 deletion tests/Message/AuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class AuthorizeRequestTest extends AbstractRequestTest
*/
protected $orderNumber;

/**
* Currency
*
* @var string
*/
protected $currency;

/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
Expand All @@ -41,6 +48,7 @@ public function setUp()
$this->amount = mt_rand(1, 100);
$this->returnUrl = 'https://test.com/' . uniqid('', true);
$this->orderNumber = uniqid('order_number_', true);
$this->currency = 'RUB';

parent::setUp();
}
Expand Down Expand Up @@ -77,7 +85,8 @@ protected function getRequestParameters()
return [
'orderNumber' => $this->orderNumber,
'amount' => $this->amount,
'returnUrl' => $this->returnUrl
'returnUrl' => $this->returnUrl,
'currency' => $this->currency
];
}

Expand Down

0 comments on commit 17311ca

Please sign in to comment.