-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thiru Njuguna
committed
Oct 27, 2017
0 parents
commit 3f41ce3
Showing
10 changed files
with
342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
} |