diff --git a/app/Console/Commands/ChargeRenewalInvoices.php b/app/Console/Commands/ChargeRenewalInvoices.php index 0e9ef0e4c071..df3ee079a9d5 100644 --- a/app/Console/Commands/ChargeRenewalInvoices.php +++ b/app/Console/Commands/ChargeRenewalInvoices.php @@ -6,7 +6,6 @@ use App\Ninja\Repositories\AccountRepository; use App\Services\PaymentService; use App\Models\Invoice; use App\Models\Account; -use Exception; /** * Class ChargeRenewalInvoices @@ -81,11 +80,10 @@ class ChargeRenewalInvoices extends Command continue; } - try { - $this->info("Charging invoice {$invoice->invoice_number}"); - $this->paymentService->autoBillInvoice($invoice); - } catch (Exception $exception) { - $this->info('Error: ' . $exception->getMessage()); + $this->info("Charging invoice {$invoice->invoice_number}"); + if ( ! $this->paymentService->autoBillInvoice($invoice)) { + $this->info('Failed to auto-bill, emailing invoice'); + $this->mailer->sendInvoice($invoice); } } diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 68c696695e49..4e66a8fe0dc8 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -3,6 +3,7 @@ use App\Models\Invoice; use Utils; use Auth; +use Exception; use App\Models\Account; use App\Models\Client; use App\Models\Activity; @@ -120,7 +121,11 @@ class PaymentService extends BaseService } } - return $paymentDriver->completeOnsitePurchase(false, $paymentMethod); + try { + return $paymentDriver->completeOnsitePurchase(false, $paymentMethod); + } catch (Exception $exception) { + return false; + } } public function getDatatable($clientPublicId, $search)