mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Working on generic payment failure notification
This commit is contained in:
parent
e9d0ac30e2
commit
2474507790
@ -31,7 +31,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
||||
|
||||
public $client;
|
||||
|
||||
public $message;
|
||||
public $error;
|
||||
|
||||
public $company;
|
||||
|
||||
@ -47,11 +47,11 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
||||
* @param $company
|
||||
* @param $amount
|
||||
*/
|
||||
public function __construct($client, $message, $company, $payment_hash)
|
||||
public function __construct($client, $error, $company, $payment_hash)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
$this->message = $message;
|
||||
$this->error = $error;
|
||||
|
||||
$this->client = $client;
|
||||
|
||||
@ -92,7 +92,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
||||
if (($key = array_search('mail', $methods)) !== false) {
|
||||
unset($methods[$key]);
|
||||
|
||||
$mail_obj = (new PaymentFailureObject($this->client, $this->message, $this->amount, $this->company))->build();
|
||||
$mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->payment_hash))->build();
|
||||
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
|
||||
|
||||
//send email
|
||||
|
@ -28,7 +28,7 @@ class AutoBillingFailureObject
|
||||
|
||||
public $payment_hash;
|
||||
|
||||
private $invoice;
|
||||
private $invoices;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
@ -54,8 +54,7 @@ class AutoBillingFailureObject
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
$this->invoice = Invoice::where('id', $this->decodePrimarykey($this->payment_hash->invoices()[0]->invoice_id))->first();
|
||||
$this->$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get();
|
||||
|
||||
$mail_obj = new stdClass;
|
||||
$mail_obj->amount = $this->getAmount();
|
||||
@ -78,7 +77,7 @@ class AutoBillingFailureObject
|
||||
return
|
||||
ctrans(
|
||||
'texts.auto_bill_failed',
|
||||
['invoice_number' => $this->invoice->number]
|
||||
['invoice_number' => $this->invoices->first()->number]
|
||||
);
|
||||
}
|
||||
|
||||
@ -89,7 +88,7 @@ class AutoBillingFailureObject
|
||||
$data = [
|
||||
'title' => ctrans(
|
||||
'texts.auto_bill_failed',
|
||||
['invoice_number' => $this->invoice->number]
|
||||
['invoice_number' => $this->invoices->first()->number]
|
||||
),
|
||||
'message' => $this->error,
|
||||
'signature' => $signature,
|
||||
|
@ -11,29 +11,52 @@
|
||||
|
||||
namespace App\Mail\Admin;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Utils\Number;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use stdClass;
|
||||
|
||||
class PaymentFailureObject
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
public $client;
|
||||
|
||||
public $message;
|
||||
public $error;
|
||||
|
||||
public $company;
|
||||
|
||||
public $amount;
|
||||
public $payment_hash;
|
||||
|
||||
public function __construct($client, $message, $amount, $company)
|
||||
private $invoices;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $client
|
||||
* @param $message
|
||||
* @param $company
|
||||
* @param $amount
|
||||
*/
|
||||
public function __construct($client, $error, $company, $payment_hash)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->message = $message;
|
||||
$this->amount = $amount;
|
||||
|
||||
$this->error = $error;
|
||||
|
||||
$this->company = $company;
|
||||
|
||||
$this->payment_hash = $payment_hash;
|
||||
|
||||
$this->company = $company;
|
||||
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
$this->invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get();
|
||||
|
||||
$mail_obj = new stdClass;
|
||||
$mail_obj->amount = $this->getAmount();
|
||||
$mail_obj->subject = $this->getSubject();
|
||||
@ -46,16 +69,20 @@ class PaymentFailureObject
|
||||
|
||||
private function getAmount()
|
||||
{
|
||||
return Number::formatMoney($this->amount, $this->client);
|
||||
|
||||
return array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total;
|
||||
|
||||
}
|
||||
|
||||
private function getSubject()
|
||||
{
|
||||
|
||||
return
|
||||
ctrans(
|
||||
'texts.payment_failed_subject',
|
||||
['client' => $this->client->present()->name()]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private function getData()
|
||||
@ -65,23 +92,36 @@ class PaymentFailureObject
|
||||
$data = [
|
||||
'title' => ctrans(
|
||||
'texts.payment_failed_subject',
|
||||
['client' => $this->client->present()->name()]
|
||||
),
|
||||
'message' => ctrans(
|
||||
'texts.notification_payment_paid',
|
||||
['amount' => $this->getAmount(),
|
||||
'client' => $this->client->present()->name(),
|
||||
'message' => $this->message,
|
||||
]
|
||||
[
|
||||
'client' => $this->client->present()->name()
|
||||
]
|
||||
),
|
||||
'message' => $this->error,
|
||||
'signature' => $signature,
|
||||
'logo' => $this->company->present()->logo(),
|
||||
'settings' => $this->client->getMergedSettings(),
|
||||
'whitelabel' => $this->company->account->isPaid() ? true : false,
|
||||
'url' => config('ninja.app_url'),
|
||||
'button' => ctrans('texts.login'),
|
||||
'additional_info' => $this->buildFailedInvoices()
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function buildFailedInvoices()
|
||||
{
|
||||
|
||||
$text = '';
|
||||
|
||||
foreach($this->invoices as $invoice)
|
||||
{
|
||||
|
||||
$text .= ctrans('texts.notification_invoice_payment_failed_subject', ['invoice' => $invoice->number]) . "\n";
|
||||
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -91,27 +91,27 @@ class Charge
|
||||
|
||||
switch ($e) {
|
||||
case ($e instanceof CardException):
|
||||
$data['status'] => $e->getHttpStatus();
|
||||
$data['error_type'] => $e->getError()->type;
|
||||
$data['error_code'] => $e->getError()->code;
|
||||
$data['param'] => $e->getError()->param;
|
||||
$data['message'] => $e->getError()->message;
|
||||
$data['status'] = $e->getHttpStatus();
|
||||
$data['error_type'] = $e->getError()->type;
|
||||
$data['error_code'] = $e->getError()->code;
|
||||
$data['param'] = $e->getError()->param;
|
||||
$data['message'] = $e->getError()->message;
|
||||
break;
|
||||
case ($e instanceof RateLimitException):
|
||||
$data['message'] => 'Too many requests made to the API too quickly';
|
||||
$data['message'] = 'Too many requests made to the API too quickly';
|
||||
break;
|
||||
case ($e instanceof InvalidRequestException):
|
||||
$data['message'] => 'Invalid parameters were supplied to Stripe\'s API';
|
||||
$data['message'] = 'Invalid parameters were supplied to Stripe\'s API';
|
||||
break;
|
||||
case ($e instanceof AuthenticationException):
|
||||
$data['message'] => 'Authentication with Stripe\'s API failed';
|
||||
$data['message'] = 'Authentication with Stripe\'s API failed';
|
||||
break;
|
||||
case ($e instanceof ApiErrorException):
|
||||
$data['message'] => 'Network communication with Stripe failed';
|
||||
$data['message'] = 'Network communication with Stripe failed';
|
||||
break;
|
||||
|
||||
default:
|
||||
$data['message'] => $e->getMessage();
|
||||
$data['message'] = $e->getMessage();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,12 @@
|
||||
|
||||
<p>{{ $message }}</p>
|
||||
|
||||
@if(isset($additional_info))
|
||||
|
||||
<p> {{ $additional_info }}</p>
|
||||
|
||||
@endif
|
||||
|
||||
@component('email.components.button', ['url' => $url])
|
||||
@lang($button)
|
||||
@endcomponent
|
||||
|
Loading…
Reference in New Issue
Block a user