PHP 8.2.30
Preview: CheckoutController.php Size: 3.24 KB
/home/byroehnu/cnggold.com.ng/app/Http/Controllers/Frontend/CheckoutController.php

<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use App\Http\Requests\CheckoutRequest;
use App\Models\Coupon;
use App\Models\ManualPaymentGateway;
use App\Models\Page;
use App\Models\Setting;
use App\Repositories\Frontend\CheckoutRepository;
use Artesaos\SEOTools\Facades\OpenGraph;
use Artesaos\SEOTools\Facades\SEOMeta;
use Artesaos\SEOTools\Facades\TwitterCard;
use Carbon\Carbon;
use Illuminate\Http\Request;

class CheckoutController extends Controller
{
    public function applyCoupon(Request $request)
    {
        $coupon = Coupon::where('code', $request->code)->first();

        if (! $coupon) {
            return response([
                'success' => false,
                'message' => 'Invalid coupon code',
            ], 404);
        }

        $now = Carbon::now();

        if (
            ($coupon->start_date && $now->lt($coupon->start_date)) ||
            ($coupon->end_date && $now->gt($coupon->end_date))
        ) {
            return response([
                'success' => false,
                'message' => 'Coupon has expired or is not active yet.',
            ], 400);
        }

        return response([
            'success' => true,
            'message' => 'Coupon applied successfully.',
            'coupon' => $coupon,
        ]);
    }

    public function checkout()
    {
        if (Setting::pull("is_enabled_ecommerce") === "0") {
            abort(404);
        }

        $data['payment_gateway'] = [
            'is_paypal_active' => Setting::pull('paypal_is_active') == '1',
            'is_stripe_active' => Setting::pull('stripe_is_active') == '1',
            'is_sslcz_active' => Setting::pull('sslcz_is_active') == '1',
            'is_flutterwave_active' => Setting::pull('flutterwave_is_active') == '1',
            'is_razorpay_active' => Setting::pull('razorpay_is_active') == '1',
            'is_cod_active' => Setting::pull('cod_is_active') == '1',
        ];

        $data['manual_payment_gateways'] = ManualPaymentGateway::where('status', '1')->with('content')->get();

        $terms_condition_page_id = Setting::pull('default_terms_and_conditions_page');
        $page = Page::find($terms_condition_page_id);
        $data['terms_condition_url'] = route('pages.show', $page->slug);

        $current_page_url = request()->url();
        $meta_tags = 'checkout';
        $site_name = Setting::pull('site_name');
        $tagline = __('Checkout');

        SEOMeta::setTitle($tagline . ' - ' . $site_name);
        SEOMeta::setCanonical($current_page_url);
        SEOMeta::addMeta('robots', 'index, follow');
        SEOMeta::addKeyword(explode(',', $meta_tags));

        OpenGraph::setUrl($current_page_url);
        OpenGraph::setSiteName($site_name);
        OpenGraph::addProperty('type', 'website');

        TwitterCard::setSite('@bione');
        TwitterCard::setType('summary_large_image');
        SEOMeta::addMeta('viewport', 'width=device-width, initial-scale=1');
        $data['meta_tags'] = $meta_tags;
        $data['tagline'] = $tagline;
        $data['site_name'] = $site_name;

        return inertia('Checkout/Index', $data);
    }

    public function placeOrder(CheckoutRequest $request, CheckoutRepository $repository)
    {
        return $repository->checkout($request);
    }
}

Directory Contents

Dirs: 0 × Files: 19

Name Size Perms Modified Actions
2.65 KB lrw-r--r-- 2025-06-13 11:19:53
Edit Download
2.26 KB lrw-r--r-- 2025-05-08 11:48:26
Edit Download
3.24 KB lrw-r--r-- 2025-05-15 11:24:11
Edit Download
551 B lrw-r--r-- 2025-04-19 04:22:18
Edit Download
1.72 KB lrw-r--r-- 2025-05-08 11:48:26
Edit Download
6.22 KB lrw-r--r-- 2025-07-19 07:29:54
Edit Download
4.00 KB lrw-r--r-- 2025-05-15 11:24:11
Edit Download
2.63 KB lrw-r--r-- 2025-05-08 11:48:26
Edit Download
3.47 KB lrw-r--r-- 2025-05-08 11:48:26
Edit Download
2.36 KB lrw-r--r-- 2025-07-19 07:29:54
Edit Download
1.63 KB lrw-r--r-- 2025-04-15 10:33:57
Edit Download
2.00 KB lrw-r--r-- 2025-05-08 11:48:26
Edit Download
1.44 KB lrw-r--r-- 2025-04-19 04:22:18
Edit Download
2.13 KB lrw-r--r-- 2025-05-08 11:48:26
Edit Download
408 B lrw-r--r-- 2025-04-19 04:22:18
Edit Download
532 B lrw-r--r-- 2025-04-08 04:12:56
Edit Download
2.09 KB lrw-r--r-- 2025-04-30 16:51:31
Edit Download
1.91 KB lrw-r--r-- 2025-04-13 07:02:31
Edit Download
2.96 KB lrw-r--r-- 2025-05-08 11:48:26
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).