0

我正在寻找关于在 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提供的额外处理脚本,我将不胜感激。

4

2 回答 2

1

ngrok 当然可以,但这是手动测试,并不是你应该如何测试的;)

您可以在此处阅读有关在本地测试条带 webhook 的更多信息:在此处输入链接描述

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

(完全披露:我和我的搭档写了博文和提到的包)

于 2015-04-23T11:17:56.160 回答
0

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

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

制作:http ://website.com/stripewebhooks

两种情况下的路线都是:

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

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

于 2015-02-19T18:34:05.360 回答