163 - Total Charges for a Specific Account

This commit is contained in:
Adam Wathan
2018-01-29 13:13:29 -05:00
parent 54a8159a1d
commit 0db962d04c
6 changed files with 37 additions and 5 deletions

View File

@@ -20,4 +20,9 @@ class Charge
{
return $this->data['card_last_four'];
}
public function destination()
{
return $this->data['destination'];
}
}

View File

@@ -23,7 +23,7 @@ class FakePaymentGateway implements PaymentGateway
return $token;
}
public function charge($amount, $token)
public function charge($amount, $token, $destinationAccountId)
{
if ($this->beforeFirstChargeCallback !== null) {
$callback = $this->beforeFirstChargeCallback;
@@ -38,6 +38,7 @@ class FakePaymentGateway implements PaymentGateway
return $this->charges[] = new Charge([
'amount' => $amount,
'card_last_four' => substr($this->tokens[$token], -4),
'destination' => $destinationAccountId,
]);
}
@@ -53,6 +54,13 @@ class FakePaymentGateway implements PaymentGateway
return $this->charges->map->amount()->sum();
}
public function totalChargesFor($accountId)
{
return $this->charges->filter(function ($charge) use ($accountId) {
return $charge->destination() === $accountId;
})->map->amount()->sum();
}
public function beforeFirstCharge($callback)
{
$this->beforeFirstChargeCallback = $callback;

View File

@@ -4,7 +4,7 @@ namespace App\Billing;
interface PaymentGateway
{
public function charge($amount, $token);
public function charge($amount, $token, $destinationAccountId);
public function getValidTestToken();
public function newChargesDuring($callback);