Download the PHP package prevailexcel/laravel-bani without Composer
On this page you can find all versions of the php package prevailexcel/laravel-bani. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download prevailexcel/laravel-bani
More information about prevailexcel/laravel-bani
Files in prevailexcel/laravel-bani
Package laravel-bani
Short Description A Laravel Package for Bani
License MIT
Informations about the package laravel-bani
laravel-bani
A Laravel Package for working with Bani Payments seamlessly.
This package also allows you to receive webhooks from Bani which it verifies for you and processes the payloads. It also implements The Bani Pop Payment Widget and handles the callback for laravel. You can start collecting payment in fiat and crypto payments in minutes.
Installation
PHP 5.4+ or HHVM 3.3+, and Composer are required.
To get the latest version of Laravel Bani, simply require it
Or add the following line to the require block of your composer.json
file.
You'll then need to run composer install
or composer update
to download it and have the autoloader updated.
Once Laravel Bani is installed, you need to register the service provider. Open up config/app.php
and add the following to the providers
key.
If you use Laravel >= 5.5 you can skip this step and go to
configuration
Also, register the Facade like so:
Configuration
You can publish the configuration file using this command:
A configuration-file named bani.php
with some sensible defaults will be placed in your config
directory:
General payment flow
This is how the payment flow should be like:
1. Collect Customer Order Data
You have to collect necessary information from the user about what they are paying for and the amount. These usually include Email, Amount, Phone Number, First name and last name. You can do this from your blade form directly (if you're building a website) or from the client app via a request.
2. Get the Bani Pop Widget or call the methods you want.
Bani allows users to pay without leaving your website or app. So you can call the payWithWidget()
to get the Bani Pop Widget and your user can complete payment.
If you want to implement your own UI or you're building an API, you can use a variety of fluent methods you can use to start and complete the payment. You can use bankTransfer()
,mobileMoney()
,payWithCrypto()
,startPayWithOpay()
and even more.
3. You service the customer after payment
After having completed payment, you have to confirm the payment. This package helps handle webhook in a breeze. It also helps you handle callback if you use the pop widget.
As recommended, use the webhook response which this package verifies for you and then mark their order as paid and send them to a thank you page, send an email or whatever you want to do.
Usage
Open your .env file and add all the necessary keys like so:
If you are using a hosting service like heroku, ensure to add the above details to your configuration variables. Remember to change BANI_ENV to 'live' and update the keys when you are in production
Next, you have to setup your routes.
There are 3 routes you should have to get started.
- To initiate payment
- To setup callback (if you want to use the
payWithWidget()
) - Route::callback. - To setup webhook and handle the event responses - Route::webhook.
OR
Lets pay with widget now.
This opens the widget and your user completes payment. The packages redirects to the handleGatewayCallback()
which veifies the payment and then you can use the payment data.
To test with bank transfer, after selecting bank, copy the account and head to https://demo-checkout.getbani.com/test_bank/ to make test payment and then come back to your site and click on "I've paid {amount}" button.
Lets pay with bank transfer now.
To get customer ref, you can create the
bani()->createCustomer($userdata)
method wth user details or find the user via phonebani()->customer("+2348011111111")
to get the user details.
This will return data that includes the account details which you will display or send to your user to make payment.
You can listen to the webhook and service the user. Write the heavy operations inside the handleWebhook()
method.
This package recommends to use a queued job to proccess the webhook data especially if you handle heavy operations like sending mail and more
How does the webhook routing Route::webhook(Controller::class, 'methodName')
work?
Behind the scenes, by default this will register a POST route 'bani/webhook'
to the controller and method you provide. Because the app that sends webhooks to you has no way of getting a csrf-token, you must add that route to the except array of the VerifyCsrfToken middleware:
A sample form will look like so:
When clicking the submit button the customer gets redirected to the Pop Widget.
So now the customer did some actions there (hopefully he or she paid the order) and now the package will redirect the customer to the Callback URL Route::callback()
.
We must validate if the redirect to our site is a valid request (we don't want imposters to wrongfully place non-paid order).
In the controller that handles the request coming from the payment provider, we have
Bani::getPaymentData()
- This function calls the verifyTransaction()
methods and ensure it is a valid transaction else it throws an exception.
Some fluent methods this package provides are listed here.
Customer
Collecting Payment
Verification
Misc
Todo
- Add Comprehensive Tests
- Add Support For Agent Endpoints
- Add Support For More Misc Endpoints
- Add Support For Bill Payment Endpoints
- Add Support For Payoutt Endpoints
Contributing
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
How can I thank you?
Why not star the github repo? I'd love the attention! Why not share the link for this repository on Twitter or HackerNews? Spread the word!
Don't forget to follow me on Twitter! and also follow me on LinkedIn!
Also check out my page on medium to catch articles and tutorials on Laravel follow me on medium!
Thanks! Chimeremeze Prevail Ejimadu.
License
The MIT License (MIT). Please see License File for more information.