PHP code example of hen8y / laravel-vpay

1. Go to this page and download the library: Download hen8y/laravel-vpay 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/ */

    

hen8y / laravel-vpay example snippets


'providers' => [
    ...
    Hen8y\Vpay\VpayServiceProvider::class,
    ...
]


    php artisan vendor:publish --tag=vpay-config


    /payment/webhook/vpay
 





return [

    /*
    |--------------------------------------------------------------------------
    | Status of Your Applicatiom 
    |--------------------------------------------------------------------------
    |
    | Here you may specify what is the status pf your app
    | Options("live", "sandbox")
    | By leaving this empty field empty would by default use sandbox
    |
    */
    "status"=> env("VPAY_STATUS","sandbox"),

    /*
    |--------------------------------------------------------------------------
    | Public Key 
    |--------------------------------------------------------------------------
    |
    | Enter the public key gotten from vpay website 
    |
    */
    "public_id"=> env("VPAY_PUBLICID"),

    /*
    |--------------------------------------------------------------------------
    | Public Key 
    |--------------------------------------------------------------------------
    |
    | Enter the secret key gotten from vpay website
    |
    */
    "secret_key"=> env("VPAY_SECRET"),

    /*
    |--------------------------------------------------------------------------
    | Customer Care Email Address 
    |--------------------------------------------------------------------------
    |
    | Here specify the customer service & support channels of your business 
    | e.g. Tel: +2348030070000, Email: [email protected]
    |
    */
    "customer_service_channel"=> env("MERCHANT_EMAIL"),

    /*
    |--------------------------------------------------------------------------
    | Customer Care Support Logo 
    |--------------------------------------------------------------------------
    |
    | Here specify a link to your customer support logo
    |
    */
    "customer_logo"=>"",


    /*
    |--------------------------------------------------------------------------
    | Transaction Type 
    |--------------------------------------------------------------------------
    |
    | Here specify your transaction type,
    | Options("percentage","flat")
    |
    | if chose percentage you can edit the percent 

    protected $except = [
        //

        "/payment/webhook/vpay",
    ];


VPAY_PUBLICID=xxxxxxxx
VPAY_SECRET=xxxxxxxx
VPAY_STATUS=sandbox
[email protected]

Route::post('/payment/redirect', [\App\Http\Controllers\PaymentController::class,'redirectToGateway']);

Route::post('/payment/callback', [\App\Http\Controllers\PaymentController::class,'callback']);




namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Hen8y\Vpay\Vpay;




class PaymentController extends Controller
{

    /**
     * Redirect the User to Checkout Page
     */
    public function redirectToGateway()
    {

        // Sends the transaction data to the checkout handler
        $data = array(
            'amount'=> request("amount"),
            "email"=>request("email"),
            "transactionref"=> \Str::random(25),
        );
        return (new Vpay)->handleCheckout($data);
    }


    /**
     * Callback
     *
     * @param Request $request
     */
     public function callback(Request $request){
        // This will give you all the data sent in the POST request
        // Now you can access individual data elements like $data['status'], $data['amount'], etc.

        // if successfull $request->input('status') will return success

        // if failed $request->input('status') will return failed

        $status = $request->input('status');
        $amount = $request->input('amount');
        $transactionref = $request->input('transactionref');
        $email = $request->input('email');

        // Use the retrieved data as needed
    }


}





namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Log;

class VpayJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     */
    public function __construct(public $payload)
    {
        $this->payload = $payload;
    }

    /**
     * Execute the job.
     */
    public function handle()
    {
        if($this->payload["originator_account_name"] != "Failed Card Transaction" ){


            Log::info($this->payload);


            $transactionref = $this->payload['transactionref'];
            $amount = $this->payload['amount'];
            
             
             // Get the transaction with same transactionref and update status to be successfull
            // Increment the user balance by the amount
            
        }
    }
}




    php artisan queue:work
bash
php artisan vpay:publish