Skip to content

Commit

Permalink
bc2 mpesa
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiru Njuguna committed Oct 27, 2017
0 parents commit 3f41ce3
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
============MPESA API=================

composer require thiru/mpesa

Add \Thiru\Mpesa\MpesaServiceProvider::class tp config/app.php

php artisan vendor:publish --tag=config
13 changes: 13 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "thiru/mpesa",
"require": {
"guzzlehttp/guzzle": "^6.3"
},
"authors": [
{
"name": "Thiru Njuguna",
"email": "[email protected]"
}
],
"minimum-stability": "dev"
}
16 changes: 16 additions & 0 deletions mpesa/src/B2C/B2CInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: thread
* Date: 10/28/17
* Time: 1:47 AM
*/
namespace Thiru\Mpesa\B2C;
interface B2CInterface
{
/**
* @param $data
* @return mixed
*/
public function sendMoney($data);
}
172 changes: 172 additions & 0 deletions mpesa/src/B2C/B2CRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: thread
* Date: 10/28/17
* Time: 1:47 AM
*/
namespace Thiru\Mpesa\B2C;

class B2CRepository implements B2CInterface
{
/**
* @param $authUrl
* @return mixed
*/
protected $authUrl;
/**
* @param $b2cUrl
* @return mixed
*/
protected $b2cUrl;
/**
* @param $publicKey
* @return mixed
*/
protected $publicKey;
/**
* @param $ConsumerSecret
* @return mixed
*/
protected $ConsumerSecret;

/**
* @param $ConsumerKey
* @return mixed
*/
protected $ConsumerKey;


/**
* @param $InitiatorPassword
* @return mixed
*/
protected $InitiatorPassword;

/**
* @param $default_header
* @return mixed
*/
protected $default_header = [
'Content-Type: application/json'
];

/**
* @param $access_token
* @return mixed
*/
protected $access_token;

/**
* B2CRepository constructor.
*/
public function __construct ()
{
$this->setAccessToken();
$this->setInitiatorPassword($this->getInitiatorPassword());
$this->setConsumerKey($this->getConsumerKey());
$this->setConsumerSecret($this->getConsumerSecret());
$this->setAuthUrl($this->getAuthUrl());
$this->setB2cUrl($this->getB2cUrl());

}

/**
* @param $data
* @return mixed
*/
public function sendMoney ($data)
{
// TODO: Implement sendMoney() method.
}

/**
* @param mixed $access_token
*/
public function setAccessToken ()
{

}

/**
* @param mixed $InitiatorPassword
*/
public function setInitiatorPassword ($InitiatorPassword)
{
$this->InitiatorPassword = $InitiatorPassword;
}

/**
* @return mixed
*/
public function getInitiatorPassword ()
{
return Config("mpesa.InitiatorPassword");
}
/**
* @return mixed
*/
public function getConsumerKey ()
{
return Config("mpesa.B2cConsumerKey");
}

/**
* @param mixed $ConsumerKey
*/
public function setConsumerKey ($ConsumerKey)
{
$this->ConsumerKey = $ConsumerKey;
}

/**
* @return mixed
*/
public function getConsumerSecret ()
{
return Config("mpesa.B2cConsumerSecret");
}

/**
* @param mixed $ConsumerSecret
*/
public function setConsumerSecret ($ConsumerSecret)
{
$this->ConsumerSecret = $ConsumerSecret;
}

/**
* @return mixed
*/
public function getAuthUrl ()
{

return Config('mpesa.is_live') == false ? '' : 'https://api.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials';
return $this->authUrl;
}

/**
* @param mixed $authUrl
*/
public function setAuthUrl ($authUrl)
{
$this->authUrl = $authUrl;
}

/**
* @return mixed
*/
public function getB2cUrl ()
{
return Config('mpesa.is_live') == true ? 'https://api.safaricom.co.ke/mpesa/b2c/v1/paymentrequest' : '';
}

/**
* @param mixed $b2cUrl
*/
public function setB2cUrl ($b2cUrl)
{
$this->b2cUrl = $b2cUrl;
}

}
13 changes: 13 additions & 0 deletions mpesa/src/C2B/B2CRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: thread
* Date: 10/28/17
* Time: 1:47 AM
*/
namespace Thiru\Mpesa\C2B;

class B2CRepository implements B2CInterface
{

}
12 changes: 12 additions & 0 deletions mpesa/src/C2B/C2BInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: thread
* Date: 10/28/17
* Time: 1:47 AM
*/
namespace Thiru\Mpesa\C2B;
interface C2BInterface
{

}
37 changes: 37 additions & 0 deletions mpesa/src/Config/mpesa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: thread
* Date: 10/28/17
* Time: 12:36 AM
*/
return [
/** @is_live true/false */
"is_live"=>false,
/** @InitiatorName */
"InitiatorName"=>"Maggie",

/** @InitiatorPassword */
"InitiatorPassword"=>"123456",

/** @B2cShortCode */
'B2cShortCode'=>"55555",

/** @B2cShortCode */
"C2bShortCode"=>"55555",

/** @B2cConsumerKey */
'B2cConsumerKey'=>'hhdGFHDgjdcscasd',

/** @B2cConsumerSecret */
'B2cConsumerSecret'=>'hhdGFHDgjdcscasd',

/** @C2bConsumerKey */
'C2bConsumerKey'=>'hhdGFHDgjdcscasd',

/** @C2bConsumerSecret */
'C2bConsumerSecret'=>'hhdGFHDgjdcscasd',


"message" => "I heard you the first time."
];
15 changes: 15 additions & 0 deletions mpesa/src/Facade/Mpesa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: thread
* Date: 10/28/17
* Time: 12:16 AM
*/
namespace Thiru\Mpesa\Facade;
use Illuminate\Support\Facades\Facade;

class Mpesa extends Facade
{
protected static function getFacadeAccessor() { return 'mpesa'; }

}
16 changes: 16 additions & 0 deletions mpesa/src/Mpesa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: thread
* Date: 10/28/17
* Time: 12:14 AM
*/

namespace Thiru\Mpesa;


class Mpesa
{


}
41 changes: 41 additions & 0 deletions mpesa/src/MpesaServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Thiru\Mpesa;

use Illuminate\Support\ServiceProvider;

class MpesaServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{


$this->publishes([__DIR__.'/Config/mpesa.php'=>config_path('mpesa.php')], 'config');
}

/**
* Register the application services.
*
* @return void
*/
public function register()
{
// Config

$this->mergeConfigFrom( __DIR__ . '/Config/mpesa.php','mpesa');
// $this->app['mpesa'] = $this->app->singleton(function($app) {
// return new Mpesa;
// });
// $this->app->bind(['mpesa' =>Mpesa::class], function () {
// // Do something here
// return new Mpesa();
// });
$this->app->alias(\Illuminate\Support\Str::class, 'Mpesa');
}

}

0 comments on commit 3f41ce3

Please sign in to comment.