我正在寻找关于在 Laravel 文档中描述的 Stripe Cashier 中使用 Webhooks 控制器的说明,因为我无法确认我的应用程序正在接收 webhook 事件:
http://laravel.com/docs/5.0/billing#handling-failed-payments
文档建议将路由指向 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,以及是否需要超出 CashierWebhookController.php
提供的额外处理脚本,我将不胜感激。