|
| 1 | +# Lazada API PHP SDK — Modern PHP Client for Lazada Open Platform |
| 2 | + |
| 3 | +[](https://packagist.org/packages/ecomphp/lazada-php) |
| 4 | +[](https://packagist.org/packages/ecomphp/lazada-php) |
| 5 | +[](https://packagist.org/packages/ecomphp/lazada-php) |
| 6 | +[](https://packagist.org/packages/ecomphp/lazada-php) |
| 7 | + |
| 8 | +A powerful, lightweight, and developer-friendly **Lazada API PHP SDK** designed to integrate **Lazada Open Platform** into vanilla PHP applications, Laravel, or Symfony projects. |
| 9 | + |
| 10 | +Easily manage Lazada OAuth authentication, automate access token generation, refresh tokens, sync products, fetch orders, and call seller APIs with minimal configuration. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## 📦 Installation |
| 15 | + |
| 16 | +Install the **Lazada PHP Client** via [Composer](https://getcomposer.org/): |
| 17 | + |
| 18 | +```shell |
| 19 | +composer require ecomphp/lazada-php |
| 20 | +``` |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## 🛠️ Configuration & Setup |
| 25 | + |
| 26 | +Initialize the **Lazada Client** using your app credentials provided by the Lazada Open Platform Console: |
| 27 | + |
| 28 | +```php |
| 29 | +use EcomPHP\Lazada\Client; |
| 30 | + |
| 31 | +$app_key = 'your_app_key_here'; |
| 32 | +$app_secret = 'your_app_secret_here'; |
| 33 | +$callback_url = 'https://your-app.com/lazada/callback'; |
| 34 | + |
| 35 | +$client = new Client($app_key, $app_secret, $callback_url); |
| 36 | +``` |
| 37 | + |
| 38 | +The SDK supports Lazada regions: `vn`, `sg`, `my`, `th`, `ph`, and `id`. |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## 🔐 Lazada API OAuth Authentication |
| 43 | + |
| 44 | +The SDK provides a dedicated `Auth` class to handle Lazada's OAuth authorization flow, access tokens, and refresh tokens. |
| 45 | + |
| 46 | +```php |
| 47 | +$auth = $client->auth(); |
| 48 | +``` |
| 49 | + |
| 50 | +### Step 1: Create the Authentication Request URL |
| 51 | + |
| 52 | +Generate the authorization redirect URL for the seller to grant permissions: |
| 53 | + |
| 54 | +```php |
| 55 | +$state = 'your-csrf-or-tracking-state'; |
| 56 | +$country = 'vn'; // Optional: vn, sg, my, th, ph, id |
| 57 | + |
| 58 | +// Returns the Lazada authentication URL instead of auto-redirecting |
| 59 | +$authUrl = $auth->createAuthRequest($state, $country, true); |
| 60 | + |
| 61 | +// Redirect user to Lazada Authorization page |
| 62 | +header('Location: ' . $authUrl); |
| 63 | +exit; |
| 64 | +``` |
| 65 | + |
| 66 | +### Step 2: Handle Redirect Callback & Fetch Access Token |
| 67 | + |
| 68 | +Once authorized, Lazada redirects the user back to your callback URL with an authorization code. Exchange it for your API tokens: |
| 69 | + |
| 70 | +```php |
| 71 | +$authorization_code = $_GET['code']; |
| 72 | + |
| 73 | +// Exchange code for Access Token & Refresh Token |
| 74 | +$token = $auth->getToken($authorization_code); |
| 75 | + |
| 76 | +$access_token = $token['access_token']; |
| 77 | +$refresh_token = $token['refresh_token']; |
| 78 | + |
| 79 | +// IMPORTANT: Save your access_token, refresh_token, and seller region to your database for later use |
| 80 | +``` |
| 81 | + |
| 82 | +### Step 3: Set Authorized Seller Credentials |
| 83 | + |
| 84 | +To make authorized calls on behalf of a specific seller, attach the access token and region to your client instance: |
| 85 | + |
| 86 | +```php |
| 87 | +$access_token = 'your_stored_access_token'; |
| 88 | +$region = 'vn'; |
| 89 | + |
| 90 | +$client->setAccessToken($access_token, $region); |
| 91 | +``` |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## 🔄 Refreshing Expired Access Tokens |
| 96 | + |
| 97 | +Lazada access tokens expire. Automate token renewal using your persistent `refresh_token`: |
| 98 | + |
| 99 | +```php |
| 100 | +$new_token = $auth->refreshNewToken($refresh_token); |
| 101 | + |
| 102 | +$new_access_token = $new_token['access_token']; |
| 103 | +$new_refresh_token = $new_token['refresh_token']; |
| 104 | +``` |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## 🚀 Lazada API Usage Examples |
| 109 | + |
| 110 | +> **Note:** A valid `access_token` and seller `region` are required to interact with seller-level data. |
| 111 | +
|
| 112 | +### 1. Get Product List |
| 113 | + |
| 114 | +Fetch product information from your Lazada store: |
| 115 | + |
| 116 | +```php |
| 117 | +$products = $client->Product->GetProducts([ |
| 118 | + 'offset' => 0, |
| 119 | + 'limit' => 50, |
| 120 | + 'filter' => 'all', |
| 121 | +]); |
| 122 | +``` |
| 123 | + |
| 124 | +### 2. Get Product Item |
| 125 | + |
| 126 | +Retrieve a single product by Lazada item ID: |
| 127 | + |
| 128 | +```php |
| 129 | +$product = $client->Product->GetProductItem('123456789'); |
| 130 | +``` |
| 131 | + |
| 132 | +### 3. Get Order List & Order Items |
| 133 | + |
| 134 | +Retrieve recent orders and their order items: |
| 135 | + |
| 136 | +```php |
| 137 | +$orders = $client->Order->GetOrders([ |
| 138 | + 'created_after' => '2026-07-01T00:00:00+0800', |
| 139 | + 'status' => 'pending', |
| 140 | +]); |
| 141 | + |
| 142 | +$orderItems = $client->Order->GetOrderItems('123456789'); |
| 143 | +``` |
| 144 | + |
| 145 | +### 4. Update Order Status to Ready to Ship |
| 146 | + |
| 147 | +Set order items as ready to ship: |
| 148 | + |
| 149 | +```php |
| 150 | +$result = $client->Order->SetStatusToReadyToShip( |
| 151 | + ['123456789'], |
| 152 | + 'Dropshipping Provider', |
| 153 | + 'TRACKING_NUMBER' |
| 154 | +); |
| 155 | +``` |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +## 🧩 Available API Resources |
| 160 | + |
| 161 | +The client exposes Lazada API groups as resource properties, including: |
| 162 | + |
| 163 | +- `System` |
| 164 | +- `Seller` |
| 165 | +- `Order` |
| 166 | +- `Finance` |
| 167 | +- `Product` |
| 168 | +- `ProductReview` |
| 169 | +- `StoreDecoration` |
| 170 | +- `MediaCenter` |
| 171 | +- `Flexicombo` |
| 172 | +- `SellerVoucher` |
| 173 | +- `FreeShipping` |
| 174 | +- `ReturnAndRefund` |
| 175 | +- `Fulfillment` |
| 176 | +- `Logistic` |
| 177 | +- `LazadaLogistics` |
| 178 | +- `Wallet` |
| 179 | +- `SponsoredSolutions` |
| 180 | +- `ServiceMarket` |
| 181 | +- `LazLive` |
| 182 | +- `Content` |
| 183 | + |
| 184 | +Example: |
| 185 | + |
| 186 | +```php |
| 187 | +$categoryTree = $client->Product->GetCategoryTree(); |
| 188 | +$sellerInfo = $client->Seller->GetSeller(); |
| 189 | +``` |
| 190 | + |
| 191 | +--- |
| 192 | + |
| 193 | +## 🧪 Testing |
| 194 | + |
| 195 | +Run the test suite with Composer: |
| 196 | + |
| 197 | +```shell |
| 198 | +composer test |
| 199 | +``` |
| 200 | + |
| 201 | +--- |
| 202 | + |
| 203 | +## 🤝 Contributing |
| 204 | + |
| 205 | +Contributions, feature suggestions, and bug reports for the **ecomphp/lazada-php** client are highly appreciated. Feel free to open issues or submit Pull Requests! |
| 206 | + |
| 207 | +## 📄 License |
| 208 | + |
| 209 | +This project is open-source software licensed under the [Apache License 2.0](LICENSE). |
0 commit comments