From a2c9abbf945970cd41e6bd7ac2b1940915e42557 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 11 Sep 2023 12:01:05 +1000 Subject: [PATCH] ACH Status checks --- app/Console/Kernel.php | 38 ++++++++------- app/Jobs/Ninja/CheckACHStatus.php | 79 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 app/Jobs/Ninja/CheckACHStatus.php diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 9da20b1020..c66cdc40e5 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -11,28 +11,29 @@ namespace App\Console; -use App\Jobs\Cron\AutoBillCron; -use App\Jobs\Cron\RecurringExpensesCron; -use App\Jobs\Cron\RecurringInvoicesCron; -use App\Jobs\Cron\SubscriptionCron; -use App\Jobs\Cron\UpdateCalculatedFields; -use App\Jobs\Invoice\InvoiceCheckLateWebhook; -use App\Jobs\Ninja\AdjustEmailQuota; -use App\Jobs\Ninja\BankTransactionSync; -use App\Jobs\Ninja\CompanySizeCheck; +use App\Utils\Ninja; +use App\Models\Account; use App\Jobs\Ninja\QueueSize; -use App\Jobs\Ninja\SystemMaintenance; -use App\Jobs\Ninja\TaskScheduler; -use App\Jobs\Quote\QuoteCheckExpired; -use App\Jobs\Subscription\CleanStaleInvoiceOrder; use App\Jobs\Util\DiskCleanup; use App\Jobs\Util\ReminderJob; -use App\Jobs\Util\SchedulerCheck; -use App\Jobs\Util\UpdateExchangeRates; +use App\Jobs\Cron\AutoBillCron; use App\Jobs\Util\VersionCheck; -use App\Models\Account; -use App\Utils\Ninja; +use App\Jobs\Ninja\TaskScheduler; +use App\Jobs\Util\SchedulerCheck; +use App\Jobs\Ninja\CheckACHStatus; +use App\Jobs\Cron\SubscriptionCron; +use App\Jobs\Ninja\AdjustEmailQuota; +use App\Jobs\Ninja\CompanySizeCheck; +use App\Jobs\Ninja\SystemMaintenance; +use App\Jobs\Quote\QuoteCheckExpired; +use App\Jobs\Util\UpdateExchangeRates; +use App\Jobs\Ninja\BankTransactionSync; +use App\Jobs\Cron\RecurringExpensesCron; +use App\Jobs\Cron\RecurringInvoicesCron; +use App\Jobs\Cron\UpdateCalculatedFields; use Illuminate\Console\Scheduling\Schedule; +use App\Jobs\Invoice\InvoiceCheckLateWebhook; +use App\Jobs\Subscription\CleanStaleInvoiceOrder; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; class Kernel extends ConsoleKernel @@ -109,6 +110,9 @@ class Kernel extends ConsoleKernel /* Pulls in bank transactions from third party services */ $schedule->job(new BankTransactionSync)->everyFourHours()->withoutOverlapping()->name('bank-trans-sync-job')->onOneServer(); + /* Checks ACH verification status and updates state to authorize when verified */ + $schedule->job(new CheckACHStatus)->everySixHours()->withoutOverlapping()->name('ach-status-job')->onOneServer(); + $schedule->command('ninja:check-data --database=db-ninja-01')->dailyAt('02:10')->withoutOverlapping()->name('check-data-db-1-job')->onOneServer(); $schedule->command('ninja:check-data --database=db-ninja-02')->dailyAt('02:20')->withoutOverlapping()->name('check-data-db-2-job')->onOneServer(); diff --git a/app/Jobs/Ninja/CheckACHStatus.php b/app/Jobs/Ninja/CheckACHStatus.php new file mode 100644 index 0000000000..a7f61b2552 --- /dev/null +++ b/app/Jobs/Ninja/CheckACHStatus.php @@ -0,0 +1,79 @@ +where('created_at', '>', now()->subMonths(2)) + ->where('gateway_type_id', 2) + ->whereHas('gateway', function ($q) { + $q->whereIn('gateway_key', ['d14dd26a37cecc30fdd65700bfb55b23','d14dd26a47cecc30fdd65700bfb67b34']); + }) + ->whereJsonContains('meta', ['state' => 'unauthorized']) + ->cursor() + ->each(function ($token) { + + try { + $stripe = $token->gateway->driver($token->client)->init(); + $pm = $stripe->getStripePaymentMethod($token->token); + + if($pm) { + + $meta = $token->meta; + $meta->state = 'authorized'; + $token->meta = $meta; + $token->save(); + + } + + } catch (\Exception $e) { + } + + }); + } + } +} \ No newline at end of file