diff --git a/app/Mail/RecurringInvoice/ClientContactRequestCancellationObject.php b/app/Mail/RecurringInvoice/ClientContactRequestCancellationObject.php
index a0c5bdca62ad..5201fc07f5a6 100644
--- a/app/Mail/RecurringInvoice/ClientContactRequestCancellationObject.php
+++ b/app/Mail/RecurringInvoice/ClientContactRequestCancellationObject.php
@@ -11,35 +11,33 @@
namespace App\Mail\RecurringInvoice;
+use App\Models\ClientContact;
+use App\Models\RecurringInvoice;
use App\Utils\Ninja;
use Illuminate\Support\Facades\App;
class ClientContactRequestCancellationObject
{
- public $recurring_invoice;
- public $client_contact;
-
- private $company;
-
- public function __construct($recurring_invoice, $client_contact)
- {
- $this->recurring_invoice = $recurring_invoice;
- $this->client_contact = $client_contact;
- $this->company = $recurring_invoice->company;
- }
+ public function __construct(public RecurringInvoice $recurring_invoice, public ClientContact $client_contact, private bool $gateway_refund_attempted){}
public function build()
{
+ $this->company = $this->recurring_invoice->company;
+
App::forgetInstance('translator');
App::setLocale($this->company->getLocale());
$t = app('translator');
$t->replace(Ninja::transformTranslations($this->company->settings));
+ $content = ctrans('texts.recurring_cancellation_request_body', ['contact' => $this->client_contact->present()->name(), 'client' => $this->client_contact->client->present()->name(), 'invoice' => $this->recurring_invoice->number]);
+
+ if($this->gateway_refund_attempted)
+ $content .= "\n\n" . ctrans('texts.status') . " : " . ctrans('texts.payment_status_6');
$data = [
'title' => ctrans('texts.recurring_cancellation_request', ['contact' => $this->client_contact->present()->name()]),
- 'content' => ctrans('texts.recurring_cancellation_request_body', ['contact' => $this->client_contact->present()->name(), 'client' => $this->client_contact->client->present()->name(), 'invoice' => $this->recurring_invoice->number]),
+ 'content' => $content,
'url' => config('ninja.web_url'),
'button' => ctrans('texts.account_login'),
'signature' => $this->company->settings->email_signature,
diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php
index fd517f04d169..b4902dc868e5 100644
--- a/app/Services/Subscription/SubscriptionService.php
+++ b/app/Services/Subscription/SubscriptionService.php
@@ -1179,11 +1179,15 @@ class SubscriptionService
{
$invoice_start_date = false;
$refund_end_date = false;
+ $gateway_refund_attempted = false;
//only refund if they are in the refund window.
$outstanding_invoice = Invoice::where('subscription_id', $this->subscription->id)
->where('client_id', $recurring_invoice->client_id)
+ ->where('status_id', Invoice::STATUS_PAID)
->where('is_deleted', 0)
+ ->where('is_proforma',0)
+ ->where('balance',0)
->orderBy('id', 'desc')
->first();
@@ -1199,7 +1203,7 @@ class SubscriptionService
$recurring_invoice_repo->archive($recurring_invoice);
/* Refund only if we are in the window - and there is nothing outstanding on the invoice */
- if($refund_end_date && $refund_end_date->greaterThan(now()) && (int)$outstanding_invoice->balance == 0)
+ if($refund_end_date && $refund_end_date->greaterThan(now()))
{
if($outstanding_invoice->payments()->exists())
@@ -1208,8 +1212,9 @@ class SubscriptionService
$data = [
'id' => $payment->id,
- 'gateway_refund' => true,
+ 'gateway_refund' => $outstanding_invoice->amount >= 1 ? true : false,
'send_email' => true,
+ 'email_receipt',
'invoices' => [
['invoice_id' => $outstanding_invoice->id, 'amount' => $outstanding_invoice->amount],
],
@@ -1217,6 +1222,7 @@ class SubscriptionService
];
$payment->refund($data);
+ $gateway_refund_attempted = true;
}
}
@@ -1232,7 +1238,7 @@ class SubscriptionService
$this->triggerWebhook($context);
$nmo = new NinjaMailerObject;
- $nmo->mailable = (new NinjaMailer((new ClientContactRequestCancellationObject($recurring_invoice, auth()->guard('contact')->user()))->build()));
+ $nmo->mailable = (new NinjaMailer((new ClientContactRequestCancellationObject($recurring_invoice, auth()->guard('contact')->user(), $gateway_refund_attempted))->build()));
$nmo->company = $recurring_invoice->company;
$nmo->settings = $recurring_invoice->company->settings;
diff --git a/resources/views/index/index.blade.php b/resources/views/index/index.blade.php
index bdce834ae5fa..2d95233ce2f3 100644
--- a/resources/views/index/index.blade.php
+++ b/resources/views/index/index.blade.php
@@ -10,11 +10,21 @@
@if(\App\Utils\Ninja::isHosted())
+
+
+
+
+
+
@endif