我在Laravel 5.1,条纹api 2015-10-16
我正在尝试处理:customer.subscription.deleted所以我要覆盖 handleCustomerSubscriptionDeleted 但该方法永远不会被调用..(即使我返回200响应而没有其他代码行条带记录500错误响应)
我按照文档中的说明进行路由:
Route::post('/stripe/webhook', 'WebhookController@handleWebhook');
自定义控制器:
namespace App\Http\Controllers;
use App\Abbonamento;
use Symfony\Component\HttpFoundation\Response;
use Laravel\Cashier\WebhookController as BaseController;
class WebhookController extends BaseController
{
/**
* Handle a stripe webhook.
*
* @param array $payload
* @return Response
*/
public function handleInvoicePaymentSucceeded($payload)
{
$subscription = $payload['data']['object']['subscription'];
$abbo = Abbonamento::bySubscription($subscription)->first();
if ($abbo)
{
$abbo->makeStripePayment($payload);
}
}
public function handleCustomerSubscriptionDeleted($payload)
{
$subscription = $payload['data']['object']['id'];
$abbo = Abbonamento::bySubscription($subscription)->first();
if ($abbo and $abbo->subscribed())
{
$abbo->subscription()->cancel();
}
return new Response('Webhook Handled', 200);
}
}
有人可以告诉我为什么“handleInvoicePaymentSucceeded”有效,但“handleCustomerSubscriptionDeleted”从未被调用过?
问题不在于我的自定义实体“Abbonamento”,这就是为什么我在customer.subscription.deleted的条带测试环境中看到总是错误500作为返回响应,以及一个ok响应 invoice.payment_succeeded
答案 0 :(得分:2)
问题是方法声明,
看着laravel.log我把它变成了:
public function handleCustomerSubscriptionDeleted(array $payload)
所以错过的部分是“阵列”