【发布时间】:2021-01-05 18:33:43
【问题描述】:
你好,我是 laravel 的新手,我建立了一个电子商务平台(细节不重要) 无论如何,我的问题是我创建了一条可以从 paypal webhook 捕获所有事件的路由,但是当我直接访问它时它正在工作,但是当我从 paypal webhook Simulator 尝试时,或者即使沙箱付款没有通过 我知道问题出在 csrf 验证中,我尝试排除路由但没有用,还尝试创建一个新的 RouteServiceProvider 这是我在控制器中的代码,因此我可以从请求中捕获任何内容
$headers = getallheaders();
file_put_contents("/home/username/public_html/test.txt", json_encode($headers));
这是我的路线
Route::domain(env("APP_DOMAIN"))->group(function () {
Route::get('/paypal/n', 'HomeController@notifications');
});
我使用 domain(env("APP_DOMAIN")) 因为每个人都可以添加自己的域,我希望它只在主域中工作。
RouteServiceProvider 中的代码
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapPaymentRoutes();
//
}
protected function mapPaymentRoutes()
{
Route::middleware('payment')
->namespace($this->namespace)
->group(base_path('routes/payment.php'));
}
当然,我确实在文件 Kernel.php 中定义了支付中间件并注释了 VerifyCsrfToken 类
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'payment' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
// \App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
即使有这一切,像很多测试一样,我还是无法让它工作 如果我向纯 php 文件发送请求,它工作正常。 你能帮我解决这个问题吗?我试图自己找到解决方案,但我花了 15 天的时间没有任何运气 我使用 laravel 6。
【问题讨论】:
-
不要将任何中间件应用于该路由...不需要会话或 cookie 或任何这些,因为 paypal 不会发送任何...您可能需要的唯一中间件是一个验证请求实际上来自贝宝......旁注:不要在配置文件之外调用
env(如果你缓存你的配置,所有对env的调用都将返回null) -
paypal 是否显示 webhook 尝试的任何错误?
-
no paypal 没有给出关于 webhook 响应的任何信息
标签: php laravel paypal-webhooks