laravel-vtung maintained by codejutsu1
laravel-vtung
An Elegant Laravel Package for vtu.ng
Installation
PHP 8.2+ and Composer are required.
-
Install the package via composer:
composer require codejutsu1/laravel-vtung -
Optionalyou can publish the config file via this command:php artisan vtung:installA configuration file named
vtung.phpwill be placed in theconfigfolder of your laravel application:<?php // config for Codejutsu1/LaravelVtuNg return [ /** * VTU username * */ 'username' => env('VTU_USERNAME') ?? null, /** * VTU Password * */ 'password' => env('VTU_PASSWORD') ?? null, ];
Usage
Open your .env file and add your username and password:
VTU_USERNAME=
VTU_PASSWORD=
[!IMPORTANT] You must have a reseller account with vtu.ng to use our API.
Services
- Wallet Balance
- Airtime
- Data
- Customer Verification
- CableTv
- Electricity
- Format Number
- Network Provider
Check your wallet balance
<?php
try{
$response = vtu()->getBalance();
$balance = $response['data']['balance'];
return $balance;
}catch(\Exception $e){
return redirect()->back()->withMessage($e->getMessage());
}
Buy Airtime
It requires 3 parameters as an array to make airtime purchase from vtu.ng
<?php
$data = [
'phone' => '09137822222', // Phone Number
'network_id' => 'mtn', // Network Provider
'amount' => 2000 //int Amount to recharge
];
try{
$response = Vtu::buyAirtime($data);
/**
* Alternatively, use:
*
* $response = vtu()->buyAirtime($data);
*/
}catch(\Exception $e){
return redirect()->back()->withMessage($e->getMessage());
}
if($response['code'] == 'success'){
//Your business logic here.
}
Format Number
You can also format Nigerian Number with +234 code to local number.
<?php
//Format +2349010344345 to 09010344345
try{
return Vtu::formatNumber('+2349010344345');
/**
* Alternatively, use:
*
* return vtu()->formatNumber('+2349010344345');
*/
}catch(\Exception $e){
return redirect()->back()->withMessage($e->getMessage());
}
Network Provider
This package gives you the power to get the network provider of any number in Nigeria.
<?php
try{
return Vtu::getNetworkProvider('+2349010344345');
/**
* Alternatively, use:
*
* return vtu()->getNetworkProvider('+2349010344345');
*/
}catch(\Exception $e){
return redirect()->back()->withMessage($e->getMessage());
}
[!NOTE] You can always use the class
Vtu::buyAirtime()or the helpervtu()->buyAirtime()
Buy Data
It requires 3 parameters as an array to make data purchase from vtu.ng
<?php
$data = [
'phone' => '09137822222', // Phone Number
'network_id' => 'mtn', // Network Provider
'variation_id' => 'mtn-75gb-15000' //variation id of the mobile data to purchase
];
try{
$response = Vtu::buyData($data);
/**
* Alternatively, use:
*
* $response = vtu()->buyData($data);
*/
}catch(\Exception $e){
return redirect()->back()->withMessage($e->getMessage());
}
if($response['code'] == 'success'){
//Your business logic here.
}
[!IMPORTANT] You can get the data
variation idfrom the vtu.ng
Verify Customers using their meter number and IUC/Smartcard Number
It requires 3 parameters as an array to verify a customer from vtu.ng
<?php
$data = [
'customer_id' => '62418234034', // Customer's smartcard number or meter number
'service_id' => 'gotv', // Unique id for all cable Tv and electricity services.
'variation_id' => 'prepaid' // Meter type of the electricity company, optional for cable Tvs.
];
try{
$response = Vtu::verifyCustomer($data);
/**
* Alternatively, use:
*
* $response = vtu()->verifyCustomer($data);
*/
}catch(\Exception $e){
return redirect()->back()->withMessage($e->getMessage());
}
if($response['code'] == 'success'){
//Your business logic here.
}
[!IMPORTANT] You can get the
service_idfrom vtu.ng. You can verify EEDC customers using theservice_idasenugu-electricbut you can't pay EEDC Electricity Bills with vtu.ng.
Purchase/Subscribe CableTv
It requires 4 parameters as an array to purchase or subscribe CableTv from vtu.ng
<?php
$data = [
'phone' => '09137822222', //Phone number stored for reference
'smartcard_number' => '62418234034', // Customer's smartcard/IUC number
'service_id' => 'gotv', // Unique id for all cable Tv.
'variation_id' => 'gotv-max' // Variation ID for cable package.
];
try{
$response = Vtu::subscribeTv($data);
/**
* Alternatively, use:
*
* $response = vtu()->subscribeTv($data);
*/
}catch(\Exception $e){
return redirect()->back()->withMessage($e->getMessage());
}
if($response['code'] == 'success'){
//Your business logic here.
}
[!IMPORTANT] You can get the
service_idandvariation_idfrom vtu.ng.
Pay Electricity Bills
To purchase, it requires 5 parameters as an array to pay electricity bills from vtu.ng
<?php
$data = [
'phone' => '09137822222', //Phone number stored for reference
'meter_number' => '62418234034', // Customer's meter number
'service_id' => 'ikeja-electric', // Unique id for electricity companies.
'variation_id' => 'prepaid', // meter type, either prepaid or postpaid.
'amount' => 8000, //amount of electricity you want to purchase.
];
try{
$response = Vtu::buyElectricity($data);
/**
* Alternatively, use:
*
* $response = vtu()->buyElectricity($data);
*/
}catch(\Exception $e){
return redirect()->back()->withMessage($e->getMessage());
}
if($response['code'] == 'success'){
//Your business logic here.
}
[!IMPORTANT] As usual, you can get the
service_idandvariation_idfrom vtu.ng.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Feel free to submit Issues (for bugs or suggestions) and Pull Requests(to the 1.x branch).
Security Vulnerabilities
If you discover a security vulnerability within this package, please send an email to Daniel Dunu at danieldunu001@gmail.com. All security vulnerabilities will be promptly addressed..
Credits
License
The MIT License (MIT). Please see License File for more information.