Setting Up Laravel for M-Pesa Integration
Objective: Set up a Laravel application and prepare for M-Pesa API integration.
1. Install a fresh Laravel project:
1. Install a fresh Laravel project:
laravel new mpesa-integration
2. Add required packages for HTTP requests:
composer require guzzlehttp/guzzle
3. Configure environment variables in .env:
MPESA_CONSUMER_KEY=your_consumer_key MPESA_CONSUMER_SECRET=your_consumer_secret MPESA_BASE_URL=https://sandbox.safaricom.co.ke
4. Create an M-Pesa Service for reusable code:
php artisan make:service MpesaService
- 1 . Setting up M-PESA developer account 345 words
- 2 . Setting Up Laravel for M-Pesa Integration 345 words
- 3 . Generating an Access Token 345 words
- 4 . Initiating a Payment Request (STK Push) 345 words
- 5 . Handling Callbacks and Storing Transactions 345 words