A PHP client library for CodesWholesale's API
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/codeswholesalev3/sdk
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ^6.3
- sainsburys/guzzle-oauth2-plugin: ^3.0
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\CodesWholesale; use CodesWholesale\Storage\SessionAuthTokenStorage; use CodesWholesale\Storage\FileContinuationTokenStorage; $params = [ '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 SessionAuthTokenStorage() ]; $client = new Client($params); $continuationStorage = new FileContinuationTokenStorage(__DIR__ . '/last_token.txt'); $continuationToken = $continuationStorage->getContinuationToken();
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');
Getter list for products
$product->getName(); $product->getPrices(); $product->getDefaultPrice(); $product->getStock(); $product->getPlatform(); $product->getRegions(); $product->getReleaseDate();
3. Create an order
use CodesWholesale\Resource\Order; $createdOrder = Order::createOrder($client, [ ['productId' => '6313677f-5219-47e4-a067-7401f55c5a3a', 'quantity' => 2] ]);
4. Retrieve account details
use CodesWholesale\Resource\Account; $accountDetails = Account::getCurrent($client);
Getter list for the current account
$accountDetails->getBalance();