diff --git a/app/Models/Client.php b/app/Models/Client.php index e573b5feba2c..1863120f223f 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -272,6 +272,15 @@ class Client extends EntityModel return AccountGatewayToken::clientAndGateway($this->id, $accountGateway->id)->first(); } + public function defaultPaymentMethod() + { + if ($token = $this->getGatewayToken()) { + return $token->default_payment_method; + } + + return false; + } + public function autoBillLater() { if ($token = $this->getGatewayToken()) { diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 6ed657d15747..5f8be4eb4530 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -138,12 +138,10 @@ class ContactMailer extends Mailer 'amount' => $invoice->getRequestedAmount() ]; - /* + // Let the client know they'll be billed later if ($client->autoBillLater()) { - // Let the client know they'll be billed later - $variables['autobill'] = $this->createAutoBillNotifyString($invoice->autoBillPaymentMethod); + $variables['autobill'] = $invoice->present()->autoBillEmailMessage(); } - */ if (empty($invitation->contact->password) && $account->hasFeature(FEATURE_CLIENT_PORTAL_PASSWORD) && $account->enable_portal_password && $account->send_portal_password) { // The contact needs a password @@ -282,19 +280,4 @@ class ContactMailer extends Mailer $this->sendTo($email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data); } - /* - 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_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]); - } - */ } diff --git a/app/Ninja/PaymentDrivers/WePayPaymentDriver.php b/app/Ninja/PaymentDrivers/WePayPaymentDriver.php index 13456e8f532f..497f86da2ec2 100644 --- a/app/Ninja/PaymentDrivers/WePayPaymentDriver.php +++ b/app/Ninja/PaymentDrivers/WePayPaymentDriver.php @@ -7,6 +7,8 @@ use Exception; class WePayPaymentDriver extends BasePaymentDriver { + protected $sourceReferenceParam = 'accessToken'; + public function gatewayTypes() { $types = [ diff --git a/app/Ninja/Presenters/InvoicePresenter.php b/app/Ninja/Presenters/InvoicePresenter.php index 1c77ef1b09e7..282f5506cd83 100644 --- a/app/Ninja/Presenters/InvoicePresenter.php +++ b/app/Ninja/Presenters/InvoicePresenter.php @@ -73,4 +73,29 @@ class InvoicePresenter extends EntityPresenter { $client = $this->entity->client; return count($client->contacts) ? $client->contacts[0]->email : ''; } + + public function autoBillEmailMessage() + { + $client = $this->entity->client; + $paymentMethod = $client->defaultPaymentMethod(); + + if ( ! $paymentMethod) { + return false; + } + + if ($paymentMethod->payment_type_id == PAYMENT_TYPE_ACH) { + $paymentMethodString = trans('texts.auto_bill_payment_method_bank_transfer'); + } elseif ($paymentMethod->payment_type_id == PAYMENT_TYPE_PAYPAL) { + $paymentMethodString = trans('texts.auto_bill_payment_method_paypal'); + } else { + $paymentMethodString = trans('texts.auto_bill_payment_method_credit_card'); + } + + $data = [ + 'payment_method' => $paymentMethodString, + 'due_date' => $this->due_date(), + ]; + + return trans('texts.auto_bill_notification', $data); + } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 27ab164f530b..f13bf56ec19a 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1328,11 +1328,11 @@ $LANG = array( 'client_session_expired' => 'Session Expired', '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.', + 'auto_bill_notification' => 'This invoice will automatically be billed to your :payment_method on file on :due_date.', + 'auto_bill_payment_method_bank_transfer' => 'bank account', + 'auto_bill_payment_method_credit_card' => 'credit card', + 'auto_bill_payment_method_paypal' => 'PayPal account', + 'auto_bill_notification_placeholder' => 'This invoice will automatically be billed to your credit card on file on the due date.', 'payment_settings' => 'Payment Settings', 'on_send_date' => 'On send date',