- PHP >= 7.2
- A PSR-17 implementation
- A PSR-18 implementation
Via Composer.
This command will get you up and running quickly with a Guzzle HTTP client.
composer require vanthao03596/ghtk-sdk guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
We are decoupled from any HTTP messaging client with help by HTTPlug.
composer require vanthao03596/ghtk-sdk symfony/http-client nyholm/psr7
To set up the GHTK client with this HTTP client
use Symfony\Component\HttpClient\HttplugClient;
$client = Client::createWithHttpClient(new HttplugClient(), true);
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$fee = $client->api('shipment')
->calculateFee([
'pick_province' => 'Hà Nội',
'pick_district' => 'Quận Hai Bà Trưng',
'province' => 'Hà nội',
'district' => 'Quận Cầu Giấy',
'address' => 'P.503 tòa nhà Auu Việt, số 1 Lê Đức Thọ',
'weight' => 1000,
'value' => 3000000,
'transport' => 'fly',
'deliver_option' => 'xteam',
'tags' => [1]
]);
From $client
object, you have access to all available GHTK api endpoints.
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$client->api('order')->createOrder([
'products' => [
[
'name' => 'bút',
'weight' => 0.1,
'quantity' => 1,
'product_code' => '23304A3MHLMVMXX625'
],
[
'name' => 'tẩy',
'weight' => 0.2,
'quantity' => 1,
'product_code' => ''
]
],
'order' => [
'id' => 'a9',
'pick_name' => 'HCM-nội thành',
'pick_address' => '590 CMT8 P.11',
'pick_province' => 'TP. Hồ Chí Minh',
'pick_district' => 'Quận 3',
'pick_ward' => 'Phường 1',
'pick_tel' => '0911222333',
'tel' => '0911222333',
'name' => 'GHTK - HCM - Noi Thanh',
'address' => '123 nguyễn chí thanh',
'province' => 'TP. Hồ Chí Minh',
'district' => 'Quận 1',
'ward' => 'Phường Bến Nghé',
'hamlet' => 'Khác',
'is_freeship' => 1,
'pick_date' => '2016-09-30',
'pick_money' => 47000,
'note' => 'Khối lượng tính cước tối đa: 1.00 kg',
'value' => 3000000,
'transport' => 'fly',
'pick_option' =>'cod',
'deliver_option' => 'xteam',
'pick_session' => '2',
'tags' => [ 1],
'email' => '[email protected]',
'use_return_address' => 1
]
]);
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$client->api('shipment')->calculateFee([
'pick_province' => 'Hà Nội',
'pick_district' => 'Quận Hai Bà Trưng',
'province' => 'Hà nội',
'district' => 'Quận Cầu Giấy',
'address' => 'P.503 tòa nhà Auu Việt, số 1 Lê Đức Thọ',
'weight' => 1000,
'value' => 3000000,
'transport' => 'fly',
'deliver_option' => 'xteam',
'tags' => [1]
]));
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$client->api('order')->checkStatus('S1.A1.17373471');
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$client->api('order')->cancelOrder('S1.A1.17373471');
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$response = $client->api('order')->printLabel('S1.A1.17373471');
header('Content-type: application/pdf');
header('Content-disposition: attachment; filename=label.pdf');
header('Content-Transfer-Encoding: Binary');
echo $response;
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$client->api('shipment')->listPickAddress();
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$client->api('address')->getAddressLevel4([
'province' => 'Hà nội',
'district' => 'Quận Thanh Xuân',
'ward_street' => 'Định Công',
'address' => 'đường Đội Cấn, Ba Đình, Hà Nội',
]));
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$client->api('inventory')->getProductInfo([
'term' => 'laptop'
]));
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$client->api('shipment')->checkXteam([
"customer_district" => "Quận Ba Đình",
"customer_province" => "Hà Nội",
"customer_ward" => "Phường Đội Cấn",
"customer_first_address" => "12",
"pick_province" => "Hà Nội",
"pick_district" => "Quận Ba Đình",
"pick_ward" => "Phường Cống Vị"
]));
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$client->api('shop')->createShop([
"name" => "shop test",
"first_address" => "ngõ 2, Phan Bá Vành, Cầu Diễn",
"province" => "Hà Nội",
"district" => "Bắc Từ Liêm",
"tel" => "01234555666",
"email" => "[email protected]"
]);
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$client->api('shop')->getToken([
"email" => "[email protected]",
"password" => "1S@fF#K2",
]));
$plugin = new Http\Client\Common\Plugin\HeaderSetPlugin([
'X-Refer-Token' => 'B2CToken-hlsheiwquhrksadlfkjahsdfjaaljh',
]);
$builder = new Vanthao03596\GhtkSdk\HttpClient\Builder(new Http\Adapter\Guzzle7\Client);
$builder->addPlugin($plugin);
$client = new \Vanthao03596\GhtkSdk\Client(
$builder,
true
);
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
// Or use ReferToken plugin
$client = Vanthao03596\GhtkSdk\Client::createWithHttpClient(new Http\Adapter\Guzzle7\Client, true); // true is production mode
$client->authenticate('APITokenSample-ca441e70288cB0515F310742');
$client->setReferToken('B2CToken-hlsheiwquhrksadlfkjahsdfjaaljh');
....
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.