Skip to content

Commit

Permalink
Merge branch 'fix_refund' into fix_tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Message/AbstractRequest.php
  • Loading branch information
Novikov Andrey committed Jan 22, 2019
2 parents 92648ff + 6301b3e commit db22e58
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 19 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
17 changes: 12 additions & 5 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,19 @@ public function sendData($data)
{
$url = $this->getEndPoint() . $this->getMethod();
$this->validate('userName', 'password');
$data = array_merge(
[
'userName' => $this->getUserName(),
'password' => $this->getPassword(),
],
$data
);

$httpResponse = $this->httpClient->request(
$this->getHttpMethod(),
$url,
$this->getHeaders(),
json_encode(array_merge([
'userName' => $this->getUserName(),
'password' => $this->getPassword()
], $data))
http_build_query($data, '', '&')
);

$responseClassName = str_replace('Request', 'Response', \get_class($this));
Expand All @@ -173,7 +178,9 @@ public function sendData($data)
);
}

return $reflection->newInstance($this, json_decode($httpResponse->getBody(), true));
$content = json_decode($httpResponse->getBody()->getContents(), true);

return $reflection->newInstance($this, $content);
}

/**
Expand Down
17 changes: 12 additions & 5 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,19 @@ public function sendData($data)
$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(),
json_encode(array_merge([
'userName' => $this->getUserName(),
'password' => $this->getPassword()
], $data))
http_build_query($data, '', '&')
);

$responseClassName = str_replace('Request', 'Response', \get_class($this));
Expand All @@ -259,6 +264,8 @@ public function sendData($data)
);
}

return $reflection->newInstance($this, json_decode($httpResponse->getBody(true), true));
$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: 3 additions & 1 deletion tests/Message/CaptureRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ protected function getRequestParameters()
*/
public function testData()
{
$this->assertEquals($this->request->getData(), $this->getRequestParameters());
$params = $this->getRequestParameters();
$params['amount'] = $params['amount'] * 100;
$this->assertEquals($this->request->getData(), $params);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/Message/RefundRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public function getMethod()
*/
public function testData()
{
$this->assertEquals($this->request->getData(), $this->getRequestParameters());
$params = $this->getRequestParameters();
$params['amount'] = $params['amount'] * 100;
$this->assertEquals($this->request->getData(), $params);
}

/**
Expand Down

0 comments on commit db22e58

Please sign in to comment.