1

我正在使用Laravel 5.4Laravel Cashier。我希望能够Stripe在我的localhost:8888

为此,我安装ultrahook并像这样启动它

超钩

http://stripe.leococo.ultrahook.com -> http://localhost:8888/stripe/webhook

Laravel 路线

Route::post('stripe/webhook', '\Laravel\Cashier\Http\Controllers\WebhookController@handleWebhook');

条纹 Webhook 配置

http://stripe.leococo.ultrahook.com

问题

当我发送webhook来自Stripe我得到Test webhook sent successfully

在终端ultrahook我得到这个

[2017-05-31 19:26:04] POST http://localhost:8888/stripe/webhook - 200

但似乎该handleWebhook功能没有被触发。它也不会停在断点上die('test')

我试过了php artisan route:clear php artisan config:clear。我不知道这是否正常,但我network在 Chrome Inspector 的部分中看不到任何内容

4

1 回答 1

1

Add the following line in your .env

CASHIER_ENV=testing

Laravel/Cashier checks if your call to the webhook has a valid event id. To verify this, eventExistsOnStripe calls back stripe servers with this event id to check its existence.

Here is the main webhook entry point from Laravel/Cashier 7.0:

public function handleWebhook(Request $request)
{
    $payload = json_decode($request->getContent(), true);

    if (! $this->isInTestingEnvironment() && ! $this->eventExistsOnStripe($payload['id'])) {
        return;
    }

    $method = 'handle'.studly_case(str_replace('.', '_', $payload['type']));

    if (method_exists($this, $method)) {
        return $this->{$method}($payload);
    } else {
        return $this->missingMethod();
    }
}

isInTestingEnvironment just check whether we are in a testing environnment or not : Thank you Cpt Obvious :)

protected function isInTestingEnvironment()
{
    return getenv('CASHIER_ENV') === 'testing';
}
于 2017-10-17T12:23:26.517 回答