Skip to content

Commit 17819bc

Browse files
committed
Order confirmation
1 parent 7953c7c commit 17819bc

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

app/Http/Controllers/OrdersController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public function store()
2929

3030
$order->addProducts($cart->items);
3131

32-
return redirect('/orders');
32+
return redirect('/orders/' . $order->id);
33+
}
34+
35+
public function show(Order $order)
36+
{
37+
return view('orders.show', ['order' => $order]);
3338
}
3439
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
@extends('layouts.app')
2+
3+
4+
@section('content')
5+
<div class="container">
6+
<div class="row">
7+
<div class="col-md-12 text-center">
8+
<hr>
9+
<h4>Success! Order for {{$order->email}} confirmed.</h4>
10+
</div>
11+
</div>
12+
<div class="row">
13+
<div class="col-md-8">
14+
<div class="panel panel-info">
15+
<div class="panel-heading">
16+
<div class="panel-title">
17+
<div class="row">
18+
<div class="col-md-12">
19+
<h5>Products</h5>
20+
</div>
21+
</div>
22+
</div>
23+
</div>
24+
<div class="panel-body">
25+
@foreach($order->products as $product)
26+
<div class="row">
27+
<div class="col-md-2">
28+
<img src="https://via.placeholder.com/100x70" alt="image" class="card-img">
29+
</div>
30+
<div class="col-md-6">
31+
<h4>{{$product->name}}</h4>
32+
</div>
33+
<div class="col-md-6">
34+
<h6>${{$product->getPrice()}}</h6>
35+
</div>
36+
</div>
37+
@endforeach
38+
</div>
39+
<div class="panel-footer">
40+
<div class="row text-center">
41+
<div class="col-md-9">
42+
<h4 class="text-right">Total <strong>$ {{ $order->totalPrice() }}</strong></h4>
43+
</div>
44+
</div>
45+
</div>
46+
</div>
47+
</div>
48+
</div>
49+
</div>
50+
@endsection

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Route::put('/cart/{product}', 'CartController@update');
2020

2121
Route::post('/orders', 'OrdersController@store');
22+
Route::get('/orders/{order}', 'OrdersController@show');
2223

2324
Route::get('/', function () {
2425
return view('welcome');

tests/Feature/PurchaseTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ public function it_can_purchase_products()
3232
$this->app->instance(PaymentContract::class, $payment);
3333

3434
$response = $this->post('/orders', [
35-
'stripeEmail' => 'test@example.com',
35+
'stripeEmail' => 'test@email.com',
3636
'stripeToken' => $payment->getTestToken(),
3737
]);
3838

39-
$response->assertRedirect('/orders');
39+
$order = Order::query()->where('email', 'test@email.com')->first();
40+
41+
$this->assertNotNull($order);
42+
$response->assertRedirect('/orders/' . $order->id);
43+
44+
$this->get('/orders/' . $order->id)
45+
->assertSee('test@email.com')
46+
->assertSee($product->name);
4047

4148
$this->assertEquals('10.00', $payment->totalCharged());
4249
}
@@ -57,11 +64,11 @@ public function it_creates_orders_after_purchase()
5764
$this->app->instance(PaymentContract::class, $payment);
5865

5966
$this->post('/orders', [
60-
'stripeEmail' => 'test@example.com',
67+
'stripeEmail' => 'test@email.com',
6168
'stripeToken' => $payment->getTestToken(),
6269
]);
6370

64-
$order = Order::where('email', 'test@example.com')->first();
71+
$order = Order::where('email', 'test@email.com')->first();
6572

6673
$this->assertNotNull($order);
6774
$this->assertEquals(1, $order->products->count());

0 commit comments

Comments
 (0)