GithubHelp home page GithubHelp logo

pesapal's Introduction

Pesapal Laravel 5 API

Laravel 5 Package for the Pesapal API

##Installation

###Add this package using Composer

From the command line inside your project directory, simply type:

composer require knox/pesapal

###Update your config

Add the service provider to the providers array in config/app.php:

Knox\Pesapal\PesapalServiceProvider::class,

Add the facade to the aliases array in config/app.php:

'Pesapal' => Knox\Pesapal\Facades\Pesapal::class,

###Publish the package configuration

Publish the configuration file and migrations by running the provided console command:

php artisan vendor:publish --provider="Knox\Pesapal\PesapalServiceProvider"

##Setup ###Environmental Variables PESAPAL_CONSUMER_KEY pesapal consumer key

PESAPAL_CONSUMER_SECRET pesapal consumer secret

PESAPAL_CURRENCY ISO code for the currency

PESAPAL_IPN controller method to call for instant notifications IPN as relative path from App\Http\Controllers\ eg "TransactionController@confirmation"

PESAPAL_CALLBACK_ROUTE route name to handle the callback eg Route::get('donepayment', ['as' => 'paymentsuccess', 'uses'=>'PaymentsController@paymentsuccess']); The route name is "paymentsuccess"

NB: The controller method accepts 4 function parameters, Example:

public function confirmation($trackingid,$status,$payment_method,$merchant_reference)
{
	$payments = Payments::where('tracking',$trackingid)->first();
    $payments -> payment_status = $status;
    $payments -> payment_method = $payment_method;
    $payments -> save();
}       

###Config live - Live or Demo environment

The ENV Variables can also be set from here.

##Usage At the top of your controller include the facade
use Pesapal;

###Example Code Assuming you have a Payment Model

public function payment(){     
    $payments = new Payments;
	$payments -> order_id = mt_rand(1,1000);
    $payments -> user_id = Auth::id();
    $payments -> transaction = Pesapal::random_reference();
    $payments -> payment_status = 'PENDING';
    $payments -> amount = 10;
    $payments -> save();
    $details = array(
        'amount' => $payments -> amount,
        'description' => 'Test',
        'type' => 'MERCHANT',
        'first_name' => 'John',
        'last_name' => 'Doe',
        'email' => '[email protected]', 
        'phonenumber' => '254723232323',
        'reference' => $payments -> transaction,
        //'currency' => 'USD'
    );
    return Pesapal::makePayment($details);
}

Returns an IFRAME to display the payment options

The Method receives two input arguments

Callback implementation

public function paymentsuccess()
{
    $trackingid = Input::get('tracking_id');
    $ref = Input::get('merchant_reference');
	$payments = Payments::where('transaction',$ref)->first();
    $payments -> tracking = $trackingid;
    $payments -> save();
    return view('payment', ['trackingid' => $trackingid, 'ref' => $ref]);
}

####All Done Feel free to report any issues

pesapal's People

Contributors

knox2 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.