billowapp / payfast

Basic Laravel Package For ITN Payments through Payfast
MIT License
27 stars 37 forks source link

Is it in the working mode? #3

Closed hardiksonchhabda closed 7 years ago

hardiksonchhabda commented 7 years ago

Payfast is sending back to return url and I am unable to access the request array or $payfast. Please help me in this, I have spent 3-4 hours already with no success. Thanks!

billowapp commented 7 years ago

Hey there, please make sure that you have put the route that responds to the ITN callback within the $except array in this file: App\Http\Middleware\VerifyCsrfToken.php

Also this can only be done on a live URL. Localhost wont run.

I can't really see any of your code, but i would suggest watching the laravel.log to see where its going wrong.

hardiksonchhabda commented 7 years ago

Hello mate, thanks for the reply.

In your example, you have written that "Payfast will send a POST request to notify the merchant (You) with a status on the transaction.", does it mean all 3 routes - Notify, Return and Cancel has to be the post routes and must be set in the App\Http\Middleware\VerifyCsrfToken.php file?

In my case, I have removed App\Http\Middleware\VerifyCsrfToken.php from kernal.php and we are not using csrf token anywhere in the site.

I have set all 3 return routes as post route and I am getting error on call back from payfast.

Yes, I am still checking in local and will move it to live to test, once I resolve the route errors.

Thanks!

billowapp commented 7 years ago

Ok cool, its not going to work until you put it on a live URL. Payfast has no way to resolve localhost on your machine, get it online and you'll start getting the responses.

hardiksonchhabda commented 7 years ago

Hey mate, yes it works on the live url. Works perfect.

Any idea if we can get response variables on success page (Return url) ? Thanks for the help and it is a very good repository.

billowapp commented 7 years ago

Hey man, glad its working. You cant get any information back on the success page from Payfast. It's literally just a redirect back to your chosen page. I would suggest binding an ID into your success url so that your app can take over and display what you need there.

ie. /orders/1/successful

then you can gather any info needed to display.

hardiksonchhabda commented 7 years ago

Yes mate, I was thinking something like that. We can store the required ID in session and then use it also. Both ways it should work I guess.

Anyways, thanks for your prime time, Looking forward to be in touch again sometimes.

Thanks for the help!

SwCharlie commented 7 years ago

Hi there

Based on the above questions/answers above, I am assuming the following should not be working, as there is no array/variable ($payfast) returned from Payfast? How would one confirm for which order the payment should be marked as "paid", if I just let it display "payment successful"?

Update: I was a bit confused with the various variables, but have my routes as follows now: Route::get('/payment', 'PaymentController@confirmPayment'); //from example function confirmPayment Route::get('/success', 'PaymentController@success'); //returns "success" Route::get('/itn', 'PaymentController@itn'); //from example function itn

also tried changing Route::get('/itn', 'PaymentController@itn'); //from example function itn to: Route::post('/itn', 'PaymentController@itn'); //from example function itn

and within the itn function I have: $entry = Order::find(1); $entry->is_paid = 1; $entry->status = "paid"; $entry->save();

But this does not update accordingly.

Update: Got it working now. Had an error with calling Order, with the following main considerations: routes file: Route::get('/payment', 'PaymentController@confirmPayment'); //from example function confirmPayment Route::get('/success', 'PaymentController@success'); //returns "success" Route::post('/itn', 'PaymentController@itn'); //from example function itn

and VerifyCsrfToken.php: protected $except = [ // '/itn', ];

Thanks for the contribution :)

billowapp commented 7 years ago

You can also pass through custom strings and custom integers, if you take a look at the source there are methods for that.

Another option is to bind the Order Id to your Success URL

mugotech commented 4 years ago

I suggest to use ngrok for local testing of payfast. It works best for me always.