问题描述
我已经使用库 https://github.com/spatie/laravel-stripe-webhooks
在 laravel 7 中实现了条纹 webhook目标是让我的用户订阅以条带形式创建的计划,并生成收费成功的网络钩子请求的发票。现在为了实现这一点,我创建了一个 cron 脚本,该脚本将作业分派给订阅用户。此外,在条带中设置一个 webhook 端点。所有设置都已完成并在环境变量中进行配置。将队列连接设置为“同步”时,它可以完美运行。但是,当设置队列连接到Redis时,它不起作用。
这是我的 config/stripe-webhooks.PHP
中的代码
<?PHP
return [
/*
* Stripe will sign each webhook using a secret. You can find the used secret at the
* webhook configuration settings: https://dashboard.stripe.com/account/webhooks.
*/
'signing_secret' => env('STRIPE_WEBHOOK_SECRET'),/*
* You can define the job that should be run when a certain webhook hits your application
* here. The key is the name of the Stripe event type with the `.` replaced by a `_`.
*
* You can find a list of Stripe webhook types here:
* https://stripe.com/docs/api#event_types.
*/
'jobs' => [
'charge_succeeded' => \App\Jobs\StripeWebhooks\ChargeSucceededJob::class,// 'source_chargeable' => \App\Jobs\StripeWebhooks\HandleChargeableSource::class,// 'charge_Failed' => \App\Jobs\StripeWebhooks\HandleFailedCharge::class,],/*
* The classname of the model to be used. The class should equal or extend
* Spatie\StripeWebhooks\ProcessstripeWebhookJob.
*/
'model' => \Spatie\StripeWebhooks\ProcessstripeWebhookJob::class,];
在调度 SubscribeCustomerJob 的命令中:
$subscribed = 0;
$users = User::role('admin')->where(function ($q) {
$q->where('stripe_id','!=',null)->where('verified_employees','>=',5);
})->get();
foreach ($users as $user) {
if ( $user->subscribed('default') && Now()->format('Y-m-d') >= $user->trial_ends_at->format('Y-m-d')) {
SubscribeCustomerJob::dispatch($user)->onQueue('api');
$subscribed++;
}
}
使用作业处理 webhook 请求
<?PHP
namespace App\Jobs\StripeWebhooks;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;
class HandleChargeableSource implements ShouldQueue
{
use InteractsWithQueue,Queueable,SerializesModels;
/** @var \Spatie\WebhookClient\Models\WebhookCall */
public $webhookCall;
public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}
public function handle()
{
// At this point,I store data to Payments table,// generate invoice and send email notification to subscribed user.
}
}
作业日志中的输出:
[2021-04-14 07:53:46][Nr84GbvR3kxqnBGRrrWHtkTj34XRYsGv] Processing: App\Jobs\SubscribeCustomerJob
[2021-04-14 07:53:53][Nr84GbvR3kxqnBGRrrWHtkTj34XRYsGv] Processed: App\Jobs\SubscribeCustomerJob
webhook_calls 中的内表: webhook_calls table click to see it
当队列连接设置为同步时,所有 thigs 都能很好地工作。但是,问题是当我将队列连接设置为“redis”时。
我知道 webhook 调用有效,因为 webhook_calls 表中有数据,但我想无法完成工作。
关于使用 redis 作为队列驱动程序的 Stripe webhook 和 laravel 的任何想法,请在下面添加您的评论并提前致谢。
解决方法
我已经解决了这个问题,我不小心在主管的队列工作器设置中放置了一个无效的队列名称。
[program:queue-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work --queue=api,notification
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/html/worker.log