encoderuz / uzpost-php
Uzpost integration package for php
Requires
- php: >=8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.9
Requires (Dev)
- pestphp/pest: ^3.7
This package is auto-updated.
Last update: 2025-04-13 11:15:15 UTC
README
UzpostClient is a PHP client for interacting with the Uzpost API. It simplifies sending HTTP requests, managing authentication, and handling API responses.
Installation
composer require encoderuz/uzpost-php
Usage
For using UzpostClient api requests you need token. For getting token you don't need api_key. You just use this case:
$token = UzpostClient::token("your_username", "your_password"); $client = new UzpostClient($token);
Methods
token(string $username, string $password): string
Authenticates a user and retrieves an authentication token.
$username
(string): User's login username.
$password
(string): User's password.
Returns (string): JWT authentication token.
Example:
$token = UzpostClient::token('your-username', 'your-password');
get_result(): array
- Returns the result of the last API request.
- Returns (array): API response data.
send_request(string $method, string $endpoint, array $params = [], string $api_version = 'v1'): UzpostClient
-
Sends an HTTP request to the Uzpost API.
-
$method
(string): HTTP method (GET, POST, etc.). -
$endpoint
(string): API endpoint. -
$params
(array): Request parameters. -
$api_version
(string): API version. Default is v1. -
Returns (UzpostClient): The current instance with the response stored in result.
Example:
$response = $client->send_request('GET', 'tracking/123456'); $result = $client->get_result();
Services
2. CustomerService
Handles authentication and customer-related operations.
Usage:
$customerService = new CustomerService($client);
Read more about CustomerService
3. JurisdictionService
Retrieves jurisdiction-related data.
Usage:
$jurisdictionService = new JurisdictionService($client);
Read more about JurisdictionService
4. OrderService
Handles order tracking, retrieval, creation, and cancellation.
Usage:
$orderService = new OrderService($client);
5. PricingService
Fetches package pricing and service types.
Usage:
$pricingService = new PricingService($client);
Read more about PricingService
Exception Handling
All methods in these services throw UzpostException
in case of API request failure.
Example:
try { $orders = $orderService->get_customer_orders(1, 10); } catch (UzpostException $e) { echo "Error: " . $e->getMessage(); }
License
This package is open-source and available under the MIT License.