我已经安排了命令 php artisan charge:debts ,它具有每分钟调度选项,但问题是它每次都会使 API 请求翻倍。
我的内核.php:
$schedule->command('charge:debts')->everyMinute();
我的控制台命令功能:
$active_debts = Debt::where([['status', '=', 0]]) -> with('channels') -> get();
foreach($active_debts as $debt) {
try {
$stripe = new \Stripe\StripeClient(env('STRIPE_CODE'));
$stripe->transfers->create([
'amount' => $transfer_amount,
'currency' => $currency,
'destination' => 'XXXXXX',//acct_1GqQxFH4ie1ley5J
'transfer_group' => 'Pltaform fees',
], ['stripe_account' => $merchant_code]);
Debt::where('id', $debt->id) -> update([
'status' => 1
]);
} catch(\Stripe\Exception\InvalidRequestException $e) {
...
}
}
也许有人可以帮助如何避免调用 $stripe->tranfers->create 两次?数据库中只有一个状态 = 0 的“债务”:)