diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index d779cc8..a9c2fb6 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -40,6 +40,8 @@ class MainController extends Controller public function registerUser(Request $data) { + + // dd($data->all()); // Validate the input data $data->validate([ 'name' => 'required|string|max:255', @@ -183,6 +185,31 @@ class MainController extends Controller } } + public function profile() + { + if (session()->has('id')) { + $user = User::find(session()->get('id')); + return view('profile', compact('user')); + } + return redirect('login'); + } + + public function updateUser(Request $data) + { + $user = User::find(session()->get('id')); + $user->name = $data->input('name'); + $user->email = $data->input('email'); + $user->password = $data->input('password'); + + if ($data->file('file') != null) { + $user->picture = $data->file('file')->getClientOriginalName(); + $data->file('file')->move('uploads/profiles/', $user->picture); + } + if ($user->save()) { + return redirect()->back()->with('success', 'User updated successfully!'); + } + } + @@ -225,6 +252,8 @@ class MainController extends Controller return view('checkout'); } + + public function shop() { return view('shop'); diff --git a/app/Http/Controllers/StripePaymentController.php b/app/Http/Controllers/StripePaymentController.php new file mode 100644 index 0000000..a96b20b --- /dev/null +++ b/app/Http/Controllers/StripePaymentController.php @@ -0,0 +1,75 @@ +input('bill'); + $name = $data->input('name'); + + $phone = $data->input('phone'); + $address = $data->input('address'); + + return view( + 'stripe', + compact('bill', 'name', 'phone', 'address') + ); + } + /** + * success response method. + * + * @return \Illuminate\Http\Response */ + public function stripePost(Request $request) + { + Stripe\Stripe::setApiKey(env('STRIPE_SECRET')); + Stripe\Charge::create([ + "amount" => $request->input('bill') * 100, + "currency" => "usd", + "source" => $request->stripeToken, + "description" => "Payment Successfull!" + ]); + Session::flash('success', 'Payment successful!'); + + if (session()->has('id')) { + $order = new Order(); + $order->status = "Pending"; + $order->customerId = session()->get('id'); + $order->name = $request->input('name'); + $order->phone = $request->input('phone'); + $order->address = $request->input('address'); + $order->bill = $request->input('bill'); + if ($order->save()) { + $cartItems = Cart::where('customerId', session()->get('id'))->get(); + foreach ($cartItems as $item) { + $product = Products::find($item->productId); + $orderItem = new OrderItem(); + $orderItem->orderId = $order->id; + $orderItem->productId = $item->productId; + $orderItem->quantity = $item->quantity; + $orderItem->price = $product->price; + + $orderItem->save(); + $item->delete(); + } + return redirect('/cart')->back()->with('success', 'Order placed successfully!'); + } + } + + + return back(); + } +} diff --git a/composer.json b/composer.json index 4b7e183..5d1ffda 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,8 @@ "require": { "php": "^8.2", "laravel/framework": "^11.9", - "laravel/tinker": "^2.9" + "laravel/tinker": "^2.9", + "stripe/stripe-php": "^15.1" }, "require-dev": { "fakerphp/faker": "^1.23", diff --git a/composer.lock b/composer.lock index 13c8871..c406f26 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7e8c3c14ff33b199b4a0838993eb8423", + "content-hash": "14e8cdf03b6b5d46f815f7145406604e", "packages": [ { "name": "brick/math", @@ -3107,6 +3107,65 @@ ], "time": "2024-04-27T21:32:50+00:00" }, + { + "name": "stripe/stripe-php", + "version": "v15.1.0", + "source": { + "type": "git", + "url": "https://github.com/stripe/stripe-php.git", + "reference": "ce69d019941cf528c036ae0d1a3a9580c7389460" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stripe/stripe-php/zipball/ce69d019941cf528c036ae0d1a3a9580c7389460", + "reference": "ce69d019941cf528c036ae0d1a3a9580c7389460", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "php": ">=5.6.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.5.0", + "phpstan/phpstan": "^1.2", + "phpunit/phpunit": "^5.7 || ^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Stripe\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Stripe and contributors", + "homepage": "https://github.com/stripe/stripe-php/contributors" + } + ], + "description": "Stripe PHP Library", + "homepage": "https://stripe.com/", + "keywords": [ + "api", + "payment processing", + "stripe" + ], + "support": { + "issues": "https://github.com/stripe/stripe-php/issues", + "source": "https://github.com/stripe/stripe-php/tree/v15.1.0" + }, + "time": "2024-07-05T18:52:07+00:00" + }, { "name": "symfony/clock", "version": "v7.1.1", diff --git a/public/uploads/profiles/IMG_2206.jpg b/public/uploads/profiles/IMG_2206.jpg new file mode 100644 index 0000000..3e5dcd4 Binary files /dev/null and b/public/uploads/profiles/IMG_2206.jpg differ diff --git a/public/uploads/profiles/wallpaperflare.com_wallpaper (2).jpg b/public/uploads/profiles/wallpaperflare.com_wallpaper (2).jpg new file mode 100644 index 0000000..0efe3ab Binary files /dev/null and b/public/uploads/profiles/wallpaperflare.com_wallpaper (2).jpg differ diff --git a/resources/views/cart.blade.php b/resources/views/cart.blade.php index bdafe33..75bf2a1 100644 --- a/resources/views/cart.blade.php +++ b/resources/views/cart.blade.php @@ -154,9 +154,9 @@
  • Total Nrs {{ $total }}
  • + {{-- --}} - diff --git a/resources/views/components/header.blade.php b/resources/views/components/header.blade.php index b9b3318..9b57064 100644 --- a/resources/views/components/header.blade.php +++ b/resources/views/components/header.blade.php @@ -22,6 +22,8 @@ + + @@ -115,16 +117,10 @@ {{--
  • Single Product
  • --}}
  • Shopping Cart
  • Check Out
  • - {{--
  • Blog Details
  • --}} +
  • Profile
  • - {{-- - @if (session()->has('id')) -
  • Logout
  • - @else -
  • Login
  • -
  • Register
  • - @endif --}} + diff --git a/resources/views/profile.blade.php b/resources/views/profile.blade.php new file mode 100644 index 0000000..6426b87 --- /dev/null +++ b/resources/views/profile.blade.php @@ -0,0 +1,72 @@ + + + + +
    +
    +
    + +
    +
    +

    Update Account

    +
    +
    + + @if (session('success')) +
    + {{ session('success') }} +
    + @endif + + @if (session('error')) +
    + {{ session('error') }} +
    + @endif + + @if ($errors->any()) +
    +
      + @foreach ($errors->all() as $error) +
    • {{ $error }}
    • + @endforeach +
    +
    + @endif + profile picture + + + @csrf +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + + +
    +
    + +
    +
    +
    +
    +
    + + + + + diff --git a/resources/views/register.blade.php b/resources/views/register.blade.php index 7fe1617..3dad250 100644 --- a/resources/views/register.blade.php +++ b/resources/views/register.blade.php @@ -34,7 +34,7 @@ @endif -
    + {{-- @csrf
    @@ -50,11 +50,39 @@
    + + +
    +
    +
    --}} +
    + @csrf +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + + diff --git a/resources/views/stripe.blade.php b/resources/views/stripe.blade.php new file mode 100644 index 0000000..64c41b9 --- /dev/null +++ b/resources/views/stripe.blade.php @@ -0,0 +1,139 @@ + + + + + Laravel - Stripe Payment Gateway Integration Example - ItSolutionStuff.com + + + + + +
    +

    Stripe Payment Gateway

    +
    +
    +
    +
    +

    Payment Details

    +
    +
    + @if (Session::has('success')) +
    + × +

    {{ Session::get('success') }}

    +
    + @endif +
    + @csrf +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    +
    +
    +
    Please correct the errors and try again.
    +
    +
    +
    +
    + + + + + +
    +
    +
    +
    +
    + +
    +
    +
    + + + + + diff --git a/routes/web.php b/routes/web.php index c5175ed..71cd48d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,30 +1,39 @@ name("cart.update"); - Route::get('/checkout', [MainController::class, 'checkout']); Route::get('/main', [MainController::class, 'main']); Route::get('/shop', [MainController::class, 'shop']); Route::get('/single/{id}', [MainController::class, 'singleProduct']); -Route::get('/register', [MainController::class, 'register']); -Route::post('/registerUser', [MainController::class, 'registerUser']); +Route::get('/register', [MainController::class, 'register'])->name('register'); +Route::post('/registerUser', [MainController::class, 'registerUser'])->name('registerUser'); Route::get('/login', [MainController::class, 'login']); Route::post('/loginUser', [MainController::class, 'loginUser']); Route::get('/logout', [MainController::class, 'logout']); + + +Route::controller(StripePaymentController::class)->group(function () { + Route::get('stripe', 'stripe'); + Route::post('stripe', 'stripePost')->name('stripe.post'); +});