A PHP client library for CodesWholesale's API
1.1.1
2026-04-09 16:03 UTC
Requires
- php: >=7.4.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\ResourceandCodesWholesale\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
Installation
composer require codeswholesalev3/sdk
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; use CodesWholesale\Resource\ProductItem; // Process all products page by page Product::getAll( $client, function (array $items, ?string $nextContinuationToken): void { foreach ($items as $item) { $product = new ProductItem($item); echo $product->getName() . PHP_EOL; } }, $continuationToken ); // 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();