Skip to content

Commit

Permalink
Resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Helldar committed Aug 6, 2021
1 parent 13c219d commit 86af6b5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
11 changes: 10 additions & 1 deletion src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class Driver extends BaseDriver

public function start(): Response
{
$this->init();
$initialized = $this->init();

$this->initialized($initialized);

$request = GetQR::make($this->model);

Expand All @@ -67,4 +69,11 @@ protected function init(): Response

return $this->request($request, Responses\Init::class);
}

protected function initialized(Response $initialized): void
{
$external_id = $initialized->getExternalId();

$this->payment->cashier()->updateOrCreate(compact('external_id'));
}
}
2 changes: 0 additions & 2 deletions src/Requests/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public function getRawBody(): array
'PaymentId' => $this->model->getExternalId(),

'Amount' => $this->model->getSum(),

'Currency' => $this->model->getCurrency(),
];
}
}
28 changes: 27 additions & 1 deletion tests/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Helldar\CashierDriver\Tinkoff\QrCode\Driver as QR;
use Helldar\Contracts\Cashier\Driver as DriverContract;
use Helldar\Contracts\Cashier\Http\Response as ResponseContract;
use Helldar\Support\Facades\Http\Url;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\database\seeders\DatabaseSeeder;
use Tests\Fixtures\Models\RequestPayment;
Expand All @@ -37,22 +38,47 @@ public function testStart()

$this->assertInstanceOf(Response::class, $response);
$this->assertInstanceOf(ResponseContract::class, $response);

$this->assertIsString($response->getExternalId());
$this->assertMatchesRegularExpression('/^(\d+)$/', $response->getExternalId());

$this->assertNull($response->getStatus());

$this->assertTrue(Url::is($response->getUrl()));
}

public function testCheck()
{
$this->driver()->start();

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

$this->assertInstanceOf(Response::class, $response);
$this->assertInstanceOf(ResponseContract::class, $response);

$this->assertIsString($response->getExternalId());
$this->assertMatchesRegularExpression('/^(\d+)$/', $response->getExternalId());

$this->assertSame('FORM_SHOWED', $response->getStatus());

$this->assertSame([
'status' => 'FORM_SHOWED',
], $response->toArray());
}

public function testRefund()
{
$this->driver()->start();

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

$this->assertInstanceOf(Response::class, $response);
$this->assertInstanceOf(ResponseContract::class, $response);

$this->assertIsString($response->getExternalId());
$this->assertMatchesRegularExpression('/^(\d+)$/', $response->getExternalId());

$this->assertSame('CANCELED', $response->getStatus());
}

protected function setUp(): void
Expand All @@ -73,7 +99,7 @@ protected function driver(): DriverContract

protected function payment(): RequestPayment
{
return RequestPayment::findOrFail(self::PAYMENT_ID);
return RequestPayment::firstOrFail();
}

protected function runSeeders()
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Models/RequestPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RequestPayment extends Model

protected $table = 'payments';

protected $fillable = ['id', 'type_id', 'status_id', 'sum', 'currency', 'created_at'];
protected $fillable = ['id', 'type_id', 'status_id', 'sum', 'currency'];

protected $casts = [
'id' => 'integer',
Expand Down
4 changes: 1 addition & 3 deletions tests/Requests/CancelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ public function testBody()
$this->assertSame([
'PaymentId' => self::PAYMENT_EXTERNAL_ID,
'Amount' => self::PAYMENT_SUM_FORMATTED,
'Currency' => self::CURRENCY_FORMATTED,

'TerminalKey' => $this->getTerminalKey(),

'Token' => '668f52d9fb6f6ff75b4a319b7bc34552cf39c82cc0cf2e7a2146f54b8977cb01',
'Token' => '8473d8d4cafb9ec63071e9050c05e0dd1178fc8e1f3c765ffef7ec7fb5fcb758',
], $request->body());
}

Expand All @@ -93,7 +92,6 @@ public function testGetRawBody()
$this->assertSame([
'PaymentId' => self::PAYMENT_EXTERNAL_ID,
'Amount' => self::PAYMENT_SUM_FORMATTED,
'Currency' => self::CURRENCY_FORMATTED,
], $request->getRawBody());
}
}
13 changes: 7 additions & 6 deletions tests/database/seeders/PaymentSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ class PaymentSeeder extends Seeder
public function run()
{
RequestPayment::create([
'id' => TestCase::PAYMENT_ID,
'type_id' => TestCase::MODEL_TYPE_ID,
'status_id' => TestCase::MODEL_STATUS_ID,
'sum' => TestCase::PAYMENT_SUM,
'currency' => TestCase::CURRENCY,
'created_at' => TestCase::PAYMENT_DATE,
'id' => rand(1, 99999999),

'type_id' => TestCase::MODEL_TYPE_ID,
'status_id' => TestCase::MODEL_STATUS_ID,

'sum' => TestCase::PAYMENT_SUM,
'currency' => TestCase::CURRENCY,
]);
}
}

0 comments on commit 86af6b5

Please sign in to comment.