rubenochoa
1 week ago

Pay on delivery | best method

Posted 1 week ago by rubenochoa

I am working on checkout. If a user does not choose to pay by card but pay on delivery, so i did this:

PostController:

 public function payondelivery(){                
                Mail::send('shop.order_confirmation2', [
                    'user' => Auth()->user(),
                    'products' => $cart->items,
                    'totalPrice' => $cart->totalPrice,
                ], function($message) use ($user) {
                        $message->to($user->email);
                        $message->from("******@gmail.com");
                        $message->subject("Your order confirmation");
                        $message->bcc("******@gmail.com");
                    }
                );          
            return redirect()->route('product.index')->with('success', 'Successfully purchased products! | You will receive an oder confirmation at your email');
    }

route:

 Route::post('/order_confirmation2', [
            'uses' => '[email protected]',
            'as' => 'payondelivery'
        ]);  

order_confirmation2.blade.php

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Shipping informations</title>
</head>

<body>
    <div class="col-md-4 col-md-offset-4">
        <div class="cart">
            <p>You choose to pay on delivery</p>
            <div class="container">
                <h2>Shipping informations</h2>
                <table class="table">
                    <thead>
                        <tr>
                            <th>Firstname</th>
                            <th>Lastname</th>
                            <th>City</th>
                            <th>Address</th>
                            <th>Zip</th>
                            <th>Vat number</th>
                            <th>Phone</th>

                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>{{ Auth::user()->name }}</td>
                            <td>{{ Auth::user()->surname }}</td>
                            <td>{{ Auth::user()->city }}</td>
                            <td>{{ Auth::user()->address }}</td>
                            <td>{{ Auth::user()->zip }}</td>
                            <td>{{ Auth::user()->vatnumber }}</td>
                            <td>{{ Auth::user()->phone }}</td>
                        </tr>
                    </tbody>
                </table>

            </div>
        </div>
        <hr>
        <h2>My Orders</h2>
        @foreach ($products as $product)
        <li class="list-group-item">
            <span class="badge badge-secondary">Quantity: {{ $product['qty'] }}</span><br>
            <span class="badge badge-secondary">Item: {{ $product['item']['title'] }}</span><br>
            <span class="badge badge-secondary">Price: ${{ $product['price'] }}</span>
        </li>
        @endforeach
    </div>
</body>

</html>

and at checkout.blade.php i am using link under the form of the payment by cart

<label><a href="{{ route('payondelivery')}}">Pay on Delivery</a></label>

Is this the best method to do it? What do you think?

Please sign in or create an account to participate in this conversation.