GithubHelp home page GithubHelp logo

pesapal's Introduction

Pesapal Laravel 5,6,7,8,9,10 API

Laravel 5,6,7,8,9,10 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 (for Laravel 5.4 and below)

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 (for Laravel 5.4 and below)

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

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

Setup

Pesapal IPN

For the url of the route use /pesapal-ipn eg mysite.com/pesapal-ipn as the IPN on the Pesapal Merchant settings dashboard

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...Better Example..Haha

Assuming you have a Payment Model

use Pesapal;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\Auth;
use App\Payment;

class PaymentsController extends Controller
{
    public function payment(){//initiates payment
        $payments = new Payment;
        $payments -> businessid = Auth::guard('business')->id(); //Business ID
        $payments -> transactionid = Pesapal::random_reference();
        $payments -> status = 'NEW'; //if user gets to iframe then exits, i prefer to have that as a new/lost transaction, not pending
        $payments -> amount = 10;
        $payments -> save();

        $details = array(
            'amount' => $payments -> amount,
            'description' => 'Test Transaction',
            'type' => 'MERCHANT',
            'first_name' => 'Fname',
            'last_name' => 'Lname',
            'email' => '[email protected]',
            'phonenumber' => '254-723232323',
            'reference' => $payments -> transactionid,
            'height'=>'400px',
            //'currency' => 'USD'
        );
        $iframe=Pesapal::makePayment($details);

        return view('payments.business.pesapal', compact('iframe'));
    }
    public function paymentsuccess(Request $request)//just tells u payment has gone thru..but not confirmed
    {
        $trackingid = $request->input('tracking_id');
        $ref = $request->input('merchant_reference');

        $payments = Payment::where('transactionid',$ref)->first();
        $payments -> trackingid = $trackingid;
        $payments -> status = 'PENDING';
        $payments -> save();
        //go back home
        $payments=Payment::all();
        return view('payments.business.home', compact('payments'));
    }
    //This method just tells u that there is a change in pesapal for your transaction..
    //u need to now query status..retrieve the change...CANCELLED? CONFIRMED?
    public function paymentconfirmation(Request $request)
    {
        $trackingid = $request->input('pesapal_transaction_tracking_id');
        $merchant_reference = $request->input('pesapal_merchant_reference');
        $pesapal_notification_type= $request->input('pesapal_notification_type');

        //use the above to retrieve payment status now..
        $this->checkpaymentstatus($trackingid,$merchant_reference,$pesapal_notification_type);
    }
    //Confirm status of transaction and update the DB
    public function checkpaymentstatus($trackingid,$merchant_reference,$pesapal_notification_type){
        $status=Pesapal::getMerchantStatus($merchant_reference);
        $payments = Payment::where('trackingid',$trackingid)->first();
        $payments -> status = $status;
        $payments -> payment_method = "PESAPAL";//use the actual method though...
        $payments -> save();
        return "success";
    }
}

Example ENV

 PESAPAL_IPN=PaymentsController@paymentconfirmation
 PESAPAL_LIVE=true
 PESAPAL_CALLBACK_ROUTE=paymentsuccess

Example View

  {!! $iframe !!}

Example Routes

Relevant routes example, to help exclude entire webhooks route group in Csrf check in VerifyCsrfToken Middleware

Route::group(['prefix' => '/webhooks'], function () {
    //PESAPAL
    Route::get('donepayment', ['as' => 'paymentsuccess', 'uses'=>'PaymentsController@paymentsuccess']);
    Route::get('paymentconfirmation', 'PaymentsController@paymentconfirmation');
});

All Done

Feel free to report any issues

pesapal's People

Contributors

george-raphael avatar knox2 avatar mudassar1 avatar muruthi avatar murwa avatar muvans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pesapal's Issues

Instant Payment Notification Settings

hi, So I have successfully integrated the Pesapal payment API thanks to this laravel package. My question is, which route do I add to the pesapal's IPN settings form. The route calling the payment's confirmation method in my controller(as in your example) i.e this one below

public function paymentConfirmation(Request $request){ $trackingid=$request->input('pesapal_transaction_tracking_id'); $merchant_reference=$request->input('pesapal_merchant_reference'); $pesapal_notification_type=$request->input('pesapal_notification_type'); $this->checkpaymentstatus($trackingid,$merchant_reference,$pesapal_notification_type); }

or the route calling the method in the PesapalAPIController in the package, i.e this one:

function handleIPN() { if (Input::has('pesapal_notification_type') && Input::has('pesapal_merchant_reference') && Input::has('pesapal_transaction_tracking_id')) { $notification_type = Input::get('pesapal_notification_type'); $merchant_reference = Input::get('pesapal_merchant_reference'); $tracking_id = Input::get('pesapal_transaction_tracking_id'); Pesapal::redirectToIPN($notification_type, $merchant_reference, $tracking_id); } else { throw new PesapalException("incorrect parameters in request"); } }

Intergration

I have issues integrating with my site. How can I get your help. The information given is incomplete

Application::share() removed in Laravel 5.4 - Breaks Package

PesapalServiceProvider.php on line 30

Upgrading to Laravel 5.4 breaks current package as the deprecated share() method has been removed.

$this->app['pesapal'] = $this->app->share(function ($app) {
    return new Pesapal;
});

The share method has been removed from the container. This was a legacy method that has not been documented in several years. If you are using this method, you should begin using the singleton method instead:

$container->singleton('foo', function () {
    return 'foo';
});

Pesapal Confirmation Status

Hi guys.
I have successfully integrated this API in my site. In addition to this, I need to get the amount paid by a client when I request for payment confirmation. Currently, I only get the status of the transaction of which the status will still be pending if one pays an amount less or more than what the iframe gets from my payment form.
Can someone help me solve this.

Kind Regards

OAuth.php does not comply with psr-4 autoloading standard

When trying to install using composer require knox/pesapal command, getting the following error on the console. It actually installed v1.0. I also tried to upgrade to v1.4.0 but failed.

Class Knox\Pesapal\OAuthException located in /vendor/knox/pesapal/src\OAuth.php does not comply with psr-4 autoloading standard. Skipping.                                                       
Class Knox\Pesapal\OAuthConsumer located in /vendor/knox/pesapal/src\OAuth.php does not comply with psr-4 autoloading standard. Skipping.                                                        
Class Knox\Pesapal\OAuthToken located in /vendor/knox/pesapal/src\OAuth.php does not comply with psr-4 autoloading standard. Skipping.                                                           
Class Knox\Pesapal\OAuthSignatureMethod located in /vendor/knox/pesapal/src\OAuth.php does not comply with psr-4 autoloading standard. Skipping.                                                 
Class Knox\Pesapal\OAuthSignatureMethod_HMAC_SHA1 located in /vendor/knox/pesapal/src\OAuth.php does not comply with psr-4 autoloading standard. Skipping.                                       
Class Knox\Pesapal\OAuthSignatureMethod_PLAINTEXT located in /vendor/knox/pesapal/src\OAuth.php does not comply with psr-4 autoloading standard. Skipping.                                       
Class Knox\Pesapal\OAuthSignatureMethod_RSA_SHA1 located in /vendor/knox/pesapal/src\OAuth.php does not comply with psr-4 autoloading standard. Skipping.                                        
Class Knox\Pesapal\OAuthRequest located in /vendor/knox/pesapal/src\OAuth.php does not comply with psr-4 autoloading standard. Skipping.                                                         
Class Knox\Pesapal\OAuthServer located in /vendor/knox/pesapal/src\OAuth.php does not comply with psr-4 autoloading standard. Skipping.                                                          
Class Knox\Pesapal\OAuthDataStore located in /vendor/knox/pesapal/src\OAuth.php does not comply with psr-4 autoloading standard. Skipping.                                                       
Class Knox\Pesapal\OAuthUtil located in /vendor/knox/pesapal/src\OAuth.php does not comply with psr-4 autoloading standard. Skipping. 

=======================
Laravel ^10.10
PHP version (8.2.6)

Please assist

This will be very useful however some of us a very new to laravel. Like I am torn a bit on where to allocate all these files, I know only a few.

integration

how do i display the iframe from pesapal on my view?
how do i know it has posted to pesapal?
where do i place the links that are posting to pesapal?
i've followed the documentation to the latter and i still don't know why it's not working

Error while rendering iframe contents

Using demo credentials.
Iframe returns this following content.

Sorry, an error occurred while processing your request. We are working to fix it
as soon as we can.

Full html returned in the iframe is:

<title>PesaPal™ | Unknown Error</title> <script src="/scripts/jquery-3.2.1.min.js" type="text/javascript"></script> <script src="/scripts/bootstrap-collapse.js" type="text/javascript"></script> <script type="text/javascript">var _gaq = _gaq || [];_gaq.push(['_setAccount', 'UA-34762642-1']);_gaq.push(['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();</script>
<div id="pp-wrapper">
    <div class="wrapper">
        <div class="accordion" id="accordion2">

Sorry, an error occurred while processing your request. We are working to fix it as soon as we can.

        </div>
    </div>
</div>

I was able to produce a good iframe using same credentials with plain php using the example code posted here. https://developer.pesapal.com/how-to-integrate/php-sample

IPN

Which method am I to use, redirectToIPN or getMerchantStatus? Am failing to get notification updates to my Model...still using the demo.pesapal site. Thank you

passing details to iframe (Pesapal payment iframe not showing)

When I use {{$iframe}} in view blade I get the following display instead of the intended Pesapal Iframe

<iframe src="https://demo.pesapal.com/api/PostPesapalDirectOrderV4?amount=1000&currency=UGX&description=Enrolled%20for%20class%20at%20Schuline%20Learning%20Portal&email=Admin%40infouganda.net&first_name=Caniwia&height=400px&last_name=phoste&oauth_callback=http%3A%2F%2F127.0.0.1%2FeClass%2Fxul%2Fpublic%2Fpesapal-callback&oauth_consumer_key=wTrOMVGPOrbrQdIKCnh%2F0f%2FANg%2F7z2g6&oauth_nonce=%7B0157F6E6-9472-AC0C-4D04-2D9A73C03353%7D&oauth_signature=3z5wkOIq1f9vxRKgAtuD2hmEMHo%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1593765358&oauth_version=1.0&pesapal_request_data=%26lt%3B%3Fxml%20version%3D%26quot%3B1.0%26quot%3B%20encoding%3D%26quot%3&phonenumber=256781463437&reference=PESAPALEA1BVMUE7ESDN9O&type=MERCHANT&width=100%25" width="100%" height="400px" scrolling="auto" frameBorder="0"> <p>Unable to load the payment page</p> </iframe>

`PESAPAL_CONSUMER_KEY=2bNDTh8ial2........

PESAPAL_CONSUMER_SECRET=/9Tc.................

PESAPAL_CURRENCY=UGX

PESAPAL_IPN=PesapalController@paymentconfirmation

PESAPAL_LIVE=false

PESAPAL_CALLBACK_ROUTE=paymentsuccess`

If you could give me code and guide on how to add iframe I would really appreciate

Payment method returning

Hello guys,
I do not think the payment function should return a view. It could simply return $iframe.

Undefined index: scheme

There seems to be an error in the knox/pesapal/src/OAuth/OAuthRequest.php

public function get_normalized_http_url()
{
    $parts = parse_url($this->http_url);
    if (array_key_exists('port', $parts)) {
        $port = @$parts['port'];
    } else {
        $port = false;
    }
    `$scheme = $parts['scheme'];`

IPN

Hi, could you help me get around getting ipn up? I keep getting bad method error, is it because my ipn in .env is 'getstatus' while my ipn url in the dashbboard is 'localhost:8000/paymentsuccess'

after payment method iframe error on view

Problem: parameter_rejected | Advice: unknown_error_occured> oauth_parameters_rejected | request_xml_data
when iframe trying to load

with following detail on Pesapal::makePayment($details);

"amount" => "1200"
"description" => "{"STUD_ID":"1","REG_NO":"STUD-0001","FEE_MASTER_ID":"1","DESCRIPTION":"BBA I-ADMISSION FEE"}"
"type" => "MERCHANT"
"first_name" => "UTTAM"
"last_name" => "YADU"
"email" => "[email protected]"
"phonenumber" => "977-98989898"
"reference" => "STUD-0001-1"
"height" => "400px"
"currency" => "USD"

Incomplete documentation

Thank you for the awesome Laravel 5 module.

I'd really like to know how does one implement the Pesapal payment gateway view using the values returned by Pesapal::makePayment($details) function?

Also what ENV variables should I use to define whether the integration is a live or demo environment? It's not provided.

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.