Files
ticketbeast/app/Billing/FakePaymentGateway.php
2016-11-19 20:50:31 -05:00

42 lines
849 B
PHP

<?php
namespace App\Billing;
class FakePaymentGateway implements PaymentGateway
{
private $charges;
private $beforeFirstChargeCallback;
public function __construct()
{
$this->charges = collect();
}
public function getValidTestToken()
{
return "valid-token";
}
public function charge($amount, $token)
{
if ($this->beforeFirstChargeCallback !== null) {
$this->beforeFirstChargeCallback->__invoke($this);
}
if ($token !== $this->getValidTestToken()) {
throw new PaymentFailedException;
}
$this->charges[] = $amount;
}
public function totalCharges()
{
return $this->charges->sum();
}
public function beforeFirstCharge($callback)
{
$this->beforeFirstChargeCallback = $callback;
}
}