I have scheduled command php artisan charge:debts which has every minute scheduling option, but the problem it doubles the API request every time.
My Kernel.php:
$schedule->command('charge:debts')->everyMinute();
My console command function:
$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) {
...
}
}
Maybe someone can help how to avoid callng $stripe->tranfers->create two times? There is only one 'Debt' with status = 0 in the database :)