diff --git a/app/Console/Commands/SendRecurringInvoices.php b/app/Console/Commands/SendRecurringInvoices.php index 6debedcd4001..2362184e8ccd 100644 --- a/app/Console/Commands/SendRecurringInvoices.php +++ b/app/Console/Commands/SendRecurringInvoices.php @@ -51,6 +51,28 @@ class SendRecurringInvoices extends Command $invoice = $this->invoiceRepo->createRecurringInvoice($recurInvoice); if ($invoice && !$invoice->isPaid()) { + $invoice->account->auto_bill_on_due_date; + + $autoBillLater = false; + if ($invoice->account->auto_bill_on_due_date) { + $autoBillLater = true; + } elseif ($paymentMethod = $this->paymentService->getClientDefaultPaymentMethod($invoice->client)) { + if ($paymentMethod && $paymentMethod->requiresDelayedAutoBill()) { + $autoBillLater = true; + } + } + + if($autoBillLater) { + if (empty($paymentMethod)) { + $paymentMethod = $this->paymentService->getClientDefaultPaymentMethod($invoice->client); + } + + if($paymentMethod) { + $invoice->autoBillPaymentMethod = $paymentMethod; + } + } + + $this->info('Sending Invoice'); $this->mailer->sendInvoice($invoice); } @@ -74,7 +96,7 @@ class SendRecurringInvoices extends Command $billNow = $invoice->account->auto_bill_on_due_date; if (!$billNow) { - $paymentMethod = $this->invoiceService->getClientDefaultPaymentMethod($invoice->client); + $paymentMethod = $this->paymentService->getClientDefaultPaymentMethod($invoice->client); if ($paymentMethod && $paymentMethod->requiresDelayedAutoBill()) { $billNow = true; diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 224d48785aea..9710fbb1df55 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -30,6 +30,7 @@ class ContactMailer extends Mailer 'viewButton', 'paymentLink', 'paymentButton', + 'autoBill', ]; public function __construct(TemplateService $templateService) @@ -106,6 +107,20 @@ class ContactMailer extends Mailer return $response; } + private function createAutoBillNotifyString($paymentMethod) { + if ($paymentMethod->payment_type_id == PAYMENT_TYPE_DIRECT_DEBIT) { + $paymentMethodString = trans('texts.auto_bill_payment_method_bank', ['bank'=>$paymentMethod->getBankName(), 'last4'=>$paymentMethod->last4]); + } elseif ($paymentMethod->payment_type_id == PAYMENT_TYPE_ID_PAYPAL) { + $paymentMethodString = trans('texts.auto_bill_payment_method_paypal', ['email'=>$paymentMethod->email]); + } else { + $code = str_replace(' ', '', strtolower($paymentMethod->payment_type->name)); + $cardType = trans("texts.card_" . $code); + $paymentMethodString = trans('texts.auto_bill_payment_method_credit_card', ['type'=>$cardType,'last4'=>$paymentMethod->last4]); + } + + return trans('texts.auto_bill_notification', ['payment_method'=>$paymentMethodString]); + } + private function sendInvitation($invitation, $invoice, $body, $subject, $pdfString, $documentStrings) { $client = $invoice->client; @@ -137,6 +152,11 @@ class ContactMailer extends Mailer 'amount' => $invoice->getRequestedAmount() ]; + if ($invoice->autoBillPaymentMethod) { + // Let the client know they'll be billed later + $variables['autobill'] = $this->createAutoBillNotifyString($invoice->autoBillPaymentMethod); + } + if (empty($invitation->contact->password) && $account->hasFeature(FEATURE_CLIENT_PORTAL_PASSWORD) && $account->enable_portal_password && $account->send_portal_password) { // The contact needs a password $variables['password'] = $password = $this->generatePassword(); diff --git a/app/Services/TemplateService.php b/app/Services/TemplateService.php index 5a41c705352d..cc3e1becc031 100644 --- a/app/Services/TemplateService.php +++ b/app/Services/TemplateService.php @@ -51,6 +51,7 @@ class TemplateService '$customInvoice1' => $account->custom_invoice_text_label1, '$customInvoice2' => $account->custom_invoice_text_label2, '$documents' => $documentsHTML, + '$autoBill' => empty($data['autobill'])?'':$data['autobill'], ]; // Add variables for available payment types diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index a5b74f646ff1..0443f37515ac 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1314,7 +1314,13 @@ $LANG = array( 'view_dashboard' => 'View Dashboard', 'client_session_expired' => 'Session Expired', - 'client_session_expired_message' => 'Your session has expired. Please click the link in your email again.' + 'client_session_expired_message' => 'Your session has expired. Please click the link in your email again.', + + 'auto_bill_notification' => 'This invoice will automatically be billed to :payment_method on the due date.', + 'auto_bill_payment_method_bank' => 'your :bank account ending in :last4', + 'auto_bill_payment_method_credit_card' => 'your :type card ending in :last4', + 'auto_bill_payment_method_paypal' => 'your PayPal account (:email)', + 'auto_bill_notification_placeholder' => 'This invoice will automatically be billed to your Visa card ending in 4242 on the due date.' ); return $LANG; diff --git a/resources/views/accounts/templates_and_reminders.blade.php b/resources/views/accounts/templates_and_reminders.blade.php index 87453e80dae6..aee11968b469 100644 --- a/resources/views/accounts/templates_and_reminders.blade.php +++ b/resources/views/accounts/templates_and_reminders.blade.php @@ -266,6 +266,7 @@ '{!! Form::flatButton('view_invoice', '#0b4d78') !!}$password', "{{ URL::to('/payment/...') }}$password", '{!! Form::flatButton('pay_now', '#36c157') !!}$password', + '{{ trans('texts.auto_bill_notification_placeholder') }}', ]; // Add blanks for custom values