Skip to content

Commit

Permalink
Payu Laravel
Browse files Browse the repository at this point in the history
  • Loading branch information
atomjoy committed Nov 19, 2022
1 parent 7902383 commit f685763
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tests/Payu/PayuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Order;
use Tests\TestCase;
use Payu\Events\PayuPaymentCreated;
use Payu\Gateways\PayuPaymentGateway;

/**
* php artisan --env=testing migrate:fresh --seed
Expand Down Expand Up @@ -76,4 +77,80 @@ public function sandbox_payment_url()

$this->assertTrue(true);
}

/** @test */
public function convert_to_cents()
{
$g = new PayuPaymentGateway();

// Invalid

$this->expectException(\Exception::class);
$g->toCents('3.59');

$this->expectException(\Exception::class);
$g->toCents(0);

$this->expectException(\Exception::class);
$g->toCents(0.00);


$this->expectException(\Exception::class);
$g->toCents(.123);


$this->expectException(\Exception::class);
$g->toCents(10.123);

// Good

$this->assertTrue($g->toCents(1) == 100);
$this->assertTrue($g->toCents(2) == 200);
$this->assertTrue($g->toCents(3) == 300);
$this->assertTrue($g->toCents(4) == 400);
$this->assertTrue($g->toCents(5) == 500);

$this->assertTrue($g->toCents(.01) == 1);
$this->assertTrue($g->toCents(.1) == 10);
$this->assertTrue($g->toCents(.10) == 10);
$this->assertTrue($g->toCents(.11) == 11);
$this->assertTrue($g->toCents(.12) == 12);
$this->assertTrue($g->toCents(.13) == 13);
$this->assertTrue($g->toCents(.14) == 14);
$this->assertTrue($g->toCents(.15) == 15);
$this->assertTrue($g->toCents(.16) == 16);
$this->assertTrue($g->toCents(.17) == 17);
$this->assertTrue($g->toCents(.18) == 18);
$this->assertTrue($g->toCents(.19) == 19);
$this->assertTrue($g->toCents(.20) == 20);
$this->assertTrue($g->toCents(.21) == 21);

$this->assertTrue($g->toCents(01.10) == 110);
$this->assertTrue($g->toCents(01.11) == 111);
$this->assertTrue($g->toCents(01.12) == 112);
$this->assertTrue($g->toCents(01.13) == 113);
$this->assertTrue($g->toCents(01.14) == 114);
$this->assertTrue($g->toCents(01.15) == 115);
$this->assertTrue($g->toCents(01.16) == 116);
$this->assertTrue($g->toCents(01.17) == 117);
$this->assertTrue($g->toCents(01.18) == 118);
$this->assertTrue($g->toCents(01.19) == 119);
$this->assertTrue($g->toCents(01.20) == 120);
$this->assertTrue($g->toCents(01.21) == 121);

$this->assertTrue($g->toCents(10.11) == 1011);
$this->assertTrue($g->toCents(10.12) == 1012);
$this->assertTrue($g->toCents(10.13) == 1013);
$this->assertTrue($g->toCents(10.14) == 1014);
$this->assertTrue($g->toCents(10.15) == 1015);
$this->assertTrue($g->toCents(10.16) == 1016);
$this->assertTrue($g->toCents(10.17) == 1017);
$this->assertTrue($g->toCents(10.18) == 1018);
$this->assertTrue($g->toCents(10.19) == 1019);
$this->assertTrue($g->toCents(10.20) == 1020);
$this->assertTrue($g->toCents(10.21) == 1021);

$this->assertTrue($g->toCents(123.46) == 12346);
$this->assertTrue($g->toCents(123.56) == 12356);
}
}

0 comments on commit f685763

Please sign in to comment.