musie / laravel-chapa
A Laravel package to integrate Chapa payment gateway
Requires
- php: ^7.3|^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^7.0|^8.0|^9.0|^10.0|^11.0
This package is not auto-updated.
Last update: 2024-09-10 15:39:31 UTC
README
A Laravel package to integrate the Chapa payment gateway easily into your Laravel applications. (It supports Laravel 11)
Installation
You can install the package via composer:
-
Require the package using Composer:
composer require musie/laravel-chapa
-
Install the package:
php artisan chapa:install
-
Add Environment Variables: Add the following lines to your
.env
file:CHAPA_SECRET_KEY=your-secret-key CHAPA_PUBLIC_KEY=your-public-key
Usage
-
Create a Payment Form: Create a view file to include the payment form provided by the package. For example, create a new file named
payment.blade.php
in theresources/views
directory and add the following content:<form action="{{ route('chapa.payment') }}" method="POST"> @csrf <input type="email" name="email" placeholder="Email" required> <input type="text" name="name" placeholder="Name" required> <input type="number" name="amount" placeholder="Amount" required> <button type="submit">Pay</button> </form>
-
Add Routes: Add routes in your
web.php
file to handle the payment and callback:use Illuminate\Support\Facades\Route; use Musie\LaravelChapa\Controllers\ChapaController; Route::get('/', function () { return view('musie.form'); }); Route::post('chapa/payment', [ChapaController::class, 'initializePayment'])->name('chapa.payment'); Route::get('chapa/callback', [ChapaController::class, 'handleCallback'])->name('chapa.callback'); Route::get('chapa/verify/{tx_ref}', [ChapaController::class, 'verifyPayment'])->name('chapa.verify');
-
Handle Callbacks: Ensure you have a callback view to display the payment status. For example, you can use the provided
callback.blade.php
view:@if($status == 'success') <p>Payment was successful!</p> @else <p>Payment failed. Please try again.</p> @endif
-
Testing the Payment Integration:
- Run the webserver.
- Fill out the form with the required details and submit it.
- You should be redirected to the Chapa payment gateway.
- After completing the payment, you should be redirected to the callback URL, where you can see the payment status.
License
The MIT License (MIT). Please see License File for more information.