A PHP client library for CodesWholesale's API
1.0.0
2025-09-04 10:24 UTC
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ^6.3
- sainsburys/guzzle-oauth2-plugin: ^3.0
This package is not auto-updated.
Last update: 2025-09-05 08:48:27 UTC
README
A simple and lightweight PHP SDK for interacting with the CodesWholesale API V3.
Designed in an object-oriented style inspired by the V2 SDK, with support for:
Features
-
Authentication & Token Management
- Automatic OAuth2 client credentials flow.
- Token storage via session or custom storage implementation.
- Automatic token renewal when expired.
-
Product Management
- Fetch all products with optional callback handling for large datasets.
- Retrieve specific products by ID.
- Access product codes (text or image) through structured objects.
-
Order Management
- Create new orders with multiple products.
- Retrieve orders and their status.
- Access ordered products as structured objects with codes.
-
Clean, Extensible Architecture
- Namespaced classes under
CodesWholesale\Resource
andCodesWholesale\Storage
. - Client class handles all HTTP requests and authentication.
- Fully object-oriented with typed properties and methods.
- Exception handling for HTTP and authentication errors.
- Namespaced classes under
Requirements
- PHP 7.4+
- cURL extension enabled
Usage
1. Initialize the Client
use CodesWholesale\Client; use CodesWholesale\Storage\TokenSessionStorage; // Initialize the client $client = new Client([ 'cw.client_id' => 'your-client-id', 'cw.client_secret' => 'your-client-secret', 'cw.endpoint_uri' => CodesWholesale::SANDBOX_ENDPOINT, // or LIVE_ENDPOINT, 'cw.token_storage' => new TokenSessionStorage(), ]);
2. Retrieve Products
use CodesWholesale\Resource\Product; // Get all products $products = Product::getAll($client); // Get a product by ID $product = Product::getById($client, 'PRODUCT_ID');