Skip to content

Commit

Permalink
Merge pull request #9 from andrey-helldar/1.x
Browse files Browse the repository at this point in the history
[1.x] Correction of conducting refunds
  • Loading branch information
Andrey Helldar authored Oct 19, 2021
2 parents 1e5a310 + 8c8f3de commit c931c6d
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 122 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ on:

jobs:
scrutinizer:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

name: Coverage

services:
mysql:
image: mysql:8.0
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: default
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [ push ]

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

strategy:
fail-fast: true
Expand All @@ -15,7 +15,7 @@ jobs:

services:
mysql:
image: mysql:8.0
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: default
Expand Down
17 changes: 11 additions & 6 deletions src/Requests/BaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ public function getRawHeaders(): array
public function getHttpOptions(): array
{
if (Main::isProduction()) {
return [
'cert' => [
$this->model->getCertificatePath(),
$this->model->getCertificatePassword(),
],
];
$cert = $this->getCertificateData();

return compact('cert');
}

return [];
Expand All @@ -66,4 +63,12 @@ protected function currentTime(): string

return Date::toString($date);
}

protected function getCertificateData(): array
{
return [
$this->model->getCertificatePath(),
$this->model->getCertificatePassword(),
];
}
}
2 changes: 2 additions & 0 deletions src/Requests/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Cancel extends BaseRequest
Body::SCOPE => Scopes::CANCEL,
];

protected $reload_relations = true;

public function getRawBody(): array
{
return [
Expand Down
40 changes: 29 additions & 11 deletions tests/Concerns/Database.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
<?php

/*
* This file is part of the "andrey-helldar/cashier-sber-qr" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <helldar@ai-rus.com>
*
* @copyright 2021 Andrey Helldar
*
* @license MIT
*
* @see https://github.com/andrey-helldar/cashier-sber-qr
*/

declare(strict_types=1);

namespace Tests\Concerns;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\Fixtures\Factories\Payment;
use Tests\Fixtures\Models\RequestPayment;
use Tests\Fixtures\Models\ReadyPayment;
use Tests\TestCase;

trait Database
{
use RefreshDatabase;

protected $pre_payment = true;
/** @var \Illuminate\Database\Eloquent\Model|string */
protected $model = ReadyPayment::class;

protected function prePayment(): void
protected function payment(): Model
{
if ($this->pre_payment) {
$this->payment($this->pre_payment);
}
}
$model = $this->model;

protected function payment(bool $enabled_events = false): RequestPayment
{
return Payment::create($enabled_events)->refresh();
return $model::create([
'type_id' => TestCase::MODEL_TYPE_ID,
'status_id' => TestCase::MODEL_STATUS_ID,

'sum' => TestCase::PAYMENT_SUM,
'currency' => TestCase::CURRENCY,
]);
}
}
33 changes: 33 additions & 0 deletions tests/Concerns/TestServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the "andrey-helldar/cashier-sber-qr" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <helldar@ai-rus.com>
*
* @copyright 2021 Andrey Helldar
*
* @license MIT
*
* @see https://github.com/andrey-helldar/cashier-sber-qr
*/

declare(strict_types=1);

namespace Tests\Concerns;

use Helldar\Cashier\Providers\ServiceProvider;

class TestServiceProvider extends ServiceProvider
{
protected function bootMigrations(): void
{
$this->loadMigrationsFrom([
__DIR__ . '/../database/migrations',
__DIR__ . '/../../vendor/andrey-helldar/cashier/database/migrations/main',
]);
}
}
24 changes: 10 additions & 14 deletions tests/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Helldar\Contracts\Cashier\Driver as DriverContract;
use Helldar\Contracts\Cashier\Http\Response as ResponseContract;
use Helldar\Support\Facades\Http\Url;
use Illuminate\Database\Eloquent\Model;
use Tests\Fixtures\Models\RequestPayment;

class DriverTest extends TestCase
Expand All @@ -31,9 +32,9 @@ class DriverTest extends TestCase

public function testStart()
{
Jobs::make($this->payment())->start();
$payment = $this->payment();

$response = $this->driver()->start();
$response = $this->driver($payment)->start();

$this->assertInstanceOf(Response::class, $response);
$this->assertInstanceOf(ResponseContract::class, $response);
Expand All @@ -48,9 +49,11 @@ public function testStart()

public function testCheck()
{
Jobs::make($this->payment())->start();
$payment = $this->payment();

Jobs::make($payment)->start();

$response = $this->driver()->check();
$response = $this->driver($payment)->check();

$this->assertInstanceOf(Response::class, $response);
$this->assertInstanceOf(ResponseContract::class, $response);
Expand All @@ -74,7 +77,7 @@ public function testRefund()
Jobs::make($payment)->start();
Jobs::make($payment)->check(true);

$response = $this->driver()->refund();
$response = $this->driver($payment)->refund();

$this->assertInstanceOf(Response::class, $response);
$this->assertInstanceOf(ResponseContract::class, $response);
Expand All @@ -85,17 +88,10 @@ public function testRefund()
$this->assertSame('REVERSED', $response->getStatus());
}

protected function driver(): DriverContract
protected function driver(Model $payment): DriverContract
{
$model = $this->paymentRequest();

$config = $this->config();

return QR::make($config, $model);
}

protected function paymentRequest(): RequestPayment
{
return RequestPayment::firstOrFail();
return QR::make($config, $payment);
}
}
53 changes: 0 additions & 53 deletions tests/Fixtures/Factories/Payment.php

This file was deleted.

5 changes: 0 additions & 5 deletions tests/Fixtures/Resources/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
/** @property \Tests\Fixtures\Models\ReadyPayment $model */
class Model extends BaseModel
{
public function getExternalId(): ?string
{
return $this->model->cashier->external_id;
}

public function getMemberId(): string
{
return config('cashier.drivers.sber_qr.member_id');
Expand Down
5 changes: 2 additions & 3 deletions tests/Helpers/StatusesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ public function testInProgress()

$this->assertFalse($this->status('PAID', 1)->inProgress());

$this->assertFalse($this->status('UNKNOWN', 7)->inProgress());

$this->assertTrue($this->status('UNKNOWN', 7)->inProgress());
$this->assertTrue($this->status('UNKNOWN', 7)->inProgress('CREATED'));

$this->assertFalse($this->status('UNKNOWN', 7)->inProgress('REVERSED'));
Expand All @@ -161,7 +160,7 @@ public function testInProgress()

$this->assertFalse($this->status('UNKNOWN', 7)->inProgress('PAID'));

$this->assertFalse($this->status('UNKNOWN', 7)->inProgress('UNKNOWN'));
$this->assertTrue($this->status('UNKNOWN', 7)->inProgress('UNKNOWN'));
}

protected function status(string $name, int $status_id = 0): Statuses
Expand Down
10 changes: 4 additions & 6 deletions tests/Observers/ObserverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use Helldar\Cashier\Constants\Status;
use Helldar\Cashier\Facades\Config\Payment as PaymentConfig;
use Helldar\Cashier\Providers\ObserverServiceProvider;
use Helldar\Cashier\Providers\ServiceProvider;
use Illuminate\Support\Facades\DB;
use Tests\Concerns\TestServiceProvider;
use Tests\Fixtures\Models\RequestPayment;
use Tests\TestCase;

Expand All @@ -33,9 +33,7 @@ public function testCreate()
$this->assertSame(0, DB::table('payments')->count());
$this->assertSame(0, DB::table('cashier_details')->count());

$payment = $this->payment();

$payment->refresh();
$payment = $this->payment()->refresh();

$this->assertSame(1, DB::table('payments')->count());
$this->assertSame(1, DB::table('cashier_details')->count());
Expand All @@ -58,7 +56,7 @@ public function testUpdate()
$this->assertSame(0, DB::table('payments')->count());
$this->assertSame(0, DB::table('cashier_details')->count());

$payment = $this->payment();
$payment = $this->payment()->refresh();

$this->assertSame(1, DB::table('payments')->count());
$this->assertSame(1, DB::table('cashier_details')->count());
Expand Down Expand Up @@ -98,7 +96,7 @@ public function testUpdate()
protected function getPackageProviders($app): array
{
return [
ServiceProvider::class,
TestServiceProvider::class,
ObserverServiceProvider::class,
];
}
Expand Down
Loading

0 comments on commit c931c6d

Please sign in to comment.