Notify user if auto bill fails

This commit is contained in:
Hillel Coren 2017-03-23 15:55:46 +02:00
parent a9832cc8c3
commit fe3710fe4b
4 changed files with 43 additions and 6 deletions

View File

@ -58,12 +58,7 @@ class UserMailer extends Mailer
$view = ($notificationType == 'approved' ? ENTITY_QUOTE : ENTITY_INVOICE) . "_{$notificationType}";
$account = $user->account;
$client = $invoice->client;
if ($account->hasMultipleAccounts()) {
$link = url(sprintf('/account/%s?redirect_to=%s', $account->account_key, $invoice->present()->path));
} else {
$link = $invoice->present()->url;
}
$link = $invoice->present()->multiAccountLink;
$data = [
'entityType' => $entityType,
@ -116,6 +111,26 @@ class UserMailer extends Mailer
$this->sendTo($user->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data);
}
/**
* @param Invitation $invitation
*/
public function sendMessage($user, $subject, $message, $invoice)
{
if (! $user->email) {
return;
}
$view = 'user_message';
$data = [
'userName' => $user->getDisplayName(),
'primaryMessage' => $subject,
'secondaryMessage' => $message,
'invoiceLink' => $invoice->present()->multiAccountLink,
];
$this->sendTo($user->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data);
}
public function sendSecurityCode($user, $code)
{
if (! $user->email) {

View File

@ -279,4 +279,18 @@ class InvoicePresenter extends EntityPresenter
return ' - ' . $fee . ' ' . $label;
}
public function multiAccountLink()
{
$invoice = $this->entity;
$account = $invoice->account;
if ($account->hasMultipleAccounts()) {
$link = url(sprintf('/account/%s?redirect_to=%s', $account->account_key, $invoice->present()->path));
} else {
$link = $invoice->present()->url;
}
return $link;
}
}

View File

@ -136,6 +136,13 @@ class PaymentService extends BaseService
try {
return $paymentDriver->completeOnsitePurchase(false, $paymentMethod);
} catch (Exception $exception) {
if (! Auth::check()) {
$subject = trans('texts.auto_bill_failed', ['invoice_number' => $invoice->invoice_number]);
$message = sprintf('%s: %s', ucwords($paymentDriver->providerName()), $exception->getMessage());
$mailer = app('App\Ninja\Mailers\UserMailer');
$mailer->sendMessage($invoice->user, $subject, $message, $invoice);
}
return false;
}
}

View File

@ -2433,6 +2433,7 @@ $LANG = array(
'reset_counter' => 'Reset Counter',
'next_reset' => 'Next Reset',
'reset_counter_help' => 'Automatically reset the invoice and quote counters.',
'auto_bill_failed' => 'Auto-billing for invoice :invoice_number failed',
);