Pesapal with Laravel

A simplified PesaPal integration for your Laravel Application.

Installation

Via Composer

composer require jchegenye/mypesapal

Usage

Add this class to your Controller.

use App\Http\JTech\PesaPal\PesaPalIframe;

Run this vendor:publish command to publish Pesapal configuration file.

What’s inside the config file?

1. Application Environment:

| Pesapal will utilize this option to determine which
| mode your App is running, either Sandbox or Live
|
| Local - Means your App is running on a Sandbox Mode.
| Production - Means your App is running on a Live Mode
2. Authentication - Configuration | 'token_params' => NULL,
| 'consumer_key' => env('PESAPAL_CONSUMER_KEY','YOUR CONSUMER'),
| 'consumer_secret' => env('PESAPAL_CONSUMER_SECRET','YOUR CONSUMER SECRET'),
| 'live_iframelink' =>
'https://www.pesapal.com/API/PostPesapalDirectOrderV4',
| 'demo_iframelink' => 'http://demo.pesapal.com/api/PostPesapalDirectOrderV4'

3. Define the callback_url

| This is the full url pointing to the page the iframe redirects to after processing the order on pesapal.com
'callback_url' => env('PESAPAL_CALLBACK_URL',
'http://test.com/payment-gateways-php/pesapal-php/'),

4. Field Names

| You may wish for to select prefered form details posted by your
| App to be used by pesapal.
|
| You can add more `Fields` here if you wish.
|
| NOTE: default value = MERCHANT

'fields' => [

'amount' => 'number_format(PESAPAL_FIELD_AMOUNT, 2)', //format amount to 2 decimal places
'description' => 'PESAPAL_FIELD_DESC',
'type' => 'MERCHANT', //default value = MERCHANT
'reference' => 'PESAPAL_FIELD_REF', //unique order id of the transaction, generated by merchant
'first_name' => 'PESAPAL_FIELD_FNAME',
'last_name' => 'PESAPAL_FIELD_LNAME',
'email' => 'PESAPAL_FIELD_EMAIL',
'phonenumber' => 'PESAPAL_FIELD_PHONE' //ONE of email or phonenumber is required

]

To return Pesapal Response use this pesapal() Method.

In-order for Pesapal to obtain an instance of the current HTTP Request add this $request variable.

See below example:

response()->pesapal($request);

Happy Coding :-)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade