diff --git a/README.md b/README.md index d1a8e3d..e1106b6 100644 --- a/README.md +++ b/README.md @@ -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 ] ); @@ -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' ] @@ -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' ] @@ -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') diff --git a/composer.json b/composer.json index 428b6d1..5995210 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ }, "autoload-dev": { "psr-4": { - "Tests\\Examples\\": "tests/Examples" + "Omnipay\\Sberbank\\Tests\\": "tests/" } }, "minimum-stability": "dev", diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index d04af12..415ab03 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -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)); @@ -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); } /** diff --git a/src/Message/AuthorizeRequest.php b/src/Message/AuthorizeRequest.php index 57ef5dc..0f7e5c0 100644 --- a/src/Message/AuthorizeRequest.php +++ b/src/Message/AuthorizeRequest.php @@ -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)); @@ -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); } } diff --git a/src/Message/CaptureRequest.php b/src/Message/CaptureRequest.php index f1b128e..60bbb6d 100644 --- a/src/Message/CaptureRequest.php +++ b/src/Message/CaptureRequest.php @@ -18,7 +18,7 @@ public function getData() $data = [ 'orderId' => $this->getOrderId(), - 'amount' => $this->getAmount(), + 'amount' => $this->getAmountInteger(), ]; return $data; diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php index 7b68c60..1eddf09 100644 --- a/src/Message/RefundRequest.php +++ b/src/Message/RefundRequest.php @@ -18,7 +18,7 @@ public function getData() $data = [ 'orderId' => $this->getOrderId(), - 'amount' => $this->getAmount(), + 'amount' => $this->getAmountInteger(), ]; return $data; diff --git a/tests/Message/CaptureRequestTest.php b/tests/Message/CaptureRequestTest.php index 6096525..444096e 100644 --- a/tests/Message/CaptureRequestTest.php +++ b/tests/Message/CaptureRequestTest.php @@ -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); } /** diff --git a/tests/Message/RefundRequestTest.php b/tests/Message/RefundRequestTest.php index 19e922c..2c23980 100644 --- a/tests/Message/RefundRequestTest.php +++ b/tests/Message/RefundRequestTest.php @@ -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); } /**