PHPackages                             thienhaxanh2405/alego-api-wrapper - 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. thienhaxanh2405/alego-api-wrapper

ActiveLibrary[API Development](/categories/api)

thienhaxanh2405/alego-api-wrapper
=================================

A Wrapper for Alego.vn

v1.1.0(8y ago)112MITPHP

Since Nov 20Pushed 8y ago1 watchersCompare

[ Source](https://github.com/thienhaxanh2405/alego-api-wrapper)[ Packagist](https://packagist.org/packages/thienhaxanh2405/alego-api-wrapper)[ RSS](/packages/thienhaxanh2405-alego-api-wrapper/feed)WikiDiscussions master Synced today

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Alego Api Wrapper
=================

[](#alego-api-wrapper)

Wrapper này mình viết để tiện cho việc gọi API sang hệ thống Alego.

Link [Github](https://github.com/thienhaxanh2405/alego-api-wrapper)

Tác giả
-------

[](#tác-giả)

thienhaxanh2405

Yêu cầu
-------

[](#yêu-cầu)

- PHP từ 5.4 đến 7.0 (Trong version tiếp theo của wrapper này sẽ cập nhật để hỗ trợ PHP 7.1 trở lên)
- Mcrypt ()

Cài đặt
-------

[](#cài-đặt)

Qua composer: `composer require thienhaxanh2405/alego-api-wrapper`

Để sử dụng `require_once "/path/to/vendor/autoload.php";`

Đối tượng (Object)
------------------

[](#đối-tượng-object)

- **\\AlegoApiWrapper\\Resource\\Buy** Đối tượng truyền tham số cho các giao dịch. Phụ thuộc vào từng giao dịch, các tham số cần truyền vào có thể khác nhau.
- **\\AlegoApiWrapper\\Resource\\ApiResponse** Đối tượng chứa các thông tin trả về cho mỗi giao dịch.
    - **message**: thông báo của giao dịch.
    - **messageCode**: mã thông báo.
    - **rawData**: dữ liệu thô được trả về từ API.
    - **result**: đối tượng chứa thông tin trả về sau khi đã được xử lý từ rawData. Có thể là ***\\AlegoApiWrapper\\Resource\\CardResult*** hoặc ***\\AlegoApiWrapper\\Resource\\Balance*** tùy thuộc vào giao dịch hiện tại.
- **\\AlegoApiWrapper\\Resource\\CardResult**: Chứa thông tin trả về khi mua thẻ điện thoại/topup/thẻ game/visa trả trước/kiểm tra giao dịch.
    - **productCode**: mã dịch vụ của Alego.
    - **$referOrder**: mã tham chiếu giao dịch trên hệ thống của bạn
    - **alegoTransactionId**: id của giao dịch tương ứng trên hệ thống Alego
    - **time**: thời gian giao dịch trên hệ thống Alego, định dạng unix timestamp.
    - **responseType**: Alego trả về kết quả thông qua: 1 - email; 2 - trực tiếp trong API.
    - **cardQuantity**: số lượng thẻ.
    - **cards**: mảng chứa thông tin thẻ hoặc mảng rỗng. Mỗi phần tử của mảng là một đối tượng ***\\AlegoApiWrapper\\Resource\\PrepaidCard*** hoặc Visa card trong tương lai khi wrapper hỗ trợ mua thẻ Visa trả trước.
- **\\AlegoApiWrapper\\Resource\\Balance**: Chứa thông tin số dư tài khoản đại lý.
    - **balance**: Tổng số dư.
    - **availableBalance**: Số dư khả dụng.
    - **frozenBalance**: Số dư bị đóng băng.
- **\\AlegoApiWrapper\\Resource\\PrepaidCard**: chứa thông tin thẻ cào điện thoại, game.
    - **code**: mã nạp thẻ.
    - **serial**: seri thẻ.
    - **expirationDate**: ngày hết hạn thẻ.

Hằng khai báo sẵn (Constant)
----------------------------

[](#hằng-khai-báo-sẵn-constant)

- **\\AlegoApiWrapper\\Constant\\AlegoProduct**: Mã sản phẩm/dịch vụ tương ứng trên hệ thống Alego.
- **\\AlegoApiWrapper\\Constant\\Telco**: Nhà mạng/mã nhà mạng di động.
- **\\AlegoApiWrapper\\Constant\\PrepaidCardPrice**: mệnh giá thẻ cào điện thoại.
- **\\AlegoApiWrapper\\Constant\\AlegoTransactionType**: Loại giao dịch trên hệ thống Alego.

Thông tin kết nối
-----------------

[](#thông-tin-kết-nối)

Bạn cần đăng ký tài khoản đại lý tại . Sử dụng thông tin kết nối để khởi tạo đối tượng Account.

```
use AlegoApiWrapper\Connection\Account;

// thông tin account bên dưới là tài khoản test của Alego
// thay thế bằng thông tin tài khoản của bạn
$account = new Account([
        'agentId' => 1,
        'accountId' => '571a01a0e4b0b96b6f950ad5',
        'keyMD5' => 'adrMjEJArHysrhwM',
        'tripleKey' => 'asdf'
    ]);

```

Khởi tạo đối tượng Client để thực hiện các giao dịch

```
use AlegoApiWrapper\Client;

$client = Client::createClient($account);
// Trường hợp trên môi trường Dev và muốn dump dữ liệu để debug
// truyền thêm 2 tham số isDevelopment và isDebug
// $client = Client::createClient($account, true, 1);

```

Sử dụng
-------

[](#sử-dụng)

### Mua thẻ cào điện thoại

[](#mua-thẻ-cào-điện-thoại)

Khởi tạo một đối tượng \\AlegoApiWrapper\\Resource\\Buy, cần tối thiểu các tham số

- **referOrder**: mã tham chiếu trên hệ thống của bạn, có thể là id hoặc một mã đơn hàng ***duy nhất*** trên hệ thống của bạn tương ứng với giao dịch này.
- **productCode**: mã sản phẩm dịch vủa Alego tương ứng với giao dịch mua thẻ cào. Đã được định nghĩa sẵn các hằng số trong ***AlegoApiWrapper\\Constant\\AlegoProduct*** để bạn có thể dễ dàng gọi và sử dụng.
- **telco**: mã nhà mạng. Đã được định nghĩa sẵn trong ***AlegoApiWrapper\\Constant\\Telco***.
- **cardPrice**: mệnh giá thẻ cào. Đã được định nghĩa sẵn trong ***AlegoApiWrapper\\Constant\\PrepaidCardPrice***.
- **cardQuantity**: số lượng thẻ cần mua (số nguyên)

Ví dụ mua 01 thẻ Viettel mệnh giá 100 000đ.

```
use AlegoApiWrapper\Constant\AlegoProduct;
use AlegoApiWrapper\Constant\Telco;
use AlegoApiWrapper\Constant\AlegoTransactionType;
use AlegoApiWrapper\Resource\Buy;
use AlegoApiWrapper\Constant\PrepaidCardPrice;

$buyCard = new Buy([
    'referOrder' => uniqid(),
    'productCode' => \AlegoApiWrapper\Constant\AlegoProduct::PREPAID_CARD_VIETTEL,
    'telco' => \AlegoApiWrapper\Constant\Telco::VIETTEL_CODE,
    'cardPrice' => \AlegoApiWrapper\Constant\PrepaidCardPrice::C_100,
    'cardQuantity' => 1
]);

$res = $client->buyPrepaidCard($buyCard);

```

### Nạp tiền điện thoại

[](#nạp-tiền-điện-thoại)

Khởi tạo một đối tượng \\AlegoApiWrapper\\Resource\\Buy, cần tối thiểu các tham số

- **referOrder**: mã tham chiếu trên hệ thống của bạn, có thể là id hoặc một mã đơn hàng ***duy nhất*** trên hệ thống của bạn tương ứng với giao dịch này.
- **productCode**: mã sản phẩm dịch vủa Alego tương ứng với giao dịch mua thẻ cào. Đã được định nghĩa sẵn các hằng số trong ***AlegoApiWrapper\\Constant\\AlegoProduct*** để bạn có thể dễ dàng gọi và sử dụng.
- **telco**: mã nhà mạng. Đã được định nghĩa sẵn trong ***AlegoApiWrapper\\Constant\\Telco***.
- **cardPrice**: mệnh giá thẻ cào. Đã được định nghĩa sẵn trong ***AlegoApiWrapper\\Constant\\PrepaidCardPrice***.
- **customerCellphone**: số điện thoại được nạp tiền
- **type**: loại giao dịch trên hệ thống Alego. Nạp tiền cho thuê bao trả trước: ***AlegoTransactionType::TOPUP\_PREPAID*** hoặc Nạp tiền cho thuê bao trả sau: ***AlegoTransactionType::TOPUP\_POSTPAID***

Ví dụ nạp tiền cho thuê bao: 0987 802 175 của nhà mạng Viettel số tiền 100 000đ.

```
use AlegoApiWrapper\Constant\AlegoProduct;
use AlegoApiWrapper\Constant\Telco;
use AlegoApiWrapper\Constant\AlegoTransactionType;
use AlegoApiWrapper\Resource\Buy;
use AlegoApiWrapper\Constant\PrepaidCardPrice;

$buy = new \AlegoApiWrapper\Resource\BuyPrepaidCard([
    'referOrder' => uniqid(),
    'productCode' => \AlegoApiWrapper\Constant\AlegoProduct::TOPUP_PREPAID_VIETTEL,
    'telco' => \AlegoApiWrapper\Constant\Telco::VIETTEL_CODE,
    'cardPrice' => \AlegoApiWrapper\Constant\PrepaidCardPrice::C_100,
    'customerCellphone' => "0987802175"
]);

$res = $client->prepaidTopUp($buy);

```

### Mua mã thẻ Game

[](#mua-mã-thẻ-game)

Khởi tạo đối tượng \\AlegoApiWrapper\\Resource\\Buy, cần tối thiểu các tham số

- **referOrder**: mã tham chiếu trên hệ thống của bạn, có thể là id hoặc một mã đơn hàng ***duy nhất*** trên hệ thống của bạn tương ứng với giao dịch này.
- **productCode**: mã sản phẩm dịch vủa Alego tương ứng với giao dịch mua thẻ game. Đã được định nghĩa sẵn các hằng số trong ***AlegoApiWrapper\\Constant\\AlegoProduct*** để bạn có thể dễ dàng gọi và sử dụng.
- **cardPrice**: mệnh giá thẻ cào. Với mỗi nhà cung cấp, mệnh giá có thể khác nhau, vui lòng xem thêm mệnh giá trong tài liệu hướng dẫn của Alego. Để tiện sử dụng, có thể sử dụng ***AlegoApiWrapper\\Constant\\PrepaidCardPrice***.
- **cardQuantity**: số lượng thẻ cần mua (số nguyên)

Ví dụ mua mã thẻ FPT Gate mệnh giá 100.000đ

```
use AlegoApiWrapper\Constant\AlegoProduct;
use AlegoApiWrapper\Resource\Buy;
use AlegoApiWrapper\Constant\PrepaidCardPrice;

$buy = new \AlegoApiWrapper\Resource\BuyPrepaidCard([
    'referOrder' => uniqid(),
    'productCode' => \AlegoApiWrapper\Constant\AlegoProduct::GAME_PREPAID_CARD_GATE,
    'cardPrice' => \AlegoApiWrapper\Constant\PrepaidCardPrice::C_100,
    'cardQuantity' => 1,
]);

$res = $client->buyGamePrepaidCard($buy);

```

### Mua thẻ Visa trả trước

[](#mua-thẻ-visa-trả-trước)

Cập nhật trong thời gian tới

### Mua thẻ Battle Net

[](#mua-thẻ-battle-net)

Cập nhật trong thời gian tới

### Kiểm tra giao dịch

[](#kiểm-tra-giao-dịch)

Sử dụng mã referOrder trên hệ thống của bạn để tham chiếu tới giao dịch trên hệ thống Alego.

Ví dụ bạn kiểm tra có mã trên hệ thống của bạn là: ***order\_5a119e3c6cfb0***

```
$res = $client->checkOrder("5a119e3c6cfb0");

```

### Kiểm tra số dư tài khoản

[](#kiểm-tra-số-dư-tài-khoản)

```
$res = $client->getBalance();

```

Tests
-----

[](#tests)

Test case sẽ được bổ sung trong thời gian tới

Hỗ trợ - giải đáp thắc mắc
--------------------------

[](#hỗ-trợ---giải-đáp-thắc-mắc)

Wrapper vẫn còn nhiều thiếu sót hoặc bug mà mình chưa tìm ra, các bạn vui lòng tạo issue hoặc liên hệ mình qua email: .

License
-------

[](#license)

Mình viết Wrapper này để phục vụ mục đích công việc cá nhân, tuy nhiên mình cũng không ngần ngại việc công khai và chia sẻ source này. Rất mong wrapper này sẽ có một chút hữu ích nào đó cho công việc của các bạn.

Mọi việc chia sẻ, góp ý, phân phối lại source này vui lòng theo giấy phép MIT.

*Trường hợp các bạn cứ thế lấy và sử dụng, cho vào project.... mà không theo giấy phép MIT thì mình cũng vẫn chào đón nhé =))*

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~21 days

Total

2

Last Release

3074d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bc62904a5785161395595085af952d66f1f0e1550be120575a239f61d68784c6?d=identicon)[thienhaxanh2405](/maintainers/thienhaxanh2405)

---

Top Contributors

[![thienhaxanh2405](https://avatars.githubusercontent.com/u/6769585?v=4)](https://github.com/thienhaxanh2405 "thienhaxanh2405 (31 commits)")

### Embed Badge

![Health badge](/badges/thienhaxanh2405-alego-api-wrapper/health.svg)

```
[![Health](https://phpackages.com/badges/thienhaxanh2405-alego-api-wrapper/health.svg)](https://phpackages.com/packages/thienhaxanh2405-alego-api-wrapper)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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