Laravel 5.3如何使用Braintree \ WebhookNotification

时间:2017-07-16 21:14:56

标签: laravel webhooks braintree

我正在使用Laravel 5.3并尝试在WebhookController中添加新的webhook事件处理程序

这是我的控制器

namespace App\Http\Controllers;

use Braintree\WebhookNotification;
use Laravel\Cashier\Http\Controllers\WebhookController as CashierController;

use Log;
use App\Models\BraintreeMerchant;

class WebhookController extends CashierController
{
    public function handleSubMerchantAccountApproved(WebhookNotification $notification)
    {
		if( isset($_POST["bt_signature"]) && isset($_POST["bt_payload"]))
		{
			$notification = Braintree_WebhookNotification::parse($_POST["bt_signature"], $_POST["bt_payload"]);
			
			$notification->kind == Braintree_WebhookNotification::SUB_MERCHANT_ACCOUNT_APPROVED;
			// true
			$notification->merchantAccount->status;
			// "active"
			$notification->merchantAccount->id;
			// "blue_ladders_store"
			$notification->merchantAccount->masterMerchantAccount->id;
			// "14ladders_marketplace"
			$notification->merchantAccount->masterMerchantAccount->status;
		}
    }
}

但收到以下错误消息: Container.php第763行中的BindingResolutionException: 目标[Braintree \ WebhookNotification]不可实例化。

1 个答案:

答案 0 :(得分:1)

我找到了答案。这是如何实现Braintree webhook控制器。

<?php

namespace App\Http\Controllers;

use Braintree\WebhookNotification;
use Laravel\Cashier\Http\Controllers\WebhookController as CashierController;
use Illuminate\Http\Request;

class WebhookController extends CashierController
{
    public function handleSubMerchantAccountApproved(Request $request)
    {
		$notification = WebhookNotification::parse($request->bt_signature, $request->bt_payload);
	
			$merchantId = $notification->merchantAccount->id;
			$result_merchant_status = $notification->merchantAccount->status;
    }
	
}