Skip to content

Commit

Permalink
Merge branch 'update_readme' into fix_refund
Browse files Browse the repository at this point in the history
  • Loading branch information
Novikov Andrey committed Jan 22, 2019
2 parents bd63aae + 5a03cb3 commit c9ce0b6
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 51 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ $gateway = Omnipay::create('Sberbank');
$gateway->authorize(
[
'orderNumber' => $localOrderNumber, // local order number
'amount' => $order_amount * 100, // The amount of payment in kopecks (or cents)
'amount' => $order_amount, // The amount of payment (you can use integer, decimal with 2 precisions or string equal to decimal
'returnUrl' => $callback_url // succesfull callback url
]
);
Expand Down Expand Up @@ -113,7 +113,7 @@ $gateway = Omnipay::create('Sberbank');
$response = $gateway->authorize(
[
'orderNumber' => $localOrderNumber, // local order number
'amount' => $order_amount * 100, // The amount of payment in kopecks (or cents)
'amount' => $order_amount, // The amount of payment (you can use integer, decimal with 2 precisions or string equal to decimal
'returnUrl' => $callback_url, // succesfull callback url
'description' => 'Order Description'
]
Expand Down Expand Up @@ -161,7 +161,7 @@ $gateway = Omnipay::create('Sberbank');
$response = $gateway->authorize(
[
'orderNumber' => $localOrderNumber, // local order number
'amount' => $order_amount * 100, // The amount of payment in kopecks (or cents)
'amount' => $order_amount, // The amount of payment (you can use integer, decimal with 2 precisions or string equal to decimal
'returnUrl' => $callback_url, // succesfull callback url
'description' => 'Order Description'
]
Expand Down Expand Up @@ -210,7 +210,7 @@ $gateway = Omnipay::create('Sberbank');
$response = $gateway->capture(
[
'orderId' => $localOrderNumber, // gateway order number
'amount' => $order_amount * 100, // The amount of payment in kopecks (or cents)
'amount' => $order_amount, // The amount of payment (you can use integer, decimal with 2 precisions or string equal to decimal
]
)->setUserName('merchant_login')
->setPassword('merchant_password')
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\Examples\\": "tests/Examples"
"Omnipay\\Sberbank\\Tests\\": "tests/"
}
},
"minimum-stability": "dev",
Expand Down
6 changes: 6 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ 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: 0 additions & 40 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,44 +228,4 @@ 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->getAmountInteger(),
'amount' => $this->getAmount(),
];

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->getAmountInteger(),
'amount' => $this->getAmount(),
];

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 float
* @var string
*/
protected $amount;

Expand Down Expand Up @@ -45,7 +45,7 @@ class AuthorizeRequestTest extends AbstractRequestTest
*/
public function setUp()
{
$this->amount = mt_rand(1, 100);
$this->amount = strval(random_int(1000, 100000)/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 = random_int(1000, 100000);
$this->amount = strval(random_int(1000, 100000)/100);

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 = mt_rand(1, 100500);
$this->amount = strval(random_int(1000, 100000)/100);

parent::setUp();
}
Expand Down

0 comments on commit c9ce0b6

Please sign in to comment.