简体   繁体   English

如何使用Laravel在PHP中处理Paypal Webhook事件?

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

I'm trying to integrate Paypal functionality into my site. 我正在尝试将Paypal功能集成到我的网站中。 I have installed the SDK and I'm able to make calls to the Paypal API. 我已经安装了SDK,并且可以调用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. 我还在Paypal上的REST API应用中设置了一个沙箱Webhook,并提供了网址。 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. 但是,当我尝试使用webhook模拟器生成事件(已付款发票)时,似乎我分配给处理过帐请求的功能并未触发。

So to review my issue... 因此,回顾我的问题...

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

  • The InvoicePaid function is simply updating a table. InvoicePaid函数只是在更新表。

  • 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. 我尝试在贝宝(Paypal)上使用webhook模拟器来模拟对上面确定的URL的“发票已付款”事件,但是当我检查表格时,似乎什么都没有更新。

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. 有一个类VerifyCsrfToken必须更新。 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. 由于Paypal Webhook发布请求不会发送csrf令牌,因此我们需要将Webhook页面添加到此类的异常列表中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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