Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you process a paypal webhook event in PHP with Laravel?

I'm trying to integrate Paypal functionality into my site. I have installed the SDK and I'm able to make calls to the Paypal API.

My main task is to create invoices and then update the database when the customer pays the invoice. I'm able to create invoices properly, they show up under my sandbox notifications. I've also setup a sandbox webhook in my REST API app on Paypal, with a url provided. However, when I try to use the webhook simulator to generate an event (Invoice Paid), it doesn't seem that the function I've assigned to handle the post request is triggering.

So to review my issue...

  • A sandbox webhook is setup on Paypal for url https://www.example.com/webhook_test.

  • In my routes file, I have the following code to handle post requests.

Route::post('/webhook_test', 'WebhookController@InvoicePaid');

  • The InvoicePaid function is simply updating a table.

  • I try to use the webhook simulator on Paypal to simulate an "Invoice Paid" event to the url I've identified above, but when I check my table, nothing seems to have been updated.

Is there a step I'm missing in the overall setup? Any help would be appreciated!

like image 969
Nazir44 Avatar asked Nov 24 '16 06:11

Nazir44


1 Answers

I found the answer after digging around, in case anyone else runs into the same problem.

There's a class VerifyCsrfToken that had to be updated. Since paypal webhook post requests don't send a csrf token, then we need to add our webhook page to the exception list in this class.

ie: protected $except = [ 'invoiceWebhook' ];

like image 84
Nazir44 Avatar answered Nov 09 '22 23:11

Nazir44