Skip to content

Latest commit

 

History

History
319 lines (236 loc) · 7.98 KB

README.md

File metadata and controls

319 lines (236 loc) · 7.98 KB

laravel-vtung

Latest Version on Packagist GitHub Tests Action Status License Total Downloads

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
  • Optional you can publish the config file via this command:

    php artisan vtung:install

    A configuration file named vtung.php will be placed in the config folder 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

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 helper vtu()->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 id from 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_id from vtu.ng. You can verify EEDC customers using the service_id as enugu-electric but 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_id and variation_id from 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_id and variation_id from 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.