PHPackages                             farzai/thailand-post - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. farzai/thailand-post

ActiveLibrary[API Development](/categories/api)

farzai/thailand-post
====================

2.0.0(2y ago)3112[3 PRs](https://github.com/parsilver/thailandpost-tracking-php/pulls)MITPHPPHP ^8.2CI passing

Since Oct 19Pushed 1mo agoCompare

[ Source](https://github.com/parsilver/thailandpost-tracking-php)[ Packagist](https://packagist.org/packages/farzai/thailand-post)[ GitHub Sponsors](https://github.com/parsilver)[ RSS](/packages/farzai-thailand-post/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (6)Dependencies (7)Versions (11)Used By (0)

Thailand Post Tracking
======================

[](#thailand-post-tracking)

[![Example CLI](assets/codeimage-snippet.png)](assets/codeimage-snippet.png)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e555ac831752ca3a5dea03fc58454f200c3c6501ec8d3f9d61e6bf0c118de6fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6661727a61692f746861696c616e642d706f73742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/farzai/thailand-post)[![Tests](https://camo.githubusercontent.com/abacadee79f1ffc9550cf2942370890763c746959fa705f70f74a5c0255b6f42/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70617273696c7665722f746861696c616e64706f73742d747261636b696e672d7068702f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/parsilver/thailandpost-tracking-php/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/21f939374cfcae9e3cef61ba74a73733e397e3ac3631102f5a40b20e8bdcee1d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6661727a61692f746861696c616e642d706f73742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/farzai/thailand-post)

PHP Library สำหรับ tracking พัสดุของไปรษณีย์ไทย อ้างอิงจากเว็บ APIs ของไปรษณีย์ไทย ซึ่ง Library ตัวนี้ทำหน้าที่ครอบ REST APIs ของทางไปรษณีย์ไทยอีกทีนึงเพื่อสะดวกในการใช้งาน

สิ่งที่ต้องการ
--------------

[](#สิ่งที่ต้องการ)

- PHP 8.2 ขึ้นไป
- API Key จากไปรษณีย์ไทย (สามารถสร้างได้ที่ )

การติดตั้ง
----------

[](#การติดตั้ง)

### ติดตั้งผ่าน Composer

[](#ติดตั้งผ่าน-composer)

การติดตั้งผ่าน Composer โดยใช้คำสั่งด้านล่าง

```
composer require farzai/thailand-post

```

เริ่มต้นใช้งาน
--------------

[](#เริ่มต้นใช้งาน)

ในการเริ่มต้นใช้งาน ท่านจำเป็นต้องมี API Key จากไปรษณีย์ไทยก่อน และนำมาใช้งานตามตัวอย่างด้านล่าง หากท่านต้องการทราบวิธีการสร้าง API Key สามารถดูได้ที่ [![Example API Token](assets/screeenshot-dashboard.png)](assets/screeenshot-dashboard.png)

### ส่วนของ REST APIs

[](#ส่วนของ-rest-apis)

```
use Farzai\ThaiPost\ClientBuilder;
use Farzai\ThaiPost\Endpoints\ApiEndpoint;

// สร้างตัวเชื่อมต่อ api
// โดยใช้ ClientBuilder ที่เราสร้างขึ้นมา เพื่อใช้ในการตั้งค่าต่างๆ
$client = ClientBuilder::create()
    // API Key ที่ได้มาจากการ generate ผ่านหน้าเว็บของไปรษณีย์ไทย
    ->setCredential('YOUR_API_KEY')

    // (Optional) ตั้งค่าที่จัดเก็บ Token ที่ได้มาจากการเรียก API
    // โดยท่านต้อง Implement \Farzai\ThaiPost\Contracts\StorageRepositoryInterface ให้เรียบร้อย
    // ->setStorage(new YourStorageRepository())

    // (Optional) ตั้งค่า Http Client ที่ท่านต้องการใช้งาน
    // ->setHttpClient(new \GuzzleHttp\Client())

    // (Optional) ตั้งค่า Logger ที่ท่านต้องการใช้งาน
    // ->setLogger(new \Monolog\Logger('thai-post'))

    // Build ตัวเชื่อมต่อ api
    ->build();

// เรียกใช้งานตัวเชื่อมต่อ api
$api = new ApiEndpoint($client);

try {
    // ส่งคำร้องขอเรื่อง ดึงสถานะของ barcode
    $response = $api->getItemsByBarcodes([
        'barcode' => ['EY145587896TH', 'RC338848854TH'],
    ]);
} catch (InvalidApiTokenException $e) {
    // กรณีที่ API Token ไม่ถูกต้อง
    exit($e->getMessage());
}

// คุณสามารถนำ json response มาใช้งานได้จากคำสั่งด้านล่างได้เลย
$array = $response->json();

// หรือ ต้องการเข้าไปยัง path ของ json
$countNumber = $response->json('response.track_count.count_number');
```

#### คำสั่งอื่นๆ ที่สามารถใช้งานได้ สำหรับ REST APIs

[](#คำสั่งอื่นๆ-ที่สามารถใช้งานได้-สำหรับ-rest-apis)

- ดึงข้อมูลสถานะของ barcode ที่ต้องการ

```
$response = $api->getItemsByBarcodes([
    'barcode' => ['EY145587896TH', 'RC338848854TH'],

    // Options
    'status' => 'all',
    'language' => 'TH',
]);
```

- ดึงข้อมูลสถานะตามหมายเลขใบเสร็จที่ต้องการ

```
$response = $api->getItemsByReceipts([
    'receiptNo' => ['RC338848854TH'],

    // Options
    'status' => 'all',
    'language' => 'TH',
]);
```

- สร้าง Access Token สำหรับใช้งาน Rest APIs

```
$response = $api->generateAccessToken();
```

---

### ส่วนของ Webhook APIs

[](#ส่วนของ-webhook-apis)

```
use Farzai\ThaiPost\ClientBuilder;
use Farzai\ThaiPost\Endpoints\WebhookEndpoint;

$client = ClientBuilder::create()
    ->setCredential('YOUR_API_KEY')
    ->build();

$webhook = new WebhookEndpoint($client);

$response = $webhook->subscribeBarcodes([
    'barcode' => ['EY145587896TH', 'RC338848854TH'],
]);

// ตรวจสอบว่าทำงานถูกต้องหรือไม่
if ($response->isSuccessfull() && $response->json('status') === true) {
    $returnedJson = $response->json();

    // Or
    $message = $response->json('message');
    $items = $response->json('response.items');
    $trackCount = $response->json('response.track_count.count_number');
}
```

#### คำสั่งอื่นๆ ที่สามารถใช้งานได้ สำหรับ Webhook APIs

[](#คำสั่งอื่นๆ-ที่สามารถใช้งานได้-สำหรับ-webhook-apis)

- สร้าง Webhook สำหรับติดตาม barcode ที่ต้องการ

```
$response = $webhook->subscribeBarcodes([
    'barcode' => ['EY145587896TH', 'RC338848854TH'],

    // Options
    'status' => 'all',
    'language' => 'TH',
    'req_previous_status' => true,
]);
```

- สร้าง Webhook สำหรับติดตามหมายเลขใบเสร็จที่ต้องการ

```
$response = $webhook->subscribeReceipts([
    'receiptNo' => ['RC338848854TH'],

    // Options
    'status' => 'all',
    'language' => 'TH',
    'req_previous_status' => true,
]);
```

- ติดตามสถานะจาก Profile

```
$response = $webhook->subscribeByProfile([
    'fullName' => 'John Doe',
    'telephone' => '0123456789',

    // Options
    'email' => 'jonh@email.com',
    'nickname' => 'John',
]);
```

- ยกเลิกการติดตาม Profile

```
$response = $webhook->unsubscribeByProfile([
    'uid' => '1234567890',
    'ref' => '1234567890',
]);
```

---

Testing
-------

[](#testing)

```
$ composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/farzai/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [parsilver](https://github.com/parsilver)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance60

Regular maintenance activity

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 63.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~177 days

Recently: every ~221 days

Total

6

Last Release

784d ago

Major Versions

0.1.0 → 1.0.02021-10-20

1.1.2 → 2.0.02024-03-24

PHP version history (2 changes)0.1.0PHP ^7.3|^8.0

2.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4928451?v=4)[parsilver](/maintainers/parsilver)[@parsilver](https://github.com/parsilver)

---

Top Contributors

[![parsilver](https://avatars.githubusercontent.com/u/4928451?v=4)](https://github.com/parsilver "parsilver (47 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (16 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (11 commits)")

---

Tags

emsphpthailandthailandposttracking

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/farzai-thailand-post/health.svg)

```
[![Health](https://phpackages.com/badges/farzai-thailand-post/health.svg)](https://phpackages.com/packages/farzai-thailand-post)
```

###  Alternatives

[kirschbaum-development/laravel-openapi-validator

Automatic OpenAPI validation for Laravel HTTP tests

581.1M5](/packages/kirschbaum-development-laravel-openapi-validator)[toshy/bunnynet-php

BunnyNet API client for PHP

61172.1k6](/packages/toshy-bunnynet-php)[antcool/easy-lark

PHP SDK for Lark

583.1k](/packages/antcool-easy-lark)[oxid-esales/graphql-base

OXID eSales GraphQL base module

24101.0k10](/packages/oxid-esales-graphql-base)[dariusiii/tmdb-laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

1821.1k](/packages/dariusiii-tmdb-laravel)[arbor-education/arbor-sdk-php

Arbor Education PHP SDK

116.8k](/packages/arbor-education-arbor-sdk-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
