A PHP library/Laravel Package for integrating with M-Pesa Daraja API
# M-Pesa Daraja PHP Library
This is a PHP library designed to integrate with the M-Pesa Daraja API, exclusively for Laravel users but also adaptable for non-Laravel PHP applications.
## Installation
### For Laravel Users
Install the package using Composer:
```sh
composer require sntaks/daraja
```
### For Non-Laravel Users
If you are using plain PHP, you can install the package via Composer:
```sh
composer require sntaks/daraja
```
Then, manually include the Composer autoloader at the beginning of your script:
```php
require __DIR__ . '/vendor/autoload.php';
```
## Configuration
### Laravel Configuration
Publish the configuration file:
```sh
php artisan vendor:publish --tag=config
```
This will create a `config/mpesa.php` file where you can set your API credentials.
### For Non-Laravel Users
Install the package using Composer:
```bash
composer require sntaks/daraja
```
Since non-Laravel projects do not have automatic config publishing, you need to create a configuration file manually. Create a `config/mpesa.php` file in your project's root folder:
```php
[
'c2b' => [
'consumer_key' => env('MPESA_C2B_CONSUMER_KEY'),
'consumer_secret' => env('MPESA_C2B_CONSUMER_SECRET'),
],
'b2c' => [
'consumer_key' => env('MPESA_B2C_CONSUMER_KEY'),
'consumer_secret' => env('MPESA_B2C_CONSUMER_SECRET'),
],
'sandbox' => [
'consumer_key' => env('MPESA_SANDBOX_CONSUMER_KEY'),
'consumer_secret' => env('MPESA_SANDBOX_CONSUMER_SECRET'),
],
],
'cache_location' => 'cache',
'callback_method' => 'POST',
'lnmo' => [
'short_code' => env('MPESA_LNMO_SHORT_CODE'),
'callback' => env('MPESA_LMNO_CALLBACK'),
'passkey' => env('MPESA_LNMO_PASSKEY'),
'default_transaction_type' => 'CustomerPaybillOnline'
],
'c2b' => [
'initiator_name' => env('MPESA_C2B_INITIATOR_NAME'),
'security_credential' => env('MPESA_C2B_SECURITY_CREDENTIAL'),
'confirmation_url' => env('MPESA_C2B_CONFIRMATION_URL'),
'validation_url' => env('MPESA_C2B_VALIDATION_URL'),
'on_timeout' => 'Completed',
'short_code' => en …