Skip to content

Commit

Permalink
fix declare and getToken and connect client
Browse files Browse the repository at this point in the history
  • Loading branch information
remils committed Sep 20, 2019
1 parent 424c378 commit 21e5798
Show file tree
Hide file tree
Showing 39 changed files with 99 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/Data/CancelData.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SergeyZatulivetrov\TinkoffAcquiring\Data;

use SergeyZatulivetrov\TinkoffAcquiring\Data\Traits\Amount;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/ConfirmData.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SergeyZatulivetrov\TinkoffAcquiring\Data;

use SergeyZatulivetrov\TinkoffAcquiring\Data\Traits\Amount;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/GetStateData.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SergeyZatulivetrov\TinkoffAcquiring\Data;

use SergeyZatulivetrov\TinkoffAcquiring\Data\Traits\Amount;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/InitData.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SergeyZatulivetrov\TinkoffAcquiring\Data;

use SergeyZatulivetrov\TinkoffAcquiring\Data\Traits\Amount;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/ItemsData.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SergeyZatulivetrov\TinkoffAcquiring\Data;

use SergeyZatulivetrov\TinkoffAcquiring\Data\Traits\Amount;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/ReceiptData.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SergeyZatulivetrov\TinkoffAcquiring\Data;

use SergeyZatulivetrov\TinkoffAcquiring\Data\Traits\BaseData;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/ResendData.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SergeyZatulivetrov\TinkoffAcquiring\Data;

use SergeyZatulivetrov\TinkoffAcquiring\Data\Traits\BaseData;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Amount.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Сумма в копейках.
* Параметр "Amount" должен быть равен сумме всех параметров "Amount", переданных в объекте Items.
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/BaseData.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace SergeyZatulivetrov\TinkoffAcquiring\Data\Traits;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/CustomerKey.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Идентификатор покупателя в системе Продавца. Если передается, для данного
* покупателя будет осуществлена привязка карты к данному идентификатору клиента
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/DATA.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* JSON объект, содержащий дополнительные параметры в виде “ключ”:”значение”. Данные параметры
* будут переданы на страницу оплаты (в случае ее кастомизации). Максимальная длина для каждого
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Description.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Краткое описание
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Ean13.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Штрих-код
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Email.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Электронный адрес для отправки чека покупателю. Поле обязательно, если не передан параметр Phone
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/EmailCompany.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Электронная почта отправителя чека. Максимальная длина строки – 64 символа
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/FailURL.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* URL на веб-сайте продавца, куда будет переведен покупатель в случае неуспешной оплаты
* (настраивается в Личном кабинете).
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/IP.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* IP-адрес клиента
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Items.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Массив, содержащий в себе информацию о товарах
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Language.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Язык платёжной формы.
* ru - форма оплаты на русском языке;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Name.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Наименование товара. Максимальная длина строки – 128 символа
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/NotificationURL.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* URL на веб-сайте продавца, куда будет отправлен POST запрос о статусе выполнения вызываемых
* методов (настраивается в Личном кабинете).
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/OrderId.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Номер заказа в системе Продавца
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/PayType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Определяет тип проведения платежа - двухстадийная или одностадийная оплата.
* "О" - одностадийная оплата;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/PaymentId.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Уникальный идентификатор транзакции в системе Банка
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/PaymentMethod.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Признак способа расчёта. Если значение не передано, по умолчанию в онлайн-кассу передается признак способа расчёта "full_payment".
* Возможные значения:
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/PaymentObject.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Признак предмета расчёта.Если значение не передано, по умолчанию в онлайн-кассу отправляется признак
* предмета расчёта "commodity".
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Phone.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Телефон покупателя. Поле обязательно, если не передан параметр Email
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Price.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Цена в копейках. *Целочисленное значение не более 10 знаков
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Quantity.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Количество/вес:
* целая часть не более 8 знаков;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Receipt.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* JSON объект с данными чека
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Recurrent.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Если передается и установлен в Y, регистрирует платёж как рекуррентный. В этом
* случае после оплаты в нотификации на AUTHORIZED будет передан параметр RebillId
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/RedirectDueDate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Cрок жизни ссылки. Eсли текущая дата превышает дату переданную в данном параметре, ссылка
* для оплаты становится недоступной и платёж выполнить нельзя.
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/ShopCode.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Код магазина
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/SuccessURL.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* URL на веб-сайте продавца, куда будет переведен покупатель в случае успешной оплаты
* (настраивается в Личном кабинете).
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Tax.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Ставка налога. Перечисление со значениями:
* «none» – без НДС;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/Taxation.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Система налогообложения. Перечисление со значениями:
* «osn» – общая СН;
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Traits/TerminalKey.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Идентификатор терминала, выдается Продавцу Банком
*/
Expand Down
18 changes: 15 additions & 3 deletions src/Data/Traits/Token.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Подпись запроса. Алгоритм формирования подписи описан в разделе
* "Подпись запросов"
Expand All @@ -19,13 +21,23 @@ trait Token
private $data = [];

/**
* @param $token
* @param $password
*
* @return $this
*/
public function setToken($token)
public function setToken($password)
{
$this->data['Token'] = $token;
$data = $this->data;
unset($data['Receipt'], $data['DATA']);
$data['Password'] = $password;
ksort($data);

$token = '';
foreach ($data as $value) {
$token .= $value;
}

$this->data['Token'] = hash('sha256', $token);

return $this;
}
Expand Down
25 changes: 10 additions & 15 deletions src/Traits/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,16 @@ private function execute($action, $data = [])

$headers['Content-Type'] = 'application/json';

$data = \json_encode($data);

$status = 500;
$response = [];
try {
$client = new Client();
$res = $client->request(
$this->HTTP_METHOD, $apiURL, [
'headers' => $headers,
'body' => $data,
]);
$status = $res->getStatusCode();
$response = json_decode($res->getBody()->getContents(), true);
} catch (\Exception $exception) {
}
$data = \json_encode($data, JSON_FORCE_OBJECT);

$client = new Client();
$res = $client->request(
$this->HTTP_METHOD, $apiURL, [
'headers' => $headers,
'body' => $data,
]);
$status = $res->getStatusCode();
$response = json_decode($res->getBody()->getContents(), true);

return [
'status' => $status,
Expand Down

0 comments on commit 21e5798

Please sign in to comment.