【发布时间】:2017-07-27 02:45:31
【问题描述】:
我正在使用 Braintree 为使用 Laravel 5.2 构建的 SaaS 订阅网站收取费用,并使用 ngrok.io 在我的本地主机上对其进行测试。注册和初始费用工作正常。我也可以取消和恢复订阅。但是,我无法让自定义 webhook 工作。我正在关注 Laravel 文档。这是我的代码:
routes.php
Route::post('/webhook/braintree', 'BraintreeWebhookController@handleWebhook');
BraintreeWebhookController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Braintree\WebhookNotification;
use Laravel\Cashier\Http\Controllers\WebhookController;
use App\Transaction;
class BraintreeWebhookController extends WebhookController
{
//
public function handleSubscriptionChargedSuccessfully(WebhookNotification $notification)
{
$transaction = new Transaction();
$transaction->subscript_id = $notification->subscription->id;
$transaction->name = $notification->subscription->name;
$transaction->next_bill_date = $notification->subscription->next_bill_date;
$transaction->price = $notification->subscription->price;
$transaction->save();
return new Response('Webhook Handled', 200);
}
public function handleSubscriptionChargedUnsuccessfully(WebhookNotification $notification)
{
//
}
public function handleSubscriptionTrialEnded(WebhookNotification $notification)
{
//
}
}
Braintree Webhooks 测试 URL 链接返回“成功!服务器响应 200。”我使用测试表单测试了事务模型,它创建了一个数据库记录就好了。 Subscription_Charged_Successfully webhook 是没有通过控制器还是我在句柄函数中遗漏了什么?在这里的任何帮助将不胜感激。
【问题讨论】:
标签: php laravel webhooks braintree