mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 03:04:05 +00:00
4.2 - Returning Order Details
This commit is contained in:
@@ -30,7 +30,9 @@ class ConcertOrdersController extends Controller
|
||||
try {
|
||||
$order = $concert->orderTickets(request('email'), request('ticket_quantity'));
|
||||
$this->paymentGateway->charge(request('ticket_quantity') * $concert->ticket_price, request('payment_token'));
|
||||
return response()->json([], 201);
|
||||
|
||||
return response()->json($order, 201);
|
||||
|
||||
} catch (PaymentFailedException $e) {
|
||||
$order->cancel();
|
||||
return response()->json([], 422);
|
||||
|
||||
@@ -8,6 +8,11 @@ class Order extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function concert()
|
||||
{
|
||||
return $this->belongsTo(Concert::class);
|
||||
}
|
||||
|
||||
public function tickets()
|
||||
{
|
||||
return $this->hasMany(Ticket::class);
|
||||
@@ -26,4 +31,13 @@ class Order extends Model
|
||||
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'email' => $this->email,
|
||||
'ticket_quantity' => $this->ticketQuantity(),
|
||||
'amount' => $this->ticketQuantity() * $this->concert->ticket_price,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,21 @@ class OrderTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
/** @test */
|
||||
function converting_to_an_array()
|
||||
{
|
||||
$concert = factory(Concert::class)->create(['ticket_price' => 1200])->addTickets(5);
|
||||
$order = $concert->orderTickets('jane@example.com', 5);
|
||||
|
||||
$result = $order->toArray();
|
||||
|
||||
$this->assertEquals([
|
||||
'email' => 'jane@example.com',
|
||||
'ticket_quantity' => 5,
|
||||
'amount' => 6000,
|
||||
], $result);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function tickets_are_released_when_an_order_is_cancelled()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user