From 1dc29ab62c352c87c5dc258c7bc119857f96be46 Mon Sep 17 00:00:00 2001 From: Seba Carrasco Poblete Date: Fri, 18 Jun 2021 08:56:00 -0400 Subject: [PATCH] Added methods to knowing statuses (success and pending) --- src/LaravelPayku.php | 15 +++++++++++++++ tests/Unit/LaravelPaykuFacadeTest.php | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/LaravelPayku.php b/src/LaravelPayku.php index f6a7e06..5e746f7 100644 --- a/src/LaravelPayku.php +++ b/src/LaravelPayku.php @@ -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'; + } } diff --git a/tests/Unit/LaravelPaykuFacadeTest.php b/tests/Unit/LaravelPaykuFacadeTest.php index d11f7e4..739e0e4 100644 --- a/tests/Unit/LaravelPaykuFacadeTest.php +++ b/tests/Unit/LaravelPaykuFacadeTest.php @@ -75,4 +75,27 @@ function it_can_prepare_an_order() { 'urlnotify' => route('payku.notify', 'AAA'), ], LaravelPayku::prepareOrder('AAA', 'Test', 1000, 'seba@sextanet.cl')); } + + /** @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...')); + } }