mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
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) {
|
|
$callback = $this->beforeFirstChargeCallback;
|
|
$this->beforeFirstChargeCallback = null;
|
|
$callback($this);
|
|
}
|
|
|
|
if ($token !== $this->getValidTestToken()) {
|
|
throw new PaymentFailedException;
|
|
}
|
|
$this->charges[] = $amount;
|
|
}
|
|
|
|
public function newChargesDuring($callback)
|
|
{
|
|
$chargesFrom = $this->charges->count();
|
|
$callback($this);
|
|
return $this->charges->slice($chargesFrom)->values();
|
|
}
|
|
|
|
public function totalCharges()
|
|
{
|
|
return $this->charges->sum();
|
|
}
|
|
|
|
public function beforeFirstCharge($callback)
|
|
{
|
|
$this->beforeFirstChargeCallback = $callback;
|
|
}
|
|
}
|