nicholasmt/switchappgo-library

This is a Laravel library package for switchApp Api

dev-main 2023-06-06 11:07 UTC

This package is auto-updated.

Last update: 2024-09-06 13:40:44 UTC


README

Laravel Package

This is a laravel library package for SwitchApp Api payment engine.

To get Started Run

composer require nicholasmt/switchappgo-library

Note: if You encounter this or any other error which means you are using the old version of that package

Your requirements could not be resolved to an installable set of packages.

To Resolve simply run


 composer update
 

After successfull composer update then install the package again with composer require nicholasmt/zoom_library

Note: if you encounter any error based on poor network on updating composer,

just backup the vender file, delete and run composer update again with composer update

Configuire .env file as below:

SWITCHAPP_SECRET_KEY = "your switchapp secret key"

Create a Controller

php artisan make:controller SwitchAppController

Require Package using:

use Nicholasmt\Switchappgo\Switchappgo;

To verify transaction using the API callback use the code below

     
        $tx_ref = $request->query('tx_ref');
        $switchapp = new Switchappgo();
        $transaction_response = $switchapp->SwitchappAPI('GET', 'https://api.switchappgo.com/v1/transactions/verify/'.$tx_ref, false);
        $response = json_decode($transaction_response);
       
        if($response->status == 'success')
        {
             //code here
              
         }
        else
        {
           //code here
        }
           

Then Finally Setup callback Route

Route::get('switchapp', [App\Http\Controllers\SwitchAppController::class, 'switchappCallback'])->name('switchappgo');

What the Controller will look like:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Nicholasmt\Switchappgo\Switchappgo;

class SwitchAppController extends Controller
{
    
    public function switchappCallback(Request $request)
    {
    
        $tx_ref = $request->query('tx_ref');
        $switchapp = new Switchappgo();
        $transaction_response = $switchapp->SwitchappAPI('GET', 'https://api.switchappgo.com/v1/transactions/verify/'.$tx_ref, false);
         $response = json_decode($transaction_response);
        
        if($response->status == 'success')
        {
             //code here
             
         }
        else
        {
          //code here
        }
    }

}

Don't forget to like.