简体   繁体   中英

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...

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!

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' ];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM