Skip to content

Commit

Permalink
version 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vhar committed Jan 31, 2023
1 parent d3bfcdc commit baa784f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 39 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 1.0.1

1. request method changed to POST
2. test_mode configuration variable renamed to testMode
3. added sslVerify configuration variable.
>This allows you to disable ssl validation (don't do this!) or use a custom SSL certificate from file system
## 0.1.3

Optimize registerOrder input patam processing
Expand Down
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ composer require vhar/sberbank
```php
<?php

use GuzzleHttp\Client;
use VHar\Sberbank\SBClient;

$config = [
'shopLogin' => 'ваш-api-логин',
'shopPassword' => 'ваш-api-пароль',
'test_mode' => 0, // 0 - production, 1 - test
'testMode' => 0, // 0 - production, 1 - test
'sslVerify' => 1 // 0 - игнорировать ошибки SSL сертификата (не делайте так!), 1 - проверять SSL сертификат (по умолчанию), '/path/to/cert.pem' - использовать пользовательский сертификат для проверки
];

$http_client = new Client();
$sber = new SBClient($config, $http_client);
$sber = new SBClient($config);

/**
* В примере показаны только обязательные поля.
Expand Down Expand Up @@ -57,17 +56,16 @@ if (isset($response->errorCode) && $response->errorMessage) {
```php
<?php

use GuzzleHttp\Client;
use VHar\Sberbank\SBClient;

$config = [
'shopLogin' => 'ваш-api-логин',
'shopPassword' => 'ваш-api-пароль',
'test_mode' => 0, // 0 - production, 1 - test
'testMode' => 0, // 0 - production, 1 - test
'sslVerify' => 1 // 0 - игнорировать ошибки SSL сертификата (не делайте так!), 1 - проверять SSL сертификат (по умолчанию), '/path/to/cert.pem' - использовать пользовательский сертификат для проверки
];

$http_client = new Client();
$sber = new SBClient($config, $http_client);
$sber = new SBClient($config);

/**
* В примере показано только обязательное поле.
Expand Down Expand Up @@ -97,17 +95,16 @@ if (isset($response->errorCode) && $response->errorCode) {
```php
<?php

use GuzzleHttp\Client;
use VHar\Sberbank\SBClient;

$config = [
'shopLogin' => 'ваш-api-логин',
'shopPassword' => 'ваш-api-пароль',
'test_mode' => 0, // 0 - production, 1 - test
'testMode' => 0, // 0 - production, 1 - test
'sslVerify' => 1 // 0 - игнорировать ошибки SSL сертификата (не делайте так!), 1 - проверять SSL сертификат (по умолчанию), '/path/to/cert.pem' - использовать пользовательский сертификат для проверки
];

$http_client = new Client();
$sber = new SBClient($config, $http_client);
$sber = new SBClient($config);

/**
* см. https://securepayments.sberbank.ru/wiki/doku.php/integration:api:rest:requests:refund
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vhar/sberbank",
"description": "Simple PHP client for Sperbank acquiring REST API",
"version": "0.1.3",
"version": "1.0.1",
"type": "library",
"keywords": ["sberbank", "sberbank online", "credit card", "sberbank acquiring"],
"require": {
Expand Down
86 changes: 60 additions & 26 deletions src/SBClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
*
* @package vhar\sberbank
* @author Vladimir Kharinenkov <vhar@mail.ru>
* @version 0.1.3
* @version 1.0.1
*
*/

namespace VHar\Sberbank;

use ErrorException;
use GuzzleHttp\Client;

/**
* Class SBClient for working with Sberbank REST API.
Expand All @@ -31,18 +30,36 @@ class SBClient
*/
const API_TEST_URL = 'https://3dsec.sberbank.ru';

/**
* Basic request options
* @var array
*/
private $config;

/**
* Http Client
* @var Client
*/
private $client;

/**
* Shop login for REST API access
* @var string
*/
private $shopLogin;

/**
* Shop password for REST API access
* @var string
*/
private $shopPassword;

/**
* use test or production payment gateway
* @var int
*/
private $testMode;

/**
* SSL certificate validation
* @var mixed
*/
private $sslVerify;

/**
* Clients accept an array of constructor parameters.
*
Expand All @@ -53,28 +70,45 @@ class SBClient
* - shopPassword: (string) Shop password for REST API access
*
* Additional option:
* - test_mode: (int)
* - sslVerify: mixed
* <ul>0 - Disable validation entirely (don't do this!)</ul>
* <ul>1 - Use the system's CA bundle (this is the default setting)</ul>
* <ul>'/path/to/cert.pem' - Use a custom SSL certificate on disk</ul>
* - testMode: (int)
* <ul>0 - production payment gateway.</ul>
* <ul>1 - test payment gateway</ul>
* <b>default is 0</b>
*
* @param Client $client GuzzleHttp\Client used to send the requests.
*/

public function __construct(array $config = [], Client $client)
public function __construct(array $config = [])
{
$this->client = $client ?? new GuzzleHttp\Client();

$this->shopLogin = $config['shopLogin'] ?? null;

if (!$this->shopLogin) {
throw new ErrorException('Please provide shopLogin');
}

$this->shopPassword = $config['shopPassword'] ?? null;

if (!$this->shopPassword) {
throw new ErrorException('Please provide shopPassword');
}

$this->test_mode = $config['test_mode'] ?? 0;
$this->testMode = $config['testMode'] ?? 0;

$this->sslVerify = true;

if (isset($config['sslVerify'])) {
if ($config['sslVerify'] === 0) {
$this->sslVerify = false;
} elseif (is_file($config['sslVerify'])) {
$this->sslVerify = $config['sslVerify'];
}
}

$this->client = new \GuzzleHttp\Client([
'base_uri' => $this->getApiUrl(),
'verify' => $this->sslVerify,
]);
}

/**
Expand Down Expand Up @@ -109,7 +143,7 @@ public function __construct(array $config = [], Client $client)
*/
public function registerOrder($order)
{
$url = $this->getApiUrl() . '/payment/rest/register.do?%s';
$url = '/payment/rest/register.do?%s';

if (!$order['orderNumber']) {
throw new ErrorException('Please provide orderNumber');
Expand Down Expand Up @@ -143,7 +177,7 @@ public function registerOrder($order)
}

$request = sprintf($url, http_build_query($params));
$response = $this->client->request('GET', $request);
$response = $this->client->request('POST', $request);

return json_decode($response->getBody());
}
Expand Down Expand Up @@ -181,7 +215,7 @@ public function registerOrder($order)
*/
public function getOrderStatusExtended($order)
{
$url = $this->getApiUrl() . '/payment/rest/getOrderStatusExtended.do?%s';
$url = '/payment/rest/getOrderStatusExtended.do?%s';

if (!isset($order['orderNumber']) && !isset($order['orderId'])) {
throw new ErrorException('Please provide orderId OR orderNumber');
Expand All @@ -201,7 +235,7 @@ public function getOrderStatusExtended($order)
if (isset($order['language'])) $params['language'] = $order['language'];

$request = sprintf($url, http_build_query($params));
$response = $this->client->request('GET', $request);
$response = $this->client->request('POST', $request);

return json_decode($response->getBody());
}
Expand Down Expand Up @@ -240,7 +274,7 @@ public function getOrderStatusExtended($order)
*/
public function reverseOrder($order)
{
$url = $this->getApiUrl() . '/payment/rest/reverse.do?%s';
$url = '/payment/rest/reverse.do?%s';

if (!$order['amount']) {
throw new ErrorException('Please provide amount');
Expand All @@ -267,7 +301,7 @@ public function reverseOrder($order)
}

$request = sprintf($url, http_build_query($params));
$response = $this->client->request('GET', $request);
$response = $this->client->request('POST', $request);

return json_decode($response->getBody());
}
Expand Down Expand Up @@ -302,7 +336,7 @@ public function reverseOrder($order)
*/
public function refundOrder($order)
{
$url = $this->getApiUrl() . '/payment/rest/refund.do?%s';
$url = '/payment/rest/refund.do?%s';

if (!$order['amount']) {
throw new ErrorException('Please provide amount');
Expand All @@ -328,19 +362,19 @@ public function refundOrder($order)
}

$request = sprintf($url, http_build_query($params));
$response = $this->client->request('GET', $request);
$response = $this->client->request('POST', $request);

return json_decode($response->getBody());
}

/**
* Get API URL based on test_mode $config option
* Get API URL based on testMode $config option
*
* @return string Production or Test REST API URL
*/
private function getApiUrl()
{
if ($this->test_mode) {
if ($this->testMode) {
return self::API_TEST_URL;
} else {
return self::API_PROD_URL;
Expand Down

0 comments on commit baa784f

Please sign in to comment.