Skip to content

Commit

Permalink
Added methods to knowing statuses (success and pending)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebacarrasco93 committed Jun 18, 2021
1 parent 921cab1 commit 1dc29ab
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/LaravelPayku.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,19 @@ public function notify($order)
{
return PaykuTransaction::whereOrder($order)->firstOrFail();
}

public function findById($id)
{
return PaykuTransaction::whereId($id)->firstOrFail();
}

public function hasStatusSuccess($id)
{
return $this->findById($id)->status == 'success';
}

public function hasStatusPending($id)
{
return $this->findById($id)->status == 'pending';
}
}
23 changes: 23 additions & 0 deletions tests/Unit/LaravelPaykuFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,27 @@ function it_can_prepare_an_order() {
'urlnotify' => route('payku.notify', 'AAA'),
], LaravelPayku::prepareOrder('AAA', 'Test', 1000, '[email protected]'));
}

/** @test */
function it_knows_its_details() {
$payment = PaykuTransaction::create(['id' => 'trx...']);

$this->assertInstanceOf(PaykuTransaction::class, LaravelPayku::findById('trx...'));
}

/** @test */
function it_knows_when_it_has_status_success() {
$payment = PaykuTransaction::create(['id' => 'trx...', 'status' => 'success']);

$this->assertTrue(LaravelPayku::hasStatusSuccess('trx...'));
$this->assertFalse(LaravelPayku::hasStatusPending('trx...'));
}

/** @test */
function it_knows_when_it_has_status_pending() {
$payment = PaykuTransaction::create(['id' => 'trx...', 'status' => 'pending']);

$this->assertTrue(LaravelPayku::hasStatusPending('trx...'));
$this->assertFalse(LaravelPayku::hasStatusSuccess('trx...'));
}
}

0 comments on commit 1dc29ab

Please sign in to comment.