Download the PHP package nyawach/laravel-pesapal without Composer
On this page you can find all versions of the php package nyawach/laravel-pesapal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nyawach/laravel-pesapal
More information about nyawach/laravel-pesapal
Files in nyawach/laravel-pesapal
Package laravel-pesapal
Short Description A simple pesapal payment v3 integration into laravel
License MIT
Informations about the package laravel-pesapal
Pesapal V3 Package for Laravel Applications
This package enables you to set up Pesapal V3 web payment in under 5 minutes
Preinstallation requirements
- Laravel 8*
- PHP 7.4 or higher
- CURL installed
Installation
composer require nyawach/laravel-pesapal
configuration
To publish the pesapal config file and migrations run:
Sample Config file
Refer to config/pesapal.php and create environment variable in your .env file. See example below.
PEASAPAL_ENV: Please specify whether the environment is sandbox or production PESAPAL_CONSUMER_KEY and PESAPAL_CONSUMER_SECRET Production keys can be obtained here. Sandbox or testing keys can be found here PESAPAL_GUARD: It is good practice to guard your callback and notification URLs. Think of a unique string and set it as your guard. This is how the URL will look like: https://www.myapplication/callback/ahd55hrg57edhWYDGSS
PESAPAL_IPN_ID: For production use this form to create IPN URLs and save the id. For testing or sandbox use this form. IPN URL can either be POST or GET choose the one you feel for comfortable with.
IPN stands for Instant Payment Notification. When a payment is made against a transaction, Pesapal will trigger an IPN call to the notification URL related to this transaction. This notification URL is usually located on your servers. These notifications allows you to be alerted in real time whenever there is a status change for any transaction.
An IPN is particular important as it allows you to be notified incase the following happens:
- Your client gets disconnected after payment due to internet issues
- Your client experiences server errors hence Pesapal and your application gets disconnected before callback URL is loaded.
- Your client exits your application / closes the browser during payment.
- The transaction is rejected.
Alternatively register IPN URLs
In your controller
Make sure you have saved the IPN id in your .env file.
A successful IPN registration response will look like this.
Submitting an order request
The way Pesapal works is that you submit an order request. A successful order will return a response containing order_tracking_id and an Iframe link. you can render the payment iframe within your website or redirect users to the iframe link to make payments. Thereafter you can submit a request to get the payment status.
It is also important that you save the order details in you database.
See below on how to submit an order request
On a successful order request, you will get a response that looks like this
The redirect_url contains the iframe link. Redirect clients to the link to complete the payment or render it on your website. See exsmple below how to render it
This is how the payment iframe should look when rendered
Get Transaction Status
Once Pesapal redirect your customer to your callback URL and triggers your IPN URL, you need to check the status of the payment using the OrderTrackingId.
Transaction status returns transaction info and status code. This will allow you to update the transaction details based on the status code. The status code are as follows:
- 0 - INVALID
- 1 - COMPLETED
- 2 - FAILED
- 3 - REVERSED
See example below on how to request transaction status:
A successful get transaction status should return a response that looks similar to the one below.
Refund Payment
Use this endpoint to refund payments to customer. See example below
On a successful request the following response will be returned
The refund API uses the confirm code for identification. It's important that you store all payment confirmation codes as returned in the Get Transaction Status Endpoint
Security and Vulnerabilities
If you discover a security vulnerability within laravel-pesapal, please send an e-mail to Joshua Nyawach via [email protected]. All security vulnerabilities will be promptly addressed.
License
Laravel-pesapal is an open source software licensed under the MIT License