This integration provides a reusable API for processing mobile money and credit card payments using Flutterwave in your Laravel projects.
- Credit/Debit Card payments
- Mobile Money payments (MTN, Vodafone, Airtel, etc.)
- Bank Transfer payments
- Support for multiple countries (Uganda, Ghana, Kenya, Rwanda, Tanzania, Nigeria)
- Webhook handling for payment notifications
- Comprehensive error handling
- Beautiful, responsive UI with Bootstrap
- Easy to integrate into any Laravel project
Add the following variables to your .env
file:
FLUTTERWAVE_PUBLIC_KEY=your_public_key_here
FLUTTERWAVE_SECRET_KEY=your_secret_key_here
FLUTTERWAVE_ENCRYPTION_KEY=your_encryption_key_here
FLUTTERWAVE_WEBHOOK_SECRET=your_webhook_hash_here
FLUTTERWAVE_ENVIRONMENT=sandbox # Change to 'live' for production
FLUTTERWAVE_LOGO_URL=https://your-website.com/logo.png # Optional
use App\Services\FlutterwaveService;
class YourController extends Controller
{
protected $flutterwaveService;
public function __construct(FlutterwaveService $flutterwaveService)
{
$this->flutterwaveService = $flutterwaveService;
}
public function makePayment(Request $request)
{
$paymentData = [
'amount' => 100.00,
'email' => 'customer@example.com',
'name' => 'John Doe',
'phone' => '0123456789',
'payment_method' => 'card', // 'card', 'mobilemoney', or 'bank_transfer'
'currency' => 'USD',
'redirect_url' => route('payment.callback'),
'meta' => [
'order_id' => 'ORDER-123',
'user_id' => auth()->id(),
],
];
$response = $this->flutterwaveService->initializePayment($paymentData);
if ($response['status'] === 'success') {
return redirect($response['data']['link']);
}
return back()->with('error', 'Payment initialization failed');
}
}
For mobile money payments, include additional parameters:
$paymentData = [
// ... basic payment data
'payment_method' => 'mobilemoney',
'currency' => 'UGX', // Currency code for the country
'network' => 'AIRTEL', // Mobile network provider (MTN or AIRTEL for Uganda)
'country' => 'UG', // Country code
];
Important Note for Uganda Mobile Money:
- Phone number must be in international format with country code 256
- Network must be either 'MTN' or 'AIRTEL'
- Currency should be 'UGX'
public function verifyPayment($reference)
{
$verification = $this->flutterwaveService->verifyPayment($reference);
if ($verification['status'] === 'success') {
// Payment successful, update your database
return view('payment.success', ['transaction' => $verification['data']]);
}
return view('payment.failed');
}
Initializes a payment transaction.
Parameters:
amount
: (required) Amount to chargeemail
: (required) Customer's emailname
: (required) Customer's namephone
: (required) Customer's phone numberpayment_method
: (required) Payment method ('card', 'mobilemoney', 'bank_transfer')currency
: (required) 3-letter currency coderedirect_url
: (required) URL to redirect after paymentmeta
: (optional) Additional metadatanetwork
: (optional) Mobile network for mobile moneycountry
: (optional) Country code for mobile money
Returns:
- Array containing payment link and transaction reference
Verifies a payment transaction.
Parameters:
reference
: Transaction reference
Returns:
- Array containing transaction status and details
Verifies the webhook signature from Flutterwave.
Parameters:
signature
: Signature from request header
Returns:
- Boolean indicating if signature is valid
Processes webhook notifications.
Parameters:
event
: Event typedata
: Event data
The integration handles the following webhook events:
charge.completed
: When a payment is completedtransfer.completed
: When a transfer is completedpayment.failed
: When a payment fails
This package includes an example implementation in:
PaymentExampleController.php
resources/views/payments/form.blade.php
resources/views/welcome.blade.php
resources/views/payments/success.blade.php
resources/views/payments/failed.blade.php
- Never expose your secret key or encryption key
- Always verify payments server-side
- Validate webhook signatures
- Use HTTPS for all API calls
This project is open-sourced software licensed under the MIT license.
Mycosoft Technologies
- Phone: +256 750501151 or +256 781779477
- Email: mycosoftofficial@gmail.com
- Website: mycosofttechnologies.com