gathuku / laravel_mpesa

A simple mpesa package for laravel framework | https://beyode.co.ke/mpesa
MIT License
48 stars 53 forks source link

callback url is notworking #18

Closed salman-007 closed 3 years ago

salman-007 commented 3 years ago

Hi,

thank you for the package and for the easy interface. i am facing some issue in it.

i get success message from $expressResponse=Mpesa::express(100,'254723341580','24242524','Testing Payment');

but it is not redirecting to the callback url which i defined in the mpesa.php file located in config folder.

i am using this payment gateway for first time. am i doing something wrong?

any help would be really appreciated.

thank you

gathuku commented 3 years ago

Hi @salman-007 Expose your callback URL using ngrok if you are testing locally. Ngrok has an inspection page where you can check if callback is hitting your URL.

salman-007 commented 3 years ago

i checked it there and it's showing 200 ok response and nothing else. does the callback is working directly or how the process in mpesa working, i am getting 200 ok response but it's not redirecting to the callback url.

salman-007 commented 3 years ago

i can see this message on success:

"MerchantRequestID":"326XX-978XXX-1", "CheckoutRequestID":"ws_CO_1612202011111XXXX", "ResponseCode": "0", "ResponseDescription":"Success. Request accepted for processing", "CustomerMessage":"Success. Request accepted for processing"

        it's not redirecting to callback URL
gathuku commented 3 years ago

@salman explain how you are doing it with code snippet. There's no redirection Daraja will make a POST resquest to the callback url you have provided. You will just ensure your callback url is reachable.

salman-007 commented 3 years ago

i created one route for calling a method which has express method in the controller as below:

public function mpesa() { $expressResponse=Mpesa::express(100,'254723341580','24242524','Testing Payment'); } and in config folder i have used below callback url in mpesa.php 'lnmocallback' => ' https://bb54f21ef6cd.ngrok.io/smartschol/mpesaReturn',

in my web.php Route::post('/mpesaReturns','paymentController@mpesaReturn')->name('mpesaReturn');

but it is not redirecting to this method after callback.

gathuku commented 3 years ago

@salman-007
With Callback

'lnmocallback' => ' https://bb54f21ef6cd.ngrok.io/api/smartschool/mpesaReturn',

Try adding the route in api.php

Route::post('smartschool/mpesaReturns','paymentController@mpesaReturn')->name('mpesaReturn');

or

Route::post('smartschool/mpesaReturns', function(Request $request){
    \Log::info($request->getContent());
});

What you have should also work but the route is wrong, should be

Route::post('/smartschool/mpesaReturns','paymentController@mpesaReturn')->name('mpesaReturn');

Also, ensure you have the right port exposed

./ngrok http 8000

if you are running laravel development server on port 8000

salman-007 commented 3 years ago

the smartschol is actually the folder name which is coming with every route by default so we don't need to add it in web.php

salman-007 commented 3 years ago

i want the user to redirect to a new view.

salman-007 commented 3 years ago

when i add Route::post('mpesaReturns','paymentController@mpesaReturn')->name('mpesaReturn'); to api.php it gives me an error on nrgrok that POST /api/smartschol/mpesaReturns | 404 Not Found

gathuku commented 3 years ago

you need to include smartschool in your route path or else you remove it in your callback URL

salman-007 commented 3 years ago

i am implementing this package in sandbox for testing so why is it saying insufficient balance `{ "Body": {

    "stkCallback": {
        "MerchantRequestID": "25XXX-32XXXXX-X",
        "CheckoutRequestID": "ws_CO_181220201625XXXXXX",
        "ResultCode": 1,
        "ResultDesc": "The balance is insufficient for the transaction"
    }
}

}`

gathuku commented 3 years ago

Maybe you don't have sufficient balance in your mpesa. Test with less amount 1 or 10

Or try again sometimes it can be issued on their side