mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
35 lines
863 B
PHP
35 lines
863 B
PHP
<?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);
|
|
|
|
$order = $concert->orders()->create(['email' => request('email')]);
|
|
|
|
foreach (range(1, $ticketQuantity) as $i) {
|
|
$order->tickets()->create([]);
|
|
}
|
|
|
|
return response()->json([], 201);
|
|
}
|
|
}
|