Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,46 @@ on:
pull_request:

jobs:
phpunit:
name: PHPUnit (PHP ${{ matrix.php-version }})
checks:
name: ${{ matrix.name }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-version:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
- '8.5'
include:
- name: PHPUnit (PHP 8.1)
php-version: '8.1'
command: composer test
tool: ''
- name: PHPUnit (PHP 8.2)
php-version: '8.2'
command: composer test
tool: ''
- name: PHPUnit (PHP 8.3)
php-version: '8.3'
command: composer test
tool: ''
- name: PHPUnit (PHP 8.4)
php-version: '8.4'
command: composer test
tool: ''
- name: PHPUnit (PHP 8.5)
php-version: '8.5'
command: composer test
tool: ''
- name: PHPStan
php-version: '8.3'
command: make phpstan
tool: phpstan
- name: Rector
php-version: '8.3'
command: make rector
tool: rector
- name: PHP CS Fixer
php-version: '8.3'
command: make lint
tool: php-cs-fixer

steps:
- name: Checkout
Expand All @@ -36,5 +63,9 @@ jobs:
- name: Install dependencies
run: composer update --prefer-dist --no-progress --no-interaction

- name: Run tests
run: composer test
- name: Install tool dependencies
if: ${{ matrix.tool != '' }}
run: composer bin ${{ matrix.tool }} install --no-progress --no-interaction

- name: Run ${{ matrix.name }}
run: ${{ matrix.command }}
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ lint: vendor ## Проверить PHP code style при помощи PHP CS Fix
$(EXEC_PHP) vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff --verbose
.PHONY: lint

rector: vendor ## Проверить PHP код при помощи Rector (https://getrector.com)
$(EXEC_PHP) vendor-bin/rector/vendor/bin/rector process --dry-run --no-progress-bar
.PHONY: rector

fixcs: vendor ## Исправить ошибки PHP code style при помощи PHP CS Fixer (https://github.com/FriendsOfPHP/PHP-CS-Fixer)
$(EXEC_PHP) vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer fix --diff --verbose
.PHONY: fixcs
Expand Down
342 changes: 241 additions & 101 deletions README.md

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/Hook/BaseHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
*/
class BaseHook
{
/**
* @param array<string, mixed> $request
*/
public function __construct(protected array $request)
{
$this->fill();
}

/**
* @return array<string, mixed>
*/
public function getRequest(): array
{
return $this->request;
Expand All @@ -25,7 +31,7 @@ private function fill(): void
$modelFields = get_object_vars($this);

foreach ($modelFields as $key => $field) {
$requestKey = ucfirst($key);
$requestKey = ucfirst((string) $key);

if (isset($this->request[$requestKey])) {
$this->$key = $this->request[$requestKey];
Expand Down
60 changes: 60 additions & 0 deletions src/Hook/HookReceipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,88 @@
*/
class HookReceipt extends BaseHook
{
/**
* @var int|string|null
*/
public $id;
/**
* @var int|string|null
*/
public $documentNumber;
/**
* @var int|string|null
*/
public $sessionNumber;
/**
* @var int|string|null
*/
public $number;
/**
* @var int|string|null
*/
public $fiscalSign;
/**
* @var string|null
*/
public $deviceNumber;
/**
* @var string|null
*/
public $regNumber;
/**
* @var string|null
*/
public $fiscalNumber;
/**
* @var string|null
*/
public $inn;
/**
* @var string|null
*/
public $type;
/**
* @var string|null
*/
public $ofd;
/**
* @var string|null
*/
public $url;
/**
* @var string|null
*/
public $qrCodeUrl;
/**
* @var int|null
*/
public $transactionId;
/**
* @var float|int|string|null
*/
public $amount;
/**
* @var string|null
*/
public $dateTime;
/**
* @var string|null
*/
public $invoiceId;
/**
* @var string|null
*/
public $accountId;
/**
* @var array<string, mixed>|string|null
*/
public $receipt;
/**
* @var string|null
*/
public $calculationPlace;
/**
* @var string|null
*/
public $settlePlace;
}
18 changes: 17 additions & 1 deletion src/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use Excent\Cloudpayments\Response\TransactionWith3dsResponse;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use JsonException;
use Psr\Http\Message\ResponseInterface;

/**
Expand Down Expand Up @@ -353,6 +354,16 @@ public function siteNotificationsUpdate(NotificationsUpdate $data): CloudRespons

/**
* Базовый запрос
*
* @template T of CloudResponse
*
* @param string|CloudMethodsEnum $method
* @param array<string, mixed> $postData
* @param T $cloudResponse
*
* @return T
* @throws GuzzleException
* @throws JsonException
*/
private function request(string|CloudMethodsEnum $method, array $postData, CloudResponse $cloudResponse): CloudResponse
{
Expand All @@ -361,13 +372,16 @@ private function request(string|CloudMethodsEnum $method, array $postData, Cloud
}

$response = $this->sendRequest($method, $postData);
$cloudResponse->fillByResponse($response);

return $cloudResponse->fillByResponse($response);
return $cloudResponse;
}

/**
* Запрос по api.
*
* @param array<string, mixed> $postData
*
* @throws GuzzleException
*/
public function sendRequest(string $method, array $postData = []): ResponseInterface
Expand All @@ -383,6 +397,8 @@ public function sendRequest(string $method, array $postData = []): ResponseInter

/**
* Генерирует request id для идемпотентных запросов.
*
* @param array<string, mixed> $postData
*/
public function getRequestId(string $method, array $postData): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Request/BaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function asArray(): array
$fields = get_object_vars($this);

foreach ($fields as $field => $value) {
$key = ucfirst($field);
$key = ucfirst((string) $field);

if ($value === true) {
$value = BoolField::TRUE->value;
Expand Down
3 changes: 3 additions & 0 deletions src/Request/CardsPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
class CardsPayment extends BaseRequest
{
/**
* @param array<string, mixed>|null $payer
*/
public function __construct(
public float|int $amount,
public string $currency,
Expand Down
6 changes: 6 additions & 0 deletions src/Request/CardsTopUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class CardsTopUp extends BaseRequest
public ?string $jsonData = null;
public ?string $invoiceId = null;
public ?string $description = null;
/**
* @var array<string, mixed>|null
*/
public ?array $payer = null;
/**
* @var array<string, mixed>|null
*/
public ?array $receiver = null;
}
5 changes: 3 additions & 2 deletions src/Request/OrderCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class OrderCreate extends BaseRequest
{
/**
* @var int|float
* @var int|float|string
*/
public $amount;
public ?string $email = null;
Expand All @@ -33,7 +33,8 @@ class OrderCreate extends BaseRequest
/**
* OrderCreate constructor.
*
* @param $amount
* @param int|float|string $amount
*
* @throws BadTypeException
*/
public function __construct($amount, public string $currency, public string $description)
Expand Down
7 changes: 4 additions & 3 deletions src/Request/PaymentsConfirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
class PaymentsConfirm extends BaseRequest
{
/**
* @var int|float
* @var int|float|string
*/
public $amount;
public ?string $jsonData = null;

/**
* PaymentsConfirm constructor.
*
* @param int|float $amount
* @param string|null $jsonData
* @param int|float|string $amount
* @param string|null $jsonData
*
* @throws BadTypeException
*/
public function __construct($amount, public int $transactionId, ?string $jsonData = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Request/Receipt/CustomerReceipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CustomerReceipt extends BaseRequest
* @param bool|null $isBso
* @param string|null $agentSign
* @param string|null $cashierName
* @param array|null $additionalReceiptInfos
* @param array<int|string, mixed>|null $additionalReceiptInfos
*/
public function __construct(
public array $items,
Expand Down
6 changes: 6 additions & 0 deletions src/Request/TokenTopUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class TokenTopUp extends BaseRequest
public string $accountId;
public string $currency;
public ?string $invoiceId = null;
/**
* @var array<string, mixed>|null
*/
public ?array $payer = null;
/**
* @var array<string, mixed>|null
*/
public ?array $receiver = null;
}
4 changes: 4 additions & 0 deletions src/Response/AppleSessionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Excent\Cloudpayments\Response;

use Excent\Cloudpayments\Response\Models\AppleSessionModel;
use stdClass;

/**
* Class NotificationResponse.
Expand All @@ -12,6 +13,9 @@ class AppleSessionResponse extends CloudResponse
/** @var AppleSessionModel */
public $model;

/**
* @param stdClass $modelDate
*/
public function fillModel($modelDate): void
{
$model = new AppleSessionModel();
Expand Down
Loading
Loading