6.5 - Hooking into Charges

This commit is contained in:
Adam Wathan
2016-11-19 20:50:31 -05:00
parent d855fa3e16
commit 85c79f32b8
2 changed files with 26 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Billing;
class FakePaymentGateway implements PaymentGateway
{
private $charges;
private $beforeFirstChargeCallback;
public function __construct()
{
@@ -18,6 +19,10 @@ class FakePaymentGateway implements PaymentGateway
public function charge($amount, $token)
{
if ($this->beforeFirstChargeCallback !== null) {
$this->beforeFirstChargeCallback->__invoke($this);
}
if ($token !== $this->getValidTestToken()) {
throw new PaymentFailedException;
}
@@ -28,4 +33,9 @@ class FakePaymentGateway implements PaymentGateway
{
return $this->charges->sum();
}
public function beforeFirstCharge($callback)
{
$this->beforeFirstChargeCallback = $callback;
}
}