Giter Club home page Giter Club logo

mpesa's Introduction

M-PESA API Package

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

This is a PHP package for the Safaricom's M-Pesa API. The API allows a merchant to initiate C2B online checkout (paybill via web) transactions. The merchant submits authentication details, transaction details, callback url and callback method.

After request submission, the merchant receives instant feedback with validity status of their requests. The C2B API handles customer validation and authentication via USSD push. The customer then confirms the transaction. If the validation of the customer fails or the customer declines the transaction, the API makes a callback to merchant. Otherwise the transaction is processed and its status is made through a callback.

If you enjoy using this package, please take a moment and buy me some coffee.

Installation

Pull in the package through Composer.

Native Addon

When using vanilla PHP, modify your composer.json file to include:

  "scripts": {
    "post-update-cmd": [
        "SmoDav\\Mpesa\\Support\\Installer::install"
    ]
  },

This script will copy the default configuration file to a config folder in the root directory of your project. Now proceed to require the package.

General Install

Run composer require smodav/mpesa to get the latest stable version of the package.

Migration from previous versions

v5 of the package changes the implementation and introduces some breaking changes. Please have a look at the CHANGELOG.

v4 of this package uses a new configuration setup. You will need to update your config file in order to upgrade v3 to v4. v2 is still incompatible since it uses the older API version.

Laravel

When using Laravel 5.5+, the package will automatically register. For laravel 5.4 and below, include the service provider and its alias within your config/app.php.

'providers' => [
    SmoDav\Mpesa\Laravel\ServiceProvider::class,
],

'aliases' => [
    'STK'       => SmoDav\Mpesa\Laravel\Facades\STK::class,
    'Simulate'  => SmoDav\Mpesa\Laravel\Facades\Simulate::class,
    'Registrar' => SmoDav\Mpesa\Laravel\Facades\Registrar::class,
    'Identity'  => SmoDav\Mpesa\Laravel\Facades\Identity::class,
],

Publish the package specific config using:

php artisan vendor:publish

Other Frameworks

To implement this package, a configuration repository is needed, thus any other framework will need to create its own implementation of the ConfigurationStore and CacheStore interfaces.

Configuration

The package allows you to have multiple accounts. Each account will have its specific credentials and endpoints that are independent of the rest. You will be required to set the default account to be used for all transactions, which you can override on each request you make. The package comes with two default accounts that you can modify.

/*
|--------------------------------------------------------------------------
| Default Account
|--------------------------------------------------------------------------
|
| This is the default account to be used when none is specified.
*/

'default' => 'staging',

/*
|--------------------------------------------------------------------------
| File Cache Location
|--------------------------------------------------------------------------
|
| When using the Native Cache driver, this will be the relative directory
| where the cache information will be stored.
*/

'cache_location' => '../cache',

/*
|--------------------------------------------------------------------------
| Accounts
|--------------------------------------------------------------------------
|
| These are the accounts that can be used with the package. You can configure
| as many as needed. Two have been setup for you.
|
| Sandbox: Determines whether to use the sandbox, Possible values: sandbox | production
| Initiator: This is the username used to authenticate the transaction request
| LNMO:
|    shortcode: The till number
|    passkey: The passkey for the till number
|    callback: Endpoint that will be be queried on completion or failure of the transaction.
|
*/

'accounts' => [
    'staging' => [
        'sandbox' => true,
        'key' => 'your development consumer key',
        'secret' => 'your development consumer secret',
        'initiator' => 'your development username',
        'id_validation_callback' => 'http://example.com/callback?secret=some_secret_hash_key',
        'lnmo' => [
            'paybill' => 'your development paybill number',
            'shortcode' => 'your development business code',
            'passkey' => 'your development passkey',
            'callback' => 'http://example.com/callback?secret=some_secret_hash_key',
        ]
    ],

    'paybill_1' => [
        'sandbox' => false,
        'key' => 'your production consumer key',
        'secret' => 'your production consumer secret',
        'initiator' => 'your production username',
        'id_validation_callback' => 'http://example.com/callback?secret=some_secret_hash_key',
        'lnmo' => [
            'paybill' => 'your production paybill number',
            'shortcode' => 'your production business code',
            'passkey' => 'your production passkey',
            'callback' => 'http://example.com/callback?secret=some_secret_hash_key',
        ]
    ],

    'paybill_2' => [
        'sandbox' => false,
        'key' => 'your production consumer key',
        'secret' => 'your production consumer secret',
        'initiator' => 'your production username',
        'id_validation_callback' => 'http://example.com/callback?secret=some_secret_hash_key',
        'lnmo' => [
            'paybill' => 'your production paybill number',
            'shortcode' => 'your production business code',
            'passkey' => 'your production passkey',
            'callback' => 'http://example.com/callback?secret=some_secret_hash_key',
        ]
    ],
],

You can add as many accounts as required and switch the connection using the method usingAccount on STK, Register and Simulate as shown below.

Also, note the difference between the business shortcode and your paybill number in the configuration as getting them wrong will cost you a lot of time debugging.

Usage

For Vanilla PHP you will need to initialize the core engine before any requests as shown below. The package comes with a vanilla php implementation of the cache and configuration store, NativeCache and NativeConfig.

The NativeConfig receives the custom location for the configuration file to be used as the first constructor argument. If no value is passed when creating the instance, it will use the default configuration and look for a configuration file on the root of the project under configs directory.

The NativeCache receives a custom directory path as the first constructor argument. The path denotes where the cache should store its files. If no path is provided, the default cache location in the config will be used.

use GuzzleHttp\Client;
use SmoDav\Mpesa\Engine\Core;
use SmoDav\Mpesa\Native\NativeCache;
use SmoDav\Mpesa\Native\NativeConfig;

require "vendor/autoload.php";

$config = new NativeConfig();
$cache = new NativeCache($config->get('cache_location'));
// or
$cache = new NativeCache(__DIR__ . '/../some/awesome/directory');

$core = new Core(new Client, $config, $cache);

URL Registration

submit(shortCode = null, confirmationURL = null, validationURL = null, onTimeout = 'Completed|Cancelled', account = null)

Register callback URLs

Vanilla
use SmoDav\Mpesa\C2B\Registrar;

$conf = 'http://example.com/mpesa/confirm?secret=some_secret_hash_key';
$val = 'http://example.com/mpesa/validate?secret=some_secret_hash_key';


$response = (new Registrar($core))->register(600000)
    ->onConfirmation($conf)
    ->onValidation($val)
    ->submit();

/****** OR ********/
$response = (new Registrar($core))->submit(600000, $conf, $val);

When having multiple accounts, switch using the usingAccount method. We currently have staging, paybill_1 and paybill_2 with staging as the default:

$response = (new Registrar($core))
    ->register(600000)
    ->usingAccount('paybill_1')
    ->onConfirmation($conf)
    ->onValidation($val)
    ->submit();

/****** OR ********/
$response = (new Registrar($core))->submit(600000, $conf, $val, null, 'paybill_1');
Laravel
use SmoDav\Mpesa\Laravel\Facades\Registrar;

$conf = 'http://example.com/mpesa/confirm?secret=some_secret_hash_key';
$val = 'http://example.com/mpesa/validate?secret=some_secret_hash_key';

$response = Registrar::register(600000)
    ->onConfirmation($conf)
    ->onValidation($val)
    ->submit();

/****** OR ********/
$response = Registrar::submit(600000, $conf, $val);

Using the paybill_1 account:

use SmoDav\Mpesa\Laravel\Facades\Registrar;

$response = Registrar::register(600000)
    ->usingAccount('paybill_1')
    ->onConfirmation($conf)
    ->onValidation($val)
    ->submit();

/****** OR ********/
$response = Registrar::submit(600000, $conf, $val, null, 'paybill_1');

Simulate Transaction

push(amount = null, number = null, reference = null, account = null, command = null)

Initiate a C2B simulation transaction request.

Note that when initiating a C2B simulation, setting the command type is optional and by default CustomerPaybillOnline will be used.

Vanilla
use SmoDav\Mpesa\C2B\Simulate;

$simulate = new Simulate($core)

$response = $simulate->request(10)
    ->from(254722000000)
    ->usingReference('Some Reference')
    ->push();

/****** OR ********/
$response = $simulate->push(10, 254722000000, 'Some Reference');

Using the paybill_1 account:

$response = $simulate->request(10)
    ->from(254722000000)
    ->usingReference('Some Reference')
    ->usingAccount('paybill_1')
    ->push();

/****** OR ********/
$response = $simulate->push(10, 254722000000, 'Some Reference', 'paybill_1');

Using the CustomerBuyGoodsOnline command:

$response = $simulate->request(10)
    ->from(254722000000)
    ->usingReference('Some Reference')
    ->setCommand(CUSTOMER_BUYGOODS_ONLINE)
    ->push();

/****** OR ********/
$response = $simulate->push(10, 254722000000, 'Some Reference', null, CUSTOMER_BUYGOODS_ONLINE);
Laravel
use SmoDav\Mpesa\Laravel\Facades\Simulate;

$response = Simulate::request(10)
    ->from(254722000000)
    ->usingReference('Some Reference')
    ->push();

/****** OR ********/
$response = Simulate::push(10, 254722000000, 'Some Reference');

Using the paybill_1 account:

use SmoDav\Mpesa\Laravel\Facades\Simulate;

$response = Simulate::request(10)
    ->from(254722000000)
    ->usingReference('Some Reference')
    ->usingAccount('paybill_1')
    ->push();

/****** OR ********/
$response = Simulate::push(10, 254722000000, 'Some Reference', 'paybill_1');

Using the CustomerBuyGoodsOnline command:

use SmoDav\Mpesa\Laravel\Facades\Simulate;

$response = Simulate::request(10)
    ->from(254722000000)
    ->usingReference('Some Reference')
    ->setCommand(CUSTOMER_BUYGOODS_ONLINE) 
    ->push();

/****** OR ********/
$response = Simulate::push(10, 254722000000, 'Some Reference', null, CUSTOMER_BUYGOODS_ONLINE);

STK PUSH

push(amount = null, number = null, reference = null, description = null, account = null, command = null)

Initiate a C2B STK Push request.

Note that when initiating an STK Push, setting the command type is optional and by default CustomerPaybillOnline will be used.

Vanilla
use SmoDav\Mpesa\C2B\STK;

$stk = new STK($core);

$response = $stk->request(10)
    ->from(254722000000)
    ->usingReference('Some Reference', 'Test Payment')
    ->push();

/****** OR ********/
$response = $stk->push(10, 254722000000, 'Some Reference', 'Test Payment');

Using the paybill_2 account:

$response = $stk->request(10)
    ->from(254722000000)
    ->usingAccount('paybill_2')
    ->usingReference('Some Reference', 'Test Payment')
    ->push();

/****** OR ********/
$response = $stk->push(10, 254722000000, 'Some Reference', 'Test Payment', 'paybill_2');

Using CustomerBuyGoodsOnline command:

$response = $stk->request(10)
    ->from(254722000000)
    ->usingReference('Some Reference', 'Test Payment')
    ->setCommand(CUSTOMER_BUYGOODS_ONLINE)
    ->push();

/****** OR ********/
$response = $stk->push(10, 254722000000, 'Some Reference', 'Test Payment', null, CUSTOMER_BUYGOODS_ONLINE);
Laravel
use SmoDav\Mpesa\Laravel\Facades\STK;

$response = STK::request(10)
    ->from(254722000000)
    ->usingReference('Some Reference', 'Test Payment')
    ->push();

/****** OR ********/
$response = STK::push(10, 254722000000, 'Some Reference', 'Test Payment');

Using the paybill_2 account:

use SmoDav\Mpesa\Laravel\Facades\STK;

$response = STK::request(10)
    ->from(254722000000)
    ->usingAccount('paybill_2')
    ->usingReference('Some Reference', 'Test Payment')
    ->push();

$response = STK::push(10, 254722000000, 'Some Reference', 'Test Payment', 'paybill_2');

Using the CustomerGoodsOnline command:

use SmoDav\Mpesa\Laravel\Facades\STK;

$response = STK::request(10)
    ->from(254722000000)
    ->usingReference('Some Reference', 'Test Payment')
    ->setCommand(CUSTOMER_BUYGOODS_ONLINE) 
    ->push();

$response = STK::push(10, 254722000000, 'Some Reference', 'Test Payment', null, CUSTOMER_BUYGOODS_ONLINE);

STK PUSH Transaction Validation

validate(merchantReferenceId, account = null)

Validate a C2B STK Push transaction.

Vanilla
use SmoDav\Mpesa\C2B\STK;

$stk = new STK($core);
    
$response = $stk->validate('ws_CO_16022018125');

Using the paybill_2 account:

$response = $stk->validate('ws_CO_16022018125', 'paybill_2');
Laravel
use SmoDav\Mpesa\Laravel\Facades\STK;

$response = STK::validate('ws_CO_16022018125');

Using the paybill_1 account:

use SmoDav\Mpesa\Laravel\Facades\STK;

$response = STK::validate('ws_CO_16022018125', 'paybill_2');
When going live, you should change the default value of the config file to the production account.

License

The M-Pesa Package is open-sourced software licensed under the MIT license.

mpesa's People

Contributors

codingedward avatar devmaurice avatar ejimba avatar kulemantu avatar laravel-shift avatar le-yo avatar smodav avatar swimlappy avatar weezqyd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpesa's Issues

Support for Laravel 7

When running the command composer require smodav/mpesa I get the following error

Using version ^5.0 for smodav/mpesa
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: remove laravel/framework v7.4.0
    - Conclusion: don't install laravel/framework v7.4.0
    - smodav/mpesa 5.0.x-dev requires illuminate/support ^5.0|^6.0 -> satisfiable by illuminate/support[5.0.x-dev, 5.1.x-dev, 5.2.x-dev, 5.3.x-dev, 5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.17, 5.7.18, 5.7.19, 5.7.x-dev, 5.8.x-dev, 6.x-dev, v5.0.0, v5.0.22, v5.0.25, v5.0.26, v5.0.28, v5.0.33, v5.0.4, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34, v5.5.35, v5.5.36, v5.5.37, v5.5.39, v5.5.40, v5.5.41, v5.5.43, v5.5.44, v5.6.0, v5.6.1, v5.6.10, v5.6.11, v5.6.12, v5.6.13, v5.6.14, v5.6.15, v5.6.16, v5.6.17, v5.6.19, v5.6.2, v5.6.20, v5.6.21, v5.6.22, v5.6.23, v5.6.24, v5.6.25, v5.6.26, v5.6.27, v5.6.28, v5.6.29, v5.6.3, v5.6.30, v5.6.31, v5.6.32, v5.6.33, v5.6.34, v5.6.35, v5.6.36, v5.6.37, v5.6.38, v5.6.39, v5.6.4, v5.6.5, v5.6.6, v5.6.7, v5.6.8, v5.6.9, v5.7.0, v5.7.1, v5.7.10, v5.7.11, v5.7.15, v5.7.2, v5.7.20, v5.7.21, v5.7.22, v5.7.23, v5.7.26, v5.7.27, v5.7.28, v5.7.3, v5.7.4, v5.7.5, v5.7.6, v5.7.7, v5.7.8, v5.7.9, v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.14.0, v6.15.0, v6.15.1, v6.16.0, v6.17.0, v6.17.1, v6.18.0, v6.18.1, v6.18.2, v6.18.3, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0].
    - smodav/mpesa v5.0.0 requires illuminate/support ^5.0|^6.0 -> satisfiable by illuminate/support[5.0.x-dev, 5.1.x-dev, 5.2.x-dev, 5.3.x-dev, 5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.17, 5.7.18, 5.7.19, 5.7.x-dev, 5.8.x-dev, 6.x-dev, v5.0.0, v5.0.22, v5.0.25, v5.0.26, v5.0.28, v5.0.33, v5.0.4, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34, v5.5.35, v5.5.36, v5.5.37, v5.5.39, v5.5.40, v5.5.41, v5.5.43, v5.5.44, v5.6.0, v5.6.1, v5.6.10, v5.6.11, v5.6.12, v5.6.13, v5.6.14, v5.6.15, v5.6.16, v5.6.17, v5.6.19, v5.6.2, v5.6.20, v5.6.21, v5.6.22, v5.6.23, v5.6.24, v5.6.25, v5.6.26, v5.6.27, v5.6.28, v5.6.29, v5.6.3, v5.6.30, v5.6.31, v5.6.32, v5.6.33, v5.6.34, v5.6.35, v5.6.36, v5.6.37, v5.6.38, v5.6.39, v5.6.4, v5.6.5, v5.6.6, v5.6.7, v5.6.8, v5.6.9, v5.7.0, v5.7.1, v5.7.10, v5.7.11, v5.7.15, v5.7.2, v5.7.20, v5.7.21, v5.7.22, v5.7.23, v5.7.26, v5.7.27, v5.7.28, v5.7.3, v5.7.4, v5.7.5, v5.7.6, v5.7.7, v5.7.8, v5.7.9, v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.14.0, v6.15.0, v6.15.1, v6.16.0, v6.17.0, v6.17.1, v6.18.0, v6.18.1, v6.18.2, v6.18.3, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0].
    - don't install illuminate/support 5.5.x-dev|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.16|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.17|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.2|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.28|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.33|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.34|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.35|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.36|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.37|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.39|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.40|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.41|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.43|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.5.44|don't install laravel/framework v7.4.0
    - don't install illuminate/support 5.6.x-dev|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.1|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.10|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.11|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.12|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.13|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.14|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.15|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.16|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.17|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.19|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.2|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.20|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.21|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.22|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.23|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.24|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.25|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.26|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.27|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.28|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.29|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.3|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.30|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.31|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.32|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.33|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.34|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.35|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.36|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.37|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.38|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.39|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.4|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.5|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.6|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.7|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.8|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.6.9|don't install laravel/framework v7.4.0
    - don't install illuminate/support 5.7.17|don't install laravel/framework v7.4.0
    - don't install illuminate/support 5.7.18|don't install laravel/framework v7.4.0
    - don't install illuminate/support 5.7.19|don't install laravel/framework v7.4.0
    - don't install illuminate/support 5.7.x-dev|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.1|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.10|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.11|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.15|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.2|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.20|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.21|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.22|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.23|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.26|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.27|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.28|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.3|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.4|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.5|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.6|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.7|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.8|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.7.9|don't install laravel/framework v7.4.0
    - don't install illuminate/support 5.8.x-dev|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.11|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.12|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.14|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.15|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.17|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.18|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.19|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.2|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.20|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.22|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.24|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.27|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.28|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.29|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.3|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.30|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.31|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.32|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.33|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.34|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.35|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.36|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.4|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.8|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.8.9|don't install laravel/framework v7.4.0
    - don't install illuminate/support 6.x-dev|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.0.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.0.1|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.0.2|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.0.3|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.0.4|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.1.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.10.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.11.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.12.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.13.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.13.1|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.14.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.15.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.15.1|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.16.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.17.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.17.1|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.18.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.18.1|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.18.2|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.18.3|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.2.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.3.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.4.1|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.5.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.5.1|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.5.2|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.6.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.6.1|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.6.2|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.7.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v6.8.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support 5.0.x-dev|don't install laravel/framework v7.4.0
    - don't install illuminate/support 5.1.x-dev|don't install laravel/framework v7.4.0
    - don't install illuminate/support 5.2.x-dev|don't install laravel/framework v7.4.0
    - don't install illuminate/support 5.3.x-dev|don't install laravel/framework v7.4.0
    - don't install illuminate/support 5.4.x-dev|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.0.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.0.22|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.0.25|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.0.26|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.0.28|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.0.33|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.0.4|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.1|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.13|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.16|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.2|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.20|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.22|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.25|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.28|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.30|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.31|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.41|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.6|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.1.8|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.19|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.21|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.24|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.25|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.26|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.27|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.28|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.31|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.32|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.37|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.43|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.45|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.6|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.2.7|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.3.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.3.16|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.3.23|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.3.4|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.4.0|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.4.13|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.4.17|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.4.19|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.4.27|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.4.36|don't install laravel/framework v7.4.0
    - don't install illuminate/support v5.4.9|don't install laravel/framework v7.4.0
    - Installation request for laravel/framework (locked at v7.4.0, required as ^7.0) -> satisfiable by laravel/framework[v7.4.0].
    - Installation request for smodav/mpesa ^5.0 -> satisfiable by smodav/mpesa[5.0.x-dev, v5.0.0].


Installation failed, reverting ./composer.json to its original content.

I'm assuming this is due to the library requiring older packages of the laravel framework. Any way we can get the library to support Laravel 7, or any other temporary workaround I can use?

Thanks. Issue also affects https://github.com/SmoDav/africastalking. Cheers!

REST API

Hi, can I use this code with safaricom REST API?

Determining Transaction Response

Hi,

How would I know, programmatically if the transaction was successful or unsuccessful? E.g if the client's account has insufficient balance to complete the transaction or if the money was wired successfully to my account?

Issue with alphanumeric STK validation

There is enforcement that the reference should be alphanumeric. This causes an issue where you'd like the reference to contain non-alphanumeric characters like ".", "_", "#" etc for some reason.

One common reason is KPLC account numbers have - for extensions. Another reason is for example someone buying a domain like domain.tld and you can't have the "." as it is currently.

I have tried without the validation and it works well with STK push so we shouldn't necessarily have this validation

ssl certificates

Hello,

How do you achieve the SSL certs installation? The ones provided by Safaricom? Kindly advice.

Reversals and B2C

Just a question, does this package support reversing transactions? Also does it support payments to customers from organizations bill number (B2C) ... if yes, any sample usage code?

Unable to initiate STK PUSH

i'm having trouble calling the stk class.i'm getting the following error:

SmoDav\Mpesa\Exceptions\ConfigurationException: Invalid consumer key and secret combination in file /var/www/DaiwasaApp/vendor/smodav/mpesa/src/Mpesa/Auth/Authenticator.php on line 101
Stack trace:
laravel 5.8

Unable to launch stk push

getting this error:

SmoDav\Mpesa\Exceptions\ConfigurationException: Invalid consumer key and secret combination in file /var/www/DaiwasaApp/vendor/smodav/mpesa/src/Mpesa/Auth/Authenticator.php on line 101

error in simulation

ErrorException in Simulate.php line 130:
Undefined property: SmoDav\Mpesa\C2B\Simulate::$store

ReferenceID

Why do you have to use numeric here even when any string works? Is it a limitation on Safaricom end? After commenting out this check, my call still works!

public function usingReferenceId($referenceId)
{
    if (!is_numeric($referenceId)) {
        throw new \InvalidArgumentException('The reference id must be numeric');
    }
    $this->referenceId = $referenceId;
    return $this;
}

Provision for both v1 and v2

You have made an update to only reference v1. what about we make it configurable to cover both v1 and v2?
In case Safaricom reintroduces v2 the SmoDav/mpesa package will still have provision for it.

Symfony Bundle

Can we get a Symfony Bundle or how do I use it in Symfony????

Add support for C2B transaction simulation

Hello,

I sent in a pull request for adding C2B transaction simulation #17. It was accepted and merged in, but I don't see it in stable yet. Is it still under testing or can this be added to a stable branch? I'm trying to avoid having to maintain a fork of my own to use that feature. Thanks

Jay

The operator does not exist

i'g getting this on my callback url after successfull CustomerBuyGoodsOnline

'Body' => 
  array (
    'stkCallback' => 
    array (
      'MerchantRequestID' => '7588-31800016-1',
      'CheckoutRequestID' => 'ws_CO_270920212128259339',
      'ResultCode' => 'SFC_IC0003',
      'ResultDesc' => 'The operator does not exist.',
    ),
  ),
)

Variable

what is some_secret_hash_key ?

authentication token

please illustrate how to get oauth authentication token both for test and production.

Testing mpesa by using Guzzle's MockHandler is not working out

Thanks for the package!

I use Laravel v6.0.4 and v4.1.0 of this package.

In general this package seems to be working fine. However, I went into an issue when trying to test our own implementation of this package by using Guzzle's Mock Handler.

$this->app->bind(Core::class, function ($app) {
            $config = $app->make(ConfigurationStore::class);
            $cache = $app->make(CacheStore::class);

            $mock = new MockHandler([
                new Response(200, [], json_encode([
                    'ResponseCode' => '0',
                    'expires_in' => 3600,
                    'access_token' => 'fake-token',
                ])),
                new Response(200, [], json_encode($fakeBodyResponse)),
            ]);
            $handler = new HandlerStack($mock);

            $client = new Client(['handler' => $handler]);

            return new Core($client, $config, $cache);
        });

When executing my test seperated it works fine, but when I run the whole testsuite it does not work. The reason seems to be the instance() method on the Core class (s. https://github.com/SmoDav/mpesa/blob/master/src/Mpesa/Engine/Core.php#L76-L87). Since the Core class is only resolved out of the app container once the binding from this packages (ServiceProvider)[https://github.com/SmoDav/mpesa/blob/master/src/Mpesa/Laravel/ServiceProvider.php#L43-L48] is used and my overriden binding is ignored.

Solution

I replaced the binding in your package with a singleton() and also resolve the Client out of the container by using Guzzle's ClientInterface. That way I wouldn't even need to override the binding of Core in my tests.

$this->app->singleton(Core::class, function ($app) {
            $config = $app->make(ConfigurationStore::class);
            $cache = $app->make(CacheStore::class);

            return new Core(resolve(ClientInterface::class), $config, $cache);
        });

But because of the instance() method in Core being used all over the place it only gets resolved once and can't get overriden or even accept a different Client out of the container. So, I basically replaced all Core::instance() calls with resolve(Core::class) and everything worked as supposed to.

Problem

I am aware that this package is not only for Laravel usage, but using the instance() method in a Laravel context doesn't make a lot of sense since you are basically trying to implement the singleton functionality which is already present in Laravel.


Also I am not very familiar with other frameworks, but as far as I am aware they do not tend to have an app() method which you call at https://github.com/SmoDav/mpesa/blob/master/src/Mpesa/Engine/Core.php#L83 anyways no matter which framework.

That being said, IMO if you want to maintain a vanilla PHP usable version and one for Laravel you should split those into two separate packages.

Hope that makes sense?!

Thanks for taking the time to read through this :).

Phone Number Validation

Safaricom phone numbers now begin with 1 instead of 7. So you should change your validate method in Traits\Validation to check startsWith("254").

Alternatively, you can just eliminate this check since MPesa is in use in Uganda and Tanzania also.

Thanks

Service Provider Not Found

The latest update to the package throws this error upon publishing

Class 'SmoDav\Mpesa\Laravel\ServiceProvider' not found

Is there a fix to this?

Correction of Identity request

The identity request should be

https://api.safaricom.co.ke/mpesa/checkidentity/v1/processrequest

and not

https://api.safaricom.co.ke/mpesa/checkidentity/v1/query

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.