Skip to content

Commit d7cb6f4

Browse files
committed
Initial commit: Flutterwave Mobile Money Payment API integration
0 parents  commit d7cb6f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+12316
-0
lines changed

.editorconfig

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2
16+
17+
[docker-compose.yml]
18+
indent_size = 4

.env.example

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
APP_NAME=Laravel
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
7+
APP_LOCALE=en
8+
APP_FALLBACK_LOCALE=en
9+
APP_FAKER_LOCALE=en_US
10+
11+
APP_MAINTENANCE_DRIVER=file
12+
# APP_MAINTENANCE_STORE=database
13+
14+
PHP_CLI_SERVER_WORKERS=4
15+
16+
BCRYPT_ROUNDS=12
17+
18+
LOG_CHANNEL=stack
19+
LOG_STACK=single
20+
LOG_DEPRECATIONS_CHANNEL=null
21+
LOG_LEVEL=debug
22+
23+
DB_CONNECTION=sqlite
24+
# DB_HOST=127.0.0.1
25+
# DB_PORT=3306
26+
# DB_DATABASE=laravel
27+
# DB_USERNAME=root
28+
# DB_PASSWORD=
29+
30+
SESSION_DRIVER=database
31+
SESSION_LIFETIME=120
32+
SESSION_ENCRYPT=false
33+
SESSION_PATH=/
34+
SESSION_DOMAIN=null
35+
36+
BROADCAST_CONNECTION=log
37+
FILESYSTEM_DISK=local
38+
QUEUE_CONNECTION=database
39+
40+
CACHE_STORE=database
41+
# CACHE_PREFIX=
42+
43+
MEMCACHED_HOST=127.0.0.1
44+
45+
REDIS_CLIENT=phpredis
46+
REDIS_HOST=127.0.0.1
47+
REDIS_PASSWORD=null
48+
REDIS_PORT=6379
49+
50+
MAIL_MAILER=log
51+
MAIL_SCHEME=null
52+
MAIL_HOST=127.0.0.1
53+
MAIL_PORT=2525
54+
MAIL_USERNAME=null
55+
MAIL_PASSWORD=null
56+
MAIL_FROM_ADDRESS="[email protected]"
57+
MAIL_FROM_NAME="${APP_NAME}"
58+
59+
AWS_ACCESS_KEY_ID=
60+
AWS_SECRET_ACCESS_KEY=
61+
AWS_DEFAULT_REGION=us-east-1
62+
AWS_BUCKET=
63+
AWS_USE_PATH_STYLE_ENDPOINT=false
64+
65+
VITE_APP_NAME="${APP_NAME}"
66+
67+
# Flutterwave API Configuration
68+
FLUTTERWAVE_PUBLIC_KEY=
69+
FLUTTERWAVE_SECRET_KEY=
70+
FLUTTERWAVE_ENCRYPTION_KEY=
71+
FLUTTERWAVE_WEBHOOK_SECRET=
72+
FLUTTERWAVE_ENVIRONMENT=sandbox
73+
FLUTTERWAVE_LOGO_URL=

.gitattributes

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* text=auto eol=lf
2+
3+
*.blade.php diff=html
4+
*.css diff=css
5+
*.html diff=html
6+
*.md diff=markdown
7+
*.php diff=php
8+
9+
/.github export-ignore
10+
CHANGELOG.md export-ignore
11+
.styleci.yml export-ignore

.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/.phpunit.cache
2+
/node_modules
3+
/public/build
4+
/public/hot
5+
/public/storage
6+
/storage/*.key
7+
/storage/pail
8+
/vendor
9+
.env
10+
.env.backup
11+
.env.production
12+
.phpactor.json
13+
.phpunit.result.cache
14+
Homestead.json
15+
Homestead.yaml
16+
npm-debug.log
17+
yarn-error.log
18+
/auth.json
19+
/.fleet
20+
/.idea
21+
/.nova
22+
/.vscode
23+
/.zed

FLUTTERWAVE_INTEGRATION.md

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Flutterwave Payment Integration
2+
3+
This integration provides a reusable API for processing mobile money and credit card payments using Flutterwave in your Laravel projects.
4+
5+
## Features
6+
7+
- Credit/Debit Card payments
8+
- Mobile Money payments (MTN, Vodafone, Airtel, etc.)
9+
- Bank Transfer payments
10+
- Webhook handling for payment notifications
11+
- Comprehensive error handling
12+
- Easy to integrate into any Laravel project
13+
14+
## Setup Instructions
15+
16+
### 1. Environment Configuration
17+
18+
Add the following variables to your `.env` file:
19+
20+
```
21+
FLUTTERWAVE_PUBLIC_KEY=your_public_key_here
22+
FLUTTERWAVE_SECRET_KEY=your_secret_key_here
23+
FLUTTERWAVE_ENCRYPTION_KEY=your_encryption_key_here
24+
FLUTTERWAVE_WEBHOOK_SECRET=your_webhook_hash_here
25+
FLUTTERWAVE_ENVIRONMENT=sandbox # Change to 'live' for production
26+
FLUTTERWAVE_LOGO_URL=https://your-website.com/logo.png # Optional
27+
```
28+
29+
### 2. Register Webhook URL
30+
31+
In your Flutterwave dashboard, set up a webhook URL that points to:
32+
```
33+
https://your-domain.com/api/flutterwave/webhook
34+
```
35+
36+
## Usage Examples
37+
38+
### Basic Payment Initialization
39+
40+
```php
41+
use App\Services\FlutterwaveService;
42+
43+
class YourController extends Controller
44+
{
45+
protected $flutterwaveService;
46+
47+
public function __construct(FlutterwaveService $flutterwaveService)
48+
{
49+
$this->flutterwaveService = $flutterwaveService;
50+
}
51+
52+
public function makePayment(Request $request)
53+
{
54+
$paymentData = [
55+
'amount' => 100.00,
56+
'email' => '[email protected]',
57+
'name' => 'John Doe',
58+
'phone' => '0123456789',
59+
'payment_method' => 'card', // 'card', 'mobilemoney', or 'bank_transfer'
60+
'currency' => 'USD',
61+
'redirect_url' => route('payment.callback'),
62+
'meta' => [
63+
'order_id' => 'ORDER-123',
64+
'user_id' => auth()->id(),
65+
],
66+
];
67+
68+
$response = $this->flutterwaveService->initializePayment($paymentData);
69+
70+
if ($response['status'] === 'success') {
71+
return redirect($response['data']['link']);
72+
}
73+
74+
return back()->with('error', 'Payment initialization failed');
75+
}
76+
}
77+
```
78+
79+
### Mobile Money Payment
80+
81+
For mobile money payments, include additional parameters:
82+
83+
```php
84+
$paymentData = [
85+
// ... basic payment data
86+
'payment_method' => 'mobilemoney',
87+
'currency' => 'GHS', // Currency code for the country
88+
'network' => 'MTN', // Mobile network provider
89+
'country' => 'GH', // Country code
90+
];
91+
```
92+
93+
### Verifying Payments
94+
95+
```php
96+
public function verifyPayment($reference)
97+
{
98+
$verification = $this->flutterwaveService->verifyPayment($reference);
99+
100+
if ($verification['status'] === 'success') {
101+
// Payment successful, update your database
102+
return view('payment.success', ['transaction' => $verification['data']]);
103+
}
104+
105+
return view('payment.failed');
106+
}
107+
```
108+
109+
## API Documentation
110+
111+
### FlutterwaveService Methods
112+
113+
#### `initializePayment(array $data)`
114+
115+
Initializes a payment transaction.
116+
117+
Parameters:
118+
- `amount`: (required) Amount to charge
119+
- `email`: (required) Customer's email
120+
- `name`: (required) Customer's name
121+
- `phone`: (required) Customer's phone number
122+
- `payment_method`: (required) Payment method ('card', 'mobilemoney', 'bank_transfer')
123+
- `currency`: (required) 3-letter currency code
124+
- `redirect_url`: (required) URL to redirect after payment
125+
- `meta`: (optional) Additional metadata
126+
- `network`: (optional) Mobile network for mobile money
127+
- `country`: (optional) Country code for mobile money
128+
129+
Returns:
130+
- Array containing payment link and transaction reference
131+
132+
#### `verifyPayment(string $reference)`
133+
134+
Verifies a payment transaction.
135+
136+
Parameters:
137+
- `reference`: Transaction reference
138+
139+
Returns:
140+
- Array containing transaction status and details
141+
142+
#### `verifyWebhookSignature(string $signature)`
143+
144+
Verifies the webhook signature from Flutterwave.
145+
146+
Parameters:
147+
- `signature`: Signature from request header
148+
149+
Returns:
150+
- Boolean indicating if signature is valid
151+
152+
#### `processWebhook(string $event, array $data)`
153+
154+
Processes webhook notifications.
155+
156+
Parameters:
157+
- `event`: Event type
158+
- `data`: Event data
159+
160+
## Webhook Events
161+
162+
The integration handles the following webhook events:
163+
- `charge.completed`: When a payment is completed
164+
- `transfer.completed`: When a transfer is completed
165+
- `payment.failed`: When a payment fails
166+
167+
## Example Implementation
168+
169+
This package includes an example implementation in:
170+
- `PaymentExampleController.php`
171+
- `resources/views/payments/form.blade.php`
172+
- `resources/views/payments/success.blade.php`
173+
- `resources/views/payments/failed.blade.php`
174+
175+
## Security Considerations
176+
177+
- Never expose your secret key or encryption key
178+
- Always verify payments server-side
179+
- Validate webhook signatures
180+
- Use HTTPS for all API calls

README.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
2+
3+
<p align="center">
4+
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
5+
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
6+
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
7+
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
8+
</p>
9+
10+
## About Laravel
11+
12+
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
13+
14+
- [Simple, fast routing engine](https://laravel.com/docs/routing).
15+
- [Powerful dependency injection container](https://laravel.com/docs/container).
16+
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
17+
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
18+
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
19+
- [Robust background job processing](https://laravel.com/docs/queues).
20+
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
21+
22+
Laravel is accessible, powerful, and provides tools required for large, robust applications.
23+
24+
## Learning Laravel
25+
26+
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
27+
28+
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
29+
30+
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
31+
32+
## Laravel Sponsors
33+
34+
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
35+
36+
### Premium Partners
37+
38+
- **[Vehikl](https://vehikl.com/)**
39+
- **[Tighten Co.](https://tighten.co)**
40+
- **[WebReinvent](https://webreinvent.com/)**
41+
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
42+
- **[64 Robots](https://64robots.com)**
43+
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
44+
- **[Cyber-Duck](https://cyber-duck.co.uk)**
45+
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
46+
- **[Jump24](https://jump24.co.uk)**
47+
- **[Redberry](https://redberry.international/laravel/)**
48+
- **[Active Logic](https://activelogic.com)**
49+
- **[byte5](https://byte5.de)**
50+
- **[OP.GG](https://op.gg)**
51+
52+
## Contributing
53+
54+
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
55+
56+
## Code of Conduct
57+
58+
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
59+
60+
## Security Vulnerabilities
61+
62+
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [[email protected]](mailto:[email protected]). All security vulnerabilities will be promptly addressed.
63+
64+
## License
65+
66+
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)