Directory Structure

Routes

Overview

The routes folder in a Laravel project contains all the route definitions that direct HTTP requests to the appropriate controller methods or closures. This is where we define the various endpoints of our application and how they should be handled.

Key Files used in Ecom-API

api.php

The api.php file within the routes folder defines several conditional and grouped routes. These routes are primarily used for API endpoints and are organized based on configuration settings.

  • Key Elements in api.php

    • Conditional Routes:
      • The file defines several routes that are conditionally exposed based on configuration settings in the config/app.php file.
      • Cache Test Endpoint:
        if (config('app.expose_cache_test_endpoint')) {
            Route::get('/cache-test', 'CacheTestController');
        }
        
        • This route exposes the /cache-test endpoint, mapped to the CacheTestController if expose_cache_test_endpoint is set to true in the configuration.
      • Once Test Endpoint:
        if (config('app.expose_once_test_endpoint')) {
            Route::get('/once-test', 'OnceTestController');
        }
        
        • This route exposes the /once-test endpoint, mapped to the OnceTestController if expose_once_test_endpoint is enabled.
      • Exception Test Endpoint:
        if (config('app.expose_exception_test_endpoint')) {
            Route::get('/exception', 'ExceptionTestController');
        }
        
        • This route exposes the /exception endpoint, mapped to the ExceptionTestController based on the expose_exception_test_endpoint configuration.
      • Health Check Route:
        • Route::get('/health-check', 'PingController');
          
        • This route is always available and is used for health checks, mapped to the PingController.
      • Grouped Routes with Optional Basic Authentication:
        • Route::middleware(config('auth.basic_auth.enabled') ? 'auth.basic.api' : [])->group(base_path('routes/endpoints.php'));
          
        • This section groups routes defined in the routes/endpoints.php file.
        • It conditionally applies basic authentication middleware (auth.basic.api) if the auth.basic_auth.enabled configuration is set to true. If not enabled, it proceeds without applying any middleware.

console.php

The console.php file is used to define custom Artisan commands for Laravel's command-line interface (CLI). These commands can perform various tasks, such as managing database records or automating specific processes.

  • Key Elements in console.php

    • Custom Artisan Command:
      • The file defines a custom Artisan command named submit-outstanding-orders-for-settlement.
      • This command is responsible for identifying outstanding orders that are authorized but not yet captured and submitting them for settlement.
    • Database Queries:
      • The command interacts with two tables in the payment database connection: toolstation_payment_se.transactions and toolstation.user_orders.
      • Query 1:
        • The first query selects records from toolstation_payment_se.transactions joined with the toolstation.user_orders table.
        • It filters for orders with specific criteria, such as being authorized (status = 'authorised'), having no captured amount (amount_captured = 0), using a specific payment gateway (gateway = 3), and having a specific transaction type (transaction_type = 1).
        • It processes these records in chunks of 100, ordering them by the uor_ts timestamp.
        • For each order, it dispatches a job to capture the payment using the CapturePaymentForOrder job.
      • Query 2:
        • The second query is similar but operates on toolstation_payment_se.transactions joined with the toolstation.user_parent_orders table.
        • It filters and processes records with similar criteria and orders them by the uop_ts timestamp.
        • For each parent order, it retrieves the related order and dispatches the CapturePaymentForOrder job to capture the payment, forcing the capture if necessary.
    • Processing in Chunks:
      • The chunk(100, function ($rows) { ... }) method is used to process the database records in chunks of 100 at a time. This approach is memory-efficient and helps prevent timeouts or memory issues when processing large datasets.
    • Job Dispatching:
      • For each order identified by the queries, a job (CapturePaymentForOrder) is dispatched to handle the payment capture process. This job is responsible for interacting with the payment gateway and ensuring that the payment is captured.

endpoint.php

The endpoints.php file is responsible for defining various API routes that are grouped together under specific middleware, as referenced in the api.php file. This includes multiple endpoints such as:

  • Customer
  • Accounts
  • Content
  • Orders
  • Saved list, etc
  • Read all the endpoints here

Copyright © 2026