Skip to content

Commit

Permalink
merge with updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Novikov Andrey committed Jan 22, 2019
1 parent c9ce0b6 commit 6301b3e
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 12 deletions.
6 changes: 0 additions & 6 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ public function sendData($data)
{
$url = $this->getEndPoint() . $this->getMethod();
$this->validate('userName', 'password');
if(array_key_exists('currency', $data)) {
$data['currency'] = $this->getCurrencyNumeric();
}
if(array_key_exists('amount', $data)) {
$data['amount'] = $this->getAmountInteger();
}
$data = array_merge(
[
'userName' => $this->getUserName(),
Expand Down
40 changes: 40 additions & 0 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,44 @@ 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();
$data = array_merge(
[
'userName' => $this->getUserName(),
'password' => $this->getPassword(),
],
$data
);

$httpResponse = $this->httpClient->request(
$this->getHttpMethod(),
$url,
$this->getHeaders(),
http_build_query($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'
);
}

$content = json_decode($httpResponse->getBody()->getContents(), true);

return $reflection->newInstance($this, $content);
}
}
2 changes: 1 addition & 1 deletion src/Message/CaptureRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getData()

$data = [
'orderId' => $this->getOrderId(),
'amount' => $this->getAmount(),
'amount' => $this->getAmountInteger(),
];

return $data;
Expand Down
2 changes: 1 addition & 1 deletion src/Message/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getData()

$data = [
'orderId' => $this->getOrderId(),
'amount' => $this->getAmount(),
'amount' => $this->getAmountInteger(),
];

return $data;
Expand Down
4 changes: 2 additions & 2 deletions tests/Message/AuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AuthorizeRequestTest extends AbstractRequestTest
/**
* Amount to pay
*
* @var string
* @var float
*/
protected $amount;

Expand Down Expand Up @@ -45,7 +45,7 @@ class AuthorizeRequestTest extends AbstractRequestTest
*/
public function setUp()
{
$this->amount = strval(random_int(1000, 100000)/100);
$this->amount = mt_rand(1, 100);
$this->returnUrl = 'https://test.com/' . uniqid('', true);
$this->orderNumber = uniqid('order_number_', true);
$this->currency = 'RUB';
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/CaptureRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CaptureRequestTest extends AbstractRequestTest
*/
public function setUp()
{
$this->amount = strval(random_int(1000, 100000)/100);
$this->amount = random_int(1000, 100000);

parent::setUp();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/RefundRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RefundRequestTest extends AbstractRequestTest
public function setUp()
{
$this->orderId = mt_rand(1, 100);
$this->amount = strval(random_int(1000, 100000)/100);
$this->amount = mt_rand(1, 100500);

parent::setUp();
}
Expand Down

0 comments on commit 6301b3e

Please sign in to comment.