I don't really see what the exact question is here. What is not working for you? What have you tried so far?
Jul 8, 2019
5
Level 2
confirm address and after pay
Hello,
I need a condition/connection between "confirm address" and "pay now" Confirm address = save delivery address in my db Pay now = link with stripe
I need something like: if address is not confirmated you can't pay
Front controller:
public function step2(Step2Request $request){
$city = City::firstOrCreate([
'postal_code' => $request['postal_code'],
'name' => $request['name'],
'country_id' => $request['country'],
]);
$delivery = Delivery::firstOrCreate([
'street' => $request['street'],
'house_nr' => $request['house_nr'],
'bus' => $request['bus'],
'city_id' => $city->id,
]);
$user = Auth::user();
$user->deliveries()->syncWithoutDetaching($delivery->id);
session(['delivery_id' => $delivery->id]);
$myCountry = Country::findOrFail($request['country']);
session(['shipment' => $myCountry->shipment]);
$ship_cost = session('shipment');
return view('checkout', compact('ship_cost'));
}
public function checkout(){
if(Request::isMethod('post')){
$product_id = Request::get('product_id');
$product = Product::find($product_id);
Cart::add(array('id' => $product_id, 'name' => $product->name, 'qty' => 1, 'price' => $product->price));
}
$cart = Cart::content();
//increment
if (Request::get('product_id') && (Request::get('increment')) == 1) {
$item = Cart::search(
function($key, $value) {
return $key->id == Request::get('product_id');
})->first();
Cart::update($item->rowId, $item->qty + 1);
}
if (Request::get('product_id') && (Request::get('decrease')) == 1) {
$item = Cart::search(function($key, $value) { return $key->id == Request::get('product_id'); })->first();
Cart::update($item->rowId, $item->qty - 1);
}
$myCountry = Country::where('id', 1)->first();
$ship_cost = '1.00';
return view('checkout', compact ('cart', 'token','cities', 'cit','countries', 'addresses','myCountry', 'ship_cost'));
}
web
Route::post('step2', 'FrontController@step2')->name('step2');
Route::get('/checkout', 'FrontController@checkout')->name('checkout');
checkout.blade
@if(!Auth::check())
<a href ="{{route('login')}}" class="btn btn-danger">
<i class="fas fa-shopping-basket"></i>First login</a>
@else
<div class="col-md-5">
<div class="d-md-flex">
<div class="mr-3" >
<label for="first_name">First name</label>
<input type="text" class="form-control mb-2 mr-md-3 " name="first_name" placeholder="Firstname" @auth value="{{Auth::user()->first_name}}" @endauth>
</div>
<div >
<label for="last_name">Last name</label>
<input type="text" class="form-control mb-2 mr-md-5" name="last_name" placeholder="Lastname" @auth value="{{Auth::user()->last_name}}" @endauth>
</div>
</div>
<h5>Delivery Address</h5>
<form action="{{route('step2')}}" method="POST">
@csrf
@method('POST')
<input type="text" class="form-control mb-2" name="street" placeholder="Addresss" required>
<div class="d-flex">
<input type="text" class="form-control mb-2 mr-3" name="house_nr" placeholder="Number" required>
<input type="text" class="form-control mb-2 ml-3" name="bus" placeholder="Bus">
</div>
<input type="text" class="form-control mb-2" name="postal_code" placeholder="Postal code" required>
<input type="text" class="form-control mb-2" name="name" placeholder="City" required>
<div class="form-group d-flex">
<label for="country2" class="pr-3 pt-1">Country</label>
<select class="form-control" id="country2" name="country">
@php($countries = \App\Country::all())
@foreach($countries as $country)
<option value="{{$country->id}}" @auth @if(Auth::user()->address->city->country->id == $country->id) selected @endif @endauth>{{$country->name}}</option>
@endforeach
</select>
</div>
<button class="btn btn-dark text-uppercase" type="submit">Confirm address</button>
</form>
<div class="my-2">
<a href ="{{url('stripe')}}" class="btn btn-success">
<i class="fas fa-shopping-basket"></i> Pay now
</a>
</div>
</div>
<div col-md-7>
@if(count($cart))
<h4 class="d-flex justify-content-between align-items-center mb-3">
<span class="text-muted">Your cart</span>
<span class="badge badge-secondary badge-pill">{{count($cart)}}</span>
</h4>
@foreach($cart as $item)
<ul class="list-group mb-3">
<li class="list-group-item d-flex justify-content-between lh-condensed">
<div>
<h6 class="my-0">{{ $item->name }}</h6>
</div>
<div >
<span class="text-muted mx-5">{{ $item->qty }}</span>
<span class="text-muted">€{{ $item->price }}</span>
</div>
</li>
@endforeach
<li class="list-group-item d-flex justify-content-between bg-light">
<div class="text-primary">
<h6 class="my-0">Shipping</h6>
</div>
<span class="text-primary">€ {{$ship_cost}}</span>
</li>
<li class="list-group-item d-flex justify-content-between bg-light">
<div class="text-success">
<h6 class="my-0">Promo code</h6>
<small>EXAMPLECODE</small>
</div>
<span class="text-success">-</span>
</li>
<li class="list-group-item d-flex justify-content-between">
<span>Total (EUR)</span>
<strong>€ {{Cart::subTotal() + $ship_cost}}</strong>
</li>
</ul>
<form class="card p-2">
<div class="input-group">
<input type="text" class="form-control" placeholder="Promo code">
<div class="input-group-append">
<button type="submit" class="btn btn-secondary">Redeem</button>
</div>
</div>
</form>
</div>
@else
<p class="alert-info">No items in shopping cart</p>
</div>
@endif
@endif
Please or to participate in this conversation.