Customers

Order

Overview by Shivang


GET Customer Order History

  • Route: GET ../customers/{customerId}/orders
  • Controller: OrderHistoryController
  • Method: index
  • Request: Request
  • Description: Endpoint to retrieve a paginated list of orders for a specific customer.

The index method in the OrderHistoryController fetches the order history for a customer identified by their ID. It first retrieves the customer using the customerService, ensuring a 404 error is thrown if the customer is not found. The method then verifies authorization to view the customer's orders. It retrieves the paginated list of orders with specified relationships and filters, logging the order IDs for debugging purposes. Finally, it returns an OrderResource collection containing the customer's orders.

GET Customer Purchase History

  • Route: GET ../customers/{customerId}/purchase-history
  • Controller: PurchaseHistoryController
  • Method: index
  • Request: Request
  • Description: Endpoint to retrieve a paginated list of a customer's purchase history.

The index method in the PurchaseHistoryController retrieves the purchase history for a specific customer based on their ID. It starts by fetching the customer using the customerService, ensuring a 404 error is thrown if the customer is not found. The method then checks authorization to view the customer's purchase history. It retrieves the paginated purchase history with specified relationships and filters, logging a debug message for tracking purposes. Finally, it returns an OrderItemResource collection containing the customer's purchase history.


Overview by Atul

GET: customers/{customerId}/orders

  • Controller: OrderHistoryController
  • Method: get
  • Request: Request
  • Parameters:
    • customerId: Specifies the ID of the customer for whom the order history is being fetched.
  • Description: Endpoint for retrieve the list of orders.

The index function is designed to retrieve a paginated list of orders for a specified customer, ensuring that the user is authorized to view the customer's orders, and then returns the order data with details about products and attributes.

 public function index(Request $request, $customerId)
{
    // Function implementation goes here
}

Request Parameters for customers/{customerId}/orders:

  • Header :- Accept-Language:- en-UK,en,
  • x-toolstation-customer-id:- Token Id of the customer

Response

Response Code: 200 OK

Response:

{
   {
    "data": [],
    "links": {
        "first": "https://ecom-api.gke.pre-prod.nl.toolstation.dev/api/customers/CWW02068816/orders?page=1",
        "last": null,
        "prev": null,
        "next": null
    },
    "meta": {
        "current_page": 1,
        "from": null,
        "path": "https://ecom-api.gke.pre-prod.nl.toolstation.dev/api/customers/CWW02068816/orders",
        "per_page": 50,
        "to": null
    }
}
}

Response Code: 403 Forbidden

Response:

{
    "error": {
        "code": "403.99",
        "message": "Forbidden",
        "info": "https://developers.example.com",
        "data": null
    }
}

GET: customers/{customerId}/purchase-history

  • Controller: PurchaseHistoryController
  • Method: get
  • Request: index
  • Parameters:
    • customerId: Identifies the specific customer whose purchase history is being retrieved.
  • Description: Endpoint for retrieve the purchase history.

The index function retrieves and returns a paginated list of purchase history for a specified customer, including authorization checks and logging, and handles pagination and data retrieval using request parameters and service functions.

 public function index(Request $request, $customerId)
{
    // Function implementation goes here
}

Request Parameters for customers/{customerId}/purchase-history:

  • Header :- Accept-Language:- en-UK,en,
  • x-toolstation-customer-id:- Token Id of the customer

Response

Response Code: 200 OK

Response:

{
    "data": [],
    "links": {
        "first": "https://ecom-api.gke.pre-prod.nl.toolstation.dev/api/customers/CWW02068816/purchase-history?page=1",
        "last": "https://ecom-api.gke.pre-prod.nl.toolstation.dev/api/customers/CWW02068816/purchase-history?page=1",
        "prev": null,
        "next": null
    },
    "meta": {
        "current_page": 1,
        "from": null,
        "last_page": 1,
        "links": [
            {
                "url": null,
                "label": "« Previous",
                "active": false
            },
            {
                "url": "https://ecom-api.gke.pre-prod.nl.toolstation.dev/api/customers/CWW02068816/purchase-history?page=1",
                "label": "1",
                "active": true
            },
            {
                "url": null,
                "label": "Next »",
                "active": false
            }
        ],
        "path": "https://ecom-api.gke.pre-prod.nl.toolstation.dev/api/customers/CWW02068816/purchase-history",
        "per_page": 50,
        "to": null,
        "total": 0
    }

}

Response Code: 403 Forbidden

Response:

{
    "error": {
        "code": "403.99",
        "message": "Forbidden",
        "info": "https://developers.example.com",
        "data": null
    }
}

Copyright © 2026