mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-14 16:53:04 +00:00
5.5 - Precomputing the Order Amount
This commit is contained in:
@@ -69,7 +69,7 @@ class Concert extends Model
|
||||
|
||||
public function createOrder($email, $tickets)
|
||||
{
|
||||
return Order::forTickets($tickets, $email);
|
||||
return Order::forTickets($tickets, $email, $tickets->sum('price'));
|
||||
}
|
||||
|
||||
public function addTickets($quantity)
|
||||
|
||||
@@ -29,15 +29,14 @@ class ConcertOrdersController extends Controller
|
||||
]);
|
||||
|
||||
try {
|
||||
|
||||
// Find some tickets
|
||||
$tickets = $concert->findTickets(request('ticket_quantity'));
|
||||
|
||||
// Charge the customer for the tickets
|
||||
$this->paymentGateway->charge(request('ticket_quantity') * $concert->ticket_price, request('payment_token'));
|
||||
$this->paymentGateway->charge($tickets->sum('price'), request('payment_token'));
|
||||
|
||||
// Create an order for those tickets
|
||||
$order = Order::forTickets($tickets, request('email'));
|
||||
$order = Order::forTickets($tickets, request('email'), $tickets->sum('price'));
|
||||
|
||||
return response()->json($order, 201);
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ class Order extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public static function forTickets($tickets, $email)
|
||||
public static function forTickets($tickets, $email, $amount)
|
||||
{
|
||||
$order = self::create([
|
||||
'email' => $email,
|
||||
'amount' => $tickets->sum('price'),
|
||||
'amount' => $amount,
|
||||
]);
|
||||
|
||||
foreach ($tickets as $ticket) {
|
||||
|
||||
Reference in New Issue
Block a user