mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-03 16:48:28 +00:00
49 - Moving the Email to the Reservation
This commit is contained in:
@@ -56,13 +56,13 @@ class Concert extends Model
|
||||
return $this->createOrder($email, $tickets);
|
||||
}
|
||||
|
||||
public function reserveTickets($quantity)
|
||||
public function reserveTickets($quantity, $email)
|
||||
{
|
||||
$tickets = $this->findTickets($quantity)->each(function ($ticket) {
|
||||
$ticket->reserve();
|
||||
});
|
||||
|
||||
return new Reservation($tickets);
|
||||
return new Reservation($tickets, $email);
|
||||
}
|
||||
|
||||
public function findTickets($quantity)
|
||||
|
||||
@@ -31,13 +31,13 @@ class ConcertOrdersController extends Controller
|
||||
|
||||
try {
|
||||
// Find some tickets
|
||||
$reservation = $concert->reserveTickets(request('ticket_quantity'));
|
||||
$reservation = $concert->reserveTickets(request('ticket_quantity'), request('email'));
|
||||
|
||||
// Charge the customer for the tickets
|
||||
$this->paymentGateway->charge($reservation->totalCost(), request('payment_token'));
|
||||
|
||||
// Create an order for those tickets
|
||||
$order = Order::forTickets($reservation->tickets(), request('email'), $reservation->totalCost());
|
||||
$order = Order::forTickets($reservation->tickets(), $reservation->email(), $reservation->totalCost());
|
||||
|
||||
return response()->json($order, 201);
|
||||
|
||||
|
||||
@@ -5,10 +5,12 @@ namespace App;
|
||||
class Reservation
|
||||
{
|
||||
private $tickets;
|
||||
private $email;
|
||||
|
||||
public function __construct($tickets)
|
||||
public function __construct($tickets, $email)
|
||||
{
|
||||
$this->tickets = $tickets;
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function totalCost()
|
||||
@@ -21,6 +23,11 @@ class Reservation
|
||||
return $this->tickets;
|
||||
}
|
||||
|
||||
public function email()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function cancel()
|
||||
{
|
||||
foreach ($this->tickets as $ticket) {
|
||||
|
||||
Reference in New Issue
Block a user