条纹收银台Webhook


Stripe Cashier Webhooks

我想澄清在Laravel文档中所述的Stripe Cash中使用webhook Controller的情况,因为我无法确认我的应用程序正在接收webhook事件:

http://laravel.com/docs/5.0/billing#handling-失败的付款

文档建议指向webhook控制器的路径如下:

Route::post('stripe/webhook', 'Laravel'Cashier'WebhookController@handleWebhook');

路由中的URI必须修改为我的Stripe设置中的URI。在测试环境中,我使用ngrok来公开我的本地服务器。

我想要澄清的是URI对于测试和生产来说应该是什么。为了测试,我应该只使用ngrok转发url吗(例如。http://3a4bfceb.ngrok.com),或者我需要在公共目录中有一个脚本来处理Stripe中的webhook事件。

我不确定控制器是否能够用handlePayload函数处理接收数据,或者我是否需要添加一个额外的php脚本(例如webhook.php),其中包含Stripe文档中描述的内容,例如:

// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account
Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxxxxxxx");
// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);
// Do something with $event_json
http_response_code(200); // PHP 5.4 or greater

如果有人能帮助测试和生产URI,以及是否需要除Cashier的WebhookController.php之外的其他处理脚本,我将不胜感激。

ngrok当然可以工作,但这是手动测试,而不是真正的测试方式;)

你可以在这里阅读更多关于在本地测试条纹webhook的信息:在这里输入链接描述

它使用了一个专门设计的包来实现自动webhook测试,而无需通过ngrok或其他任何方式暴露您的本地env。

(完全披露:我和我的合作伙伴写了博客文章并提到了包)

关于URI,本地/测试和生产URI类似于(假设使用ngrok):

本地/测试:http://3a4bfceb.ngrok.com/laravel/public/stripewebhooks

生产:http://website.com/stripewebhooks

这两种情况下的路线都是:

Route::post('stripewebhooks','Laravel'Cashier'WebhookController@handleWebhook');

WebhookController.php(它是Cashier包的一部分)处理所有传入事件,因此对于没有Cashier的实现,不需要创建像stripewebhooks.php这样的文件,该文件包含Stripe文档中描述的file_get_contents 200响应代码。