Skip to content

Commit c0eeabd

Browse files
author
Andrey Helldar
authored
Merge pull request #2 from andrey-helldar/refactoring
Refactoring
2 parents 4762a27 + 528e301 commit c0eeabd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1469
-335
lines changed

.codecov.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
comment: off

.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CASHIER_SBER_QR_CLIENT_ID=
2+
CASHIER_SBER_QR_CLIENT_SECRET=
3+
CASHIER_SBER_QR_MEMBER_ID=

.gitattributes

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
* text=auto
2+
3+
.github/ export-ignore
4+
.run/ export-ignore
5+
6+
docs/ export-ignore
7+
tests/ export-ignore
8+
9+
.codecov.yml export-ignore
10+
.gitattributes export-ignore
11+
.gitignore export-ignore
12+
.styleci.yml export-ignore
13+
14+
phpunit.php export-ignore
15+
phpunit.yml export-ignore

.github/workflows/coverage.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: coverage
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- coverage
7+
8+
jobs:
9+
scrutinizer:
10+
runs-on: ubuntu-20.04
11+
12+
name: Coverage
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: 7.4
22+
extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv, bcmath
23+
coverage: xdebug
24+
25+
- name: Store environment variables
26+
run: |
27+
echo "CASHIER_SBER_QR_CLIENT_ID=${{ secrets.CASHIER_SBER_QR_CLIENT_ID }}" >> .env
28+
echo "CASHIER_SBER_QR_CLIENT_SECRET=${{ secrets.CASHIER_SBER_QR_CLIENT_SECRET }}" >> .env
29+
echo "CASHIER_SBER_QR_MEMBER_ID=${{ secrets.CASHIER_SBER_QR_MEMBER_ID }}" >> .env
30+
31+
- name: Install dependencies
32+
run: composer update --prefer-stable --prefer-dist --no-progress --no-interaction
33+
34+
- name: Execute tests
35+
run: |
36+
mkdir -p build/logs
37+
sudo vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
38+
39+
- name: Export
40+
run: |
41+
wget https://scrutinizer-ci.com/ocular.phar
42+
sudo php ocular.phar code-coverage:upload --format=php-clover coverage.clover

.github/workflows/phpunit.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: phpunit
2+
on: [ push ]
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-20.04
7+
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
php: [ "7.3", "7.4", "8.0" ]
12+
laravel: [ "6.0", "7.0", "8.0" ]
13+
14+
name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
20+
- name: Setup PHP
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php }}
24+
extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv, bcmath
25+
coverage: none
26+
27+
- name: Store environment variables
28+
run: |
29+
echo "CASHIER_SBER_QR_CLIENT_ID=${{ secrets.CASHIER_SBER_QR_CLIENT_ID }}" >> .env
30+
echo "CASHIER_SBER_QR_CLIENT_SECRET=${{ secrets.CASHIER_SBER_QR_CLIENT_SECRET }}" >> .env
31+
echo "CASHIER_SBER_QR_MEMBER_ID=${{ secrets.CASHIER_SBER_QR_MEMBER_ID }}" >> .env
32+
33+
- name: Install dependencies
34+
run: composer require laravel/framework:^${{ matrix.laravel }} --prefer-stable --prefer-dist --no-progress --no-interaction
35+
36+
- name: Execute tests
37+
run: sudo vendor/bin/phpunit

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
node_modules/
44
vendor/
55

6+
.env
7+
68
*.bak
79
*.cache
810
*.clover

.styleci.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
preset: psr12
2+
3+
risky: true
4+
5+
enabled:
6+
- align_double_arrow
7+
- align_equals
8+
- align_phpdoc
9+
- alpha_ordered_imports
10+
- binary_operator_spaces
11+
- blank_line_before_continue
12+
- blank_line_before_declare
13+
- blank_line_before_return
14+
- blank_line_before_throw
15+
- blank_line_before_try
16+
- cast_spaces
17+
- combine_consecutive_issets
18+
- const_separation
19+
- dir_constant
20+
- fully_qualified_strict_types
21+
- logical_operators
22+
- method_separation
23+
- no_alias_functions
24+
- no_blank_lines_after_phpdoc
25+
- no_blank_lines_between_traits
26+
- no_empty_comment
27+
- no_empty_phpdoc
28+
- no_extra_block_blank_lines
29+
- no_extra_consecutive_blank_lines
30+
- no_short_bool_cast
31+
- no_trailing_comma_in_singleline_array
32+
- no_unneeded_control_parentheses
33+
- no_unused_imports
34+
- ordered_class_elements
35+
- php_unit_construct
36+
- php_unit_fqcn_annotation
37+
- phpdoc_indent
38+
- phpdoc_inline_tag
39+
- phpdoc_link_to_see
40+
- phpdoc_no_access
41+
- phpdoc_no_empty_return
42+
- phpdoc_no_package
43+
- phpdoc_no_useless_inheritdoc
44+
- phpdoc_order
45+
- phpdoc_property
46+
- phpdoc_return_self_reference
47+
- phpdoc_scalar
48+
- phpdoc_separation
49+
- phpdoc_summary
50+
- phpdoc_to_comment
51+
- phpdoc_trim
52+
- phpdoc_type_to_var
53+
- phpdoc_types
54+
- phpdoc_types_order
55+
- phpdoc_var_without_name
56+
- property_separation
57+
- self_accessor
58+
- short_array_syntax
59+
- short_list_syntax
60+
- single_line_class_definition
61+
- single_line_throw
62+
- single_quote
63+
- space_after_semicolon
64+
- standardize_not_equals
65+
- ternary_to_null_coalescing
66+
- trailing_comma_in_multiline_array
67+
- trim_array_spaces

README.md

+30-22
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,49 @@ Or manually update `require` block of `composer.json` and run `composer update`.
2828
## Using
2929

3030
```php
31-
namespace Helldar\CashierDriver\Sber\QrCode;
31+
namespace Helldar\CashierDriver\Sber\QrCode\Requests;
3232

33-
use Helldar\Cashier\Services\Driver as BaseDriver;
34-
use Helldar\CashierDriver\Sber\Auth\DTO\Client;
35-
use Helldar\CashierDriver\Sber\Auth\Facades\Auth;
33+
use Helldar\Cashier\Http\Request;
34+
use Helldar\CashierDriver\Sber\Auth\Auth;
3635

37-
class Driver extends BaseDriver
36+
class Init extends Request
3837
{
39-
protected function headers(string $scope): array
38+
protected $production_host = 'https://api.sberbank.ru';
39+
40+
protected $dev_host = 'https://dev.api.sberbank.ru';
41+
42+
protected $path = '/ru/prod/creation';
43+
44+
protected $auth = Auth::class;
45+
46+
public function getRawBody(): array
4047
{
4148
return [
42-
'Authorization' => 'Bearer ' . $this->accessToken($scope),
49+
'OrderId' => $this->model->getPaymentId(),
4350

44-
'X-IBM-Client-Id' => $this->auth->getClientId(),
51+
'Amount' => $this->model->getSum(),
4552

46-
'x-Introspect-RqUID' => $this->resource->getUniqueId(),
53+
'Currency' => $this->model->getCurrency(),
4754
];
4855
}
56+
}
57+
```
4958

50-
protected function accessToken(string $scope): string
51-
{
52-
$auth = $this->authDto($scope);
59+
```php
60+
namespace Helldar\CashierDriver\Sber\QrCode;
5361

54-
return Auth::accessToken($auth);
55-
}
62+
use Helldar\CashierDriver\Sber\Auth\Support\Auth;
63+
use Helldar\CashierDriver\Sber\QrCode\Driver as BaseDriver;
64+
use Helldar\CashierDriver\Sber\QrCode\Requests\Init;
65+
use Helldar\Contracts\Cashier\Resources\Response;
5666

57-
protected function authDto(string $scope): Client
67+
class Driver extends BaseDriver
68+
{
69+
public function start(): Response
5870
{
59-
return Client::make()
60-
->scope($scope)
61-
->host($this->host())
62-
->clientId($this->auth->getClientId())
63-
->clientSecret($this->auth->getClientSecret())
64-
->memberId($this->resource->getMemberId())
65-
->paymentId($this->resource->getPaymentId());
71+
$request = Init::make($this->model);
72+
73+
return $this->request($request, Response::class);
6674
}
6775
}
6876
```

composer.json

+13-7
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,29 @@
2323
"source": "https://github.com/andrey-helldar/cashier-sber-auth"
2424
},
2525
"require": {
26-
"php": "^7.2.5|^8.0",
26+
"php": "^7.3|^8.0",
2727
"ext-json": "*",
28-
"andrey-helldar/contracts": "dev-main",
28+
"andrey-helldar/contracts": "^1.9",
29+
"andrey-helldar/simple-data-transfer-object": "^1.0",
2930
"andrey-helldar/support": "^4.0",
30-
"illuminate/support": "^6.0|^7.0|^8.0",
31-
"nesbot/carbon": "^2.0",
32-
"psr/http-message": "^1.0"
31+
"illuminate/support": "^6.0|^7.0|^8.0"
3332
},
3433
"require-dev": {
35-
"andrey-helldar/cashier": "^1.0",
36-
"symfony/var-dumper": "^5.0"
34+
"andrey-helldar/cashier": "^1.1",
35+
"orchestra/testbench": "^4.0|^5.0|^6.0",
36+
"phpunit/phpunit": "^9.0",
37+
"symfony/var-dumper": "^4.3.4|^5.0"
3738
},
3839
"autoload": {
3940
"psr-4": {
4041
"Helldar\\CashierDriver\\Sber\\Auth\\": "src"
4142
}
4243
},
44+
"autoload-dev": {
45+
"psr-4": {
46+
"Tests\\": "tests"
47+
}
48+
},
4349
"config": {
4450
"preferred-install": "dist",
4551
"sort-packages": true

phpunit.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the "andrey-helldar/cashier-sber-auth" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
*
11+
* @copyright 2021 Andrey Helldar
12+
*
13+
* @license MIT
14+
*
15+
* @see https://github.com/andrey-helldar/cashier-sber-auth
16+
*/
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Register The Composer Auto Loader
21+
|--------------------------------------------------------------------------
22+
|
23+
| Composer provides a convenient, automatically generated class loader
24+
| for our application. We just need to utilize it! We'll require it
25+
| into the script here so that we do not have to worry about the
26+
| loading of any our classes "manually". Feels great to relax.
27+
|
28+
*/
29+
30+
require __DIR__ . '/vendor/autoload.php';
31+
32+
/*
33+
|--------------------------------------------------------------------------
34+
| Set The Default Timezone
35+
|--------------------------------------------------------------------------
36+
|
37+
| Here we will set the default timezone for PHP. PHP is notoriously mean
38+
| if the timezone is not explicitly set. This will be used by each of
39+
| the PHP date and date-time functions throughout the application.
40+
|
41+
*/
42+
43+
date_default_timezone_set('UTC');

phpunit.xml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
~ This file is part of the "andrey-helldar/cashier-sber-auth" project.
5+
~
6+
~ For the full copyright and license information, please view the LICENSE
7+
~ file that was distributed with this source code.
8+
~
9+
~ @author Andrey Helldar <[email protected]>
10+
~
11+
~ @copyright 2021 Andrey Helldar
12+
~
13+
~ @license MIT
14+
~
15+
~ @see https://github.com/andrey-helldar/cashier-sber-auth
16+
-->
17+
18+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
20+
backupGlobals="false"
21+
backupStaticAttributes="false"
22+
bootstrap="phpunit.php"
23+
colors="true"
24+
convertErrorsToExceptions="true"
25+
convertNoticesToExceptions="true"
26+
convertWarningsToExceptions="true"
27+
processIsolation="false"
28+
stopOnError="false"
29+
stopOnFailure="false"
30+
verbose="true"
31+
>
32+
<coverage processUncoveredFiles="true">
33+
<include>
34+
<directory suffix=".php">./src</directory>
35+
</include>
36+
<report>
37+
<clover outputFile="build/logs/clover.xml"/>
38+
<html outputDirectory="build/logs/coverage"/>
39+
<text outputFile="build/logs/coverage.txt"/>
40+
</report>
41+
</coverage>
42+
<testsuites>
43+
<testsuite name="Test Suite">
44+
<directory suffix="Test.php">./tests</directory>
45+
</testsuite>
46+
</testsuites>
47+
</phpunit>

0 commit comments

Comments
 (0)