PHP code example of vanthao03596 / ghtk-sdk

1. Go to this page and download the library: Download vanthao03596/ghtk-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/ */

    

vanthao03596 / ghtk-sdk example snippets


use Symfony\Component\HttpClient\HttplugClient;

$client = Client::createWithHttpClient(new HttplugClient(), true);



// This file is generated by Composer
teWithHttpClient(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]
    ]);


$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');

....