PHP code example of laraditz / courier-jt-express

1. Go to this page and download the library: Download laraditz/courier-jt-express 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/ */

    

laraditz / courier-jt-express example snippets


return [
    'api_account'   => env('JTEXPRESS_API_ACCOUNT'),
    'private_key'   => env('JTEXPRESS_PRIVATE_KEY'),
    'customer_code' => env('JTEXPRESS_CUSTOMER_CODE'),
    'password'      => env('JTEXPRESS_PASSWORD'),
    'sandbox'       => env('JTEXPRESS_SANDBOX', false),
    'base_url'      => 'https://ylopenapi.jtexpress.my/webopenplatformapi/api',
    'sandbox_url'   => 'https://demoopenapi.jtexpress.my/webopenplatformapi/api',
    'timeout'       => 30,
];

use Laraditz\Courier\Facades\Courier;
use Laraditz\Courier\DTOs\Shared\Address;
use Laraditz\Courier\DTOs\Shared\Parcel;
use Laraditz\Courier\DTOs\Payloads\ShipmentPayload;

$result = Courier::driver('jtexpress')->createShipment(new ShipmentPayload(
    sender: new Address(
        name: 'J&T sender',
        phone: '+60123456789',
        email: null,
        line1: 'No 32, Jalan Kempas 4',
        line2: null,
        line3: null,
        city: 'Bandar Penawar',
        state: 'Johor',
        postcode: '81930',
        country: 'MY',
    ),
    recipient: new Address(/* ... */),
    parcel: new Parcel(
        weight: 1.5,
        length: 20.0,
        width: 15.0,
        height: 10.0,
        declaredValue: 100.0,
        description: 'Goods',
        quantity: 1,
    ),
    serviceCode: 'EZ', // EX | EZ | FD | DO | JS
    reference: 'ORDER-001', // optional — a UUID is generated if omitted
));

$result->waybillNumber; // '630000491494' (J&T billCode)
$result->reference;     // 'ORDER-001' — persist this for cancelShipment()/getLabel() later

// Track
$tracking = Courier::driver('jtexpress')->track($result->waybillNumber);

// Cancel — 

public string  $billCode;
public ?string $txlogisticId;
public string  $scanTypeCode; // raw J&T code
public string  $mappedStatus; // normalised status (see table below)
public array   $raw;          // the raw scan detail

use Laraditz\Courier\JtExpress\Events\TrackingUpdated;

Event::listen(TrackingUpdated::class, function (TrackingUpdated $event) {
    // ...
});
bash
php artisan vendor:publish --tag=courier-config
php artisan vendor:publish --tag=courier-jt-express-config