![]() $result = json_decode((string)$response, true) $response = Mpesa::stkpush($phoneno, $amount, $account_number) $account_number = $request->input('account_number') $phoneno = $request->input('phonenumber') App/Http/Controllers/MpesaSTKPUSHController.php We can then add the logic to the stkpush method. Php artisan make:controller MpesaSTKPUSHController To integrate stkpush into your laravel application, you can create a new controller. This makes it easy for the customers to pay the amount with less friction as the only action needed from the customer is to authorize the transaction by entering their pin number. It contains all the prefilled details such as the business short code(pay bill), customer’s phone number, amount, and an Account Reference(Paybill’s Account Number). This API is used to initiate a transaction on behalf of a customer. How to integrate Mpesa Mpesa Express(STKPUSH) We can now start writing the Business Logic. With that, we have finished setting up the configurations. In development you can ignore running this command although in some cases you might need to run the command if you change any. This builds a configuration cache which Laravel uses when it requires any variable from the. env variables, ensure you run php artisan optimize if you are in production. Preferably if it is accessible through HTTPS. You will need to set the APP_URL variable to your desired app URL. 'reversal_timeout_url' => env('MPESA_REVERSAL_TIMEOUT_URL'), 'reversal_result_url' => env('MPESA_REVERSAL_RESULT_URL'), 'balance_timeout_url' => env('MPESA_BALANCE_TIMEOUT_URL'), 'balance_result_url' => env('MPESA_BALANCE_RESULT_URL'), 'status_timeout_url' => env('MPESA_STATUS_TIMEOUT_URL'), 'status_result_url' => env('MPESA_STATUS_RESULT_URL'), ![]() 'callback_url' => env('MPESA_CALLBACK_URL'), 'b2c_timeout_url' => env('MPESA_B2C_TIMEOUT_URL'), 'c2b_confirmation_url' => env('MPESA_C2B_CONFIRMATION_URL'), 'c2b_validation_url' => env('MPESA_C2B_VALIDATION_URL'), 'b2c_shortcode' => env('MPESA_B2C_SHORTCODE'), 'initiator_password' => env('MPESA_INITIATOR_PASSWORD'), 'initiator_name' => env('MPESA_INITIATOR_NAME', 'testapi'), ![]() 'mpesa_consumer_secret' => env('MPESA_CONSUMER_SECRET'), 'mpesa_consumer_key' => env('MPESA_CONSUMER_KEY'), This will publish a config/mpesa.php file which contains the configurations such as passkeys, consumer keys, etc. We can publish the configurations by running the mpesa:install command php artisan mpesa:install You can find comprehensive documentation on GitHub. I personally created this package to ease and speed up the development process. We then need to install a Laravel package. If not, you can create a new Laravel application. This tutorial assumes that you already have a laravel 8,9,10 application.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |