PHP code example of codejutsu1 / laravel-vtung

1. Go to this page and download the library: Download codejutsu1/laravel-vtung library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codejutsu1 / laravel-vtung example snippets


    

    // config for Codejutsu1/LaravelVtuNg
    return [
        /**
         * VTU username
         * 
         */
        'username' => env('VTU_USERNAME') ?? null,
        /**
         * VTU Password
         * 
         */
        'password' => env('VTU_PASSWORD') ?? null,
    ];

    

 

try{
    $response = vtu()->getBalance();

    $balance = $response['data']['balance'];

    return $balance;
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}




$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  +2349010344345 to 09010344345

try{
    return Vtu::formatNumber('+2349010344345');
    
    /**
     * Alternatively, use:
     * 
     * return vtu()->formatNumber('+2349010344345');
     */    
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}



try{
    return Vtu::getNetworkProvider('+2349010344345');

    /**
     * Alternatively, use:
     * 
     * return vtu()->getNetworkProvider('+2349010344345');
     */    
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}



$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.
}




$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.
}




$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.
}




$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.
}

bash
    php artisan vtung:install