【问题标题】:Stripe Cashier WebhooksStripe Cashier Webhook
【发布时间】:2015-04-18 17:33:40
【问题描述】:

我正在寻找有关 Laravel 文档中描述的 Stripe Cashier 中 Webhook 控制器使用的说明,因为我无法确认我的应用程序正在接收 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 的帮助,以及是否需要超出 Cashier's WebhookController.php 提供的额外处理脚本,我将不胜感激。

【问题讨论】:

  • 根据我的经验,它可以与 ngrok 一起正常工作。

标签: php stripe-payments laravel-5 webhooks ngrok


【解决方案1】:

ngrok 当然可以,但这是手动测试,你不应该这样测试 ;)

您可以在此处阅读更多关于在本地测试条带 webhook 的信息:enter link description here

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

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

【讨论】:

    【解决方案2】:

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

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

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

    两种情况下的路线都是:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-18
      • 2017-05-17
      • 2018-07-26
      • 2021-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多