2.4 - Faking the Payment Gateway

This commit is contained in:
Adam Wathan
2016-11-08 13:14:52 -05:00
parent 94480e7eac
commit 46640c5096
7 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Billing;
class FakePaymentGateway implements PaymentGateway
{
private $charges;
public function __construct()
{
$this->charges = collect();
}
public function getValidTestToken()
{
return "valid-token";
}
public function charge($amount, $token)
{
$this->charges[] = $amount;
}
public function totalCharges()
{
return $this->charges->sum();
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace App\Billing;
interface PaymentGateway
{
public function charge($amount, $token);
}

View File

@@ -44,6 +44,7 @@ class Handler extends ExceptionHandler
*/
public function render($request, Exception $exception)
{
throw $exception;
return parent::render($request, $exception);
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers;
use App\Concert;
use Illuminate\Http\Request;
use App\Billing\PaymentGateway;
class ConcertOrdersController extends Controller
{
private $paymentGateway;
public function __construct(PaymentGateway $paymentGateway)
{
$this->paymentGateway = $paymentGateway;
}
public function store($concertId)
{
$concert = Concert::find($concertId);
$ticketQuantity = request('ticket_quantity');
$amount = $ticketQuantity * $concert->ticket_price;
$token = request('payment_token');
$this->paymentGateway->charge($amount, $token);
return response()->json([], 201);
}
}