dev-master
9999999-devLaravel Package implementation of the MPESA REST API
The Requires
by Timothy Radier
v1.0
1.0.0.0Laravel Package implementation of the MPESA REST API
The Requires
by Timothy Radier
                         Wallogit.com
                    
                    2017 © Pedro Peláez
                    
                    
                    
                    
                
                
            
Laravel Package implementation of the MPESA REST API
Laravel Package for the MPESA REST API, (*1)
From the command line inside your project directory, simply type:, (*2)
composer require knox/mpesa-rest, (*3)
NB: from laravel 5.5 due to autodiscovery the below can be skipped, (*4)
Add the service provider to the providers array in config/app.php:, (*5)
Knox\MPESA\MpesaServiceProvider::class, (*6)
Add the facade to the aliases array in config/app.php:, (*7)
'MPESA' => Knox\MPESA\Facades\MPESA::class, (*8)
Publish the configuration file and migrations by running the provided console command:, (*9)
php artisan vendor:publish --provider="Knox\MPESA\MpesaServiceProvider", (*10)
MPESA_ENV='live' for production and 'test' for sandboxbr/
MPESA_VERSION='v1' or 'v2'br/
MPESA_CONSUMER_KEY=consumer keybr/
MPESA_CONSUMER_SECRET=consumer secretbr/
MPESA_IDENTIFIER=shortcode shortcode or tillbr/
MPESA_SHORT_CODE=shortcodebr/
MPESA_PASSKEY=passkeybr/, (*11)
MPESA_INITIATOR_NAME=initiator usernamebr/
MPESA_INITIATOR_PASSWORD=initiator passwordbr/, (*12)
MPESA_B2C_TIMEOUT_URL=url in your sitebr/
MPESA_B2C_RESULT_URL=url in your sitebr/
MPESA_B2B_TIMEOUT_URL=url in your sitebr/
MPESA_B2B_RESULT_URL=url in your sitebr/, (*13)
MPESA_STK_CALLBACK_URL=url in your sitebr/
MPESA_C2B_VALIDATION_URL=url in your sitebr/
MPESA_C2B_CONFIRMATION_URL=url in your sitebr/, (*14)
MPESA_ACCOUNT_BALANCE_TIMEOUT_URL=url in your sitebr/
MPESA_ACCOUNT_BALANCE_CONFIRMATION_URL=url in your sitebr/, (*15)
MPESA_REVERSAL_TIMEOUT_URL=url in your sitebr/
MPESA_REVERSAL_CONFIRMATION_URL=url in your sitebr/, (*16)
MPESA_TRANSACTION_STATUS_TIMEOUT_URL=url in your sitebr/
MPESA_TRANSACTION_STATUS_CONFIRMATION_URL=url in your sitebr/, (*17)
MPESA_IDENTITY_CALLBACK_URL=url in your sitebr/, (*18)
At the top of your controller include the facadebr/
use MPESA;, (*19)
If you haven't registered the mpesa url callbacks then use the belowbr/, (*20)
use MPESA;
use Illuminate\Http\Request;
class PaymentsController extends Controller
{
    public function registerURL(){
        $mpesa = MPESA::registerC2bUrl();
    }
}
mpesa = MPESA::b2c('254700123456',10,'PromotionPayment', 'No Remarks');
mpesa = MPESA::b2b('600000',100,'BusinessPayBill',4,4, 'No Remarks',123456);
mpesa = MPESA::b2b('600000',100,'BusinessBuyGoods',4,4, 'No Remarks');
mpesa = MPESA::registerC2bUrl();
mpesa = MPESA::c2bSimulate('254700123456',100,'CustomerPayBillOnline','123456');
mpesa = MPESA::c2bSimulate('254700123456',1000,'CustomerBuyGoodsOnline');
mpesa = MPESA::getAccountBalance();
mpesa = MPESA::doReversal('ND893KKHX1', 100, 602984, 4);
mpesa = MPESA::stkPush('254700123456', 1000, 'Account 123');
mpesa = MPESA::stkQuery('ws_CO_14092017184227664');
mpesa = MPESA::getTransactionStatus('ND893KKHX1', null,4);
public function c2bConfirmation(Request $request)
{
    $response = json_decode($request->getContent(), true);
    $mpesa_transaction_id = $response['TransID'];
    $date_time = Carbon::parse($response['TransTime']);
    $amount = $response['TransAmount'];
    $account = strtoupper(preg_replace('/\s+/', '', $response['BillRefNumber']));
    $merchant_transaction_id = $response['ThirdPartyTransID'];
    $phone = $response['MSISDN'];
    $payer = preg_replace('!\s+!', ' ', ucwords(strtolower($response['FirstName'] . ' ' . $response['MiddleName'] . ' ' . $response['LastName'])));
}
Feel free to report any issues, (*21)
Laravel Package implementation of the MPESA REST API
Laravel Package implementation of the MPESA REST API