1. Go to this page and download the library: Download puleeno/nhanh-vn-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
puleeno / nhanh-vn-sdk example snippets
use Puleeno\NhanhVn\Client\NhanhClientBuilder;
// Tạo client với Builder Pattern
$client = NhanhClientBuilder::create()
->withAppId('your_app_id_here') // ID ứng dụng từ Nhanh.vn
->withBusinessId('your_business_id_here') // ID doanh nghiệp
->withAccessToken('your_access_token_here') // Token truy cập
->withEnvironment('production') // Môi trường: 'production' hoặc 'sandbox'
->withTimeout(30) // Timeout cho API calls (giây)
->build();
// Hoặc sử dụng convenience methods
$client = NhanhClientBuilder::createBasic(
'your_app_id_here',
'your_business_id_here',
'your_access_token_here'
);
// Cho development
$client = NhanhClientBuilder::createDevelopment(
'your_app_id_here',
'your_business_id_here',
'your_access_token_here'
);
use Puleeno\NhanhVn\Client\NhanhVnClient;
use Puleeno\NhanhVn\Config\ClientConfig;
// Tạo cấu hình client
$config = new ClientConfig([
'appId' => 'your_app_id_here', // ID ứng dụng từ Nhanh.vn
'businessId' => 'your_business_id_here', // ID doanh nghiệp
'accessToken' => 'your_access_token_here', // Token truy cập
'environment' => 'production', // Môi trường: 'production' hoặc 'sandbox'
'timeout' => 30 // Timeout cho API calls (giây)
]);
// Khởi tạo client singleton
$client = NhanhVnClient::getInstance($config);
// Lấy access token từ Nhanh.vn
$oauthModule = $client->oauth();
// Thực hiện OAuth flow
$authUrl = $oauthModule->getAuthorizationUrl([
'scope' => 'read write',
'state' => 'random_state_string'
]);
// Xử lý callback và lấy access token
$token = $oauthModule->handleCallback($code);
// Tìm kiếm tất cả khách hàng
$customers = $client->customers()->getAll(1, 20);
// Tìm kiếm khách hàng theo ID
$customer = $client->customers()->searchById(12345);
// Tìm kiếm khách hàng theo số điện thoại
$customer = $client->customers()->searchByMobile('0987654321');
// Lấy khách hàng theo loại (lẻ, sỉ, đại lý)
$retailCustomers = $client->customers()->getRetailCustomers(1, 10);
$wholesaleCustomers = $client->customers()->getWholesaleCustomers(1, 10);
// Lấy khách hàng theo khoảng thời gian cập nhật
$customers = $client->customers()->getByDateRange(
'2024-01-01 00:00:00',
'2024-12-31 23:59:59',
1,
20
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.