Wrapper này mình viết để tiện cho việc gọi API sang hệ thống Alego.
Link Github
thienhaxanh2405 nguyenductoan2405@gmail.com
Qua composer: composer require thienhaxanh2405/alego-api-wrapper
Để sử dụng require_once "/path/to/vendor/autoload.php";
Bạn cần đăng ký tài khoản đại lý tại http://alego.vn. 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);
Khởi tạo một đối tượng \AlegoApiWrapper\Resource\Buy, cần tối thiểu các tham số
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);
Khởi tạo một đối tượng \AlegoApiWrapper\Resource\Buy, cần tối thiểu các tham số
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);
Cập nhật trong thời gian tới
Cập nhật trong thời gian tới
Cập nhật trong thời gian tới
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");
$res = $client->getBalance();
Test case sẽ được bổ sung trong thời gian tới
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: nguyenductoan2405@gmail.com.
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é =))
]]>