diff --git a/app/Jobs/Payment/EmailRefundPayment.php b/app/Jobs/Payment/EmailRefundPayment.php new file mode 100644 index 000000000000..6096061f6eef --- /dev/null +++ b/app/Jobs/Payment/EmailRefundPayment.php @@ -0,0 +1,108 @@ +payment = $payment; + $this->contact = $contact; + $this->company = $company; + $this->settings = $payment->client->getMergedSettings(); + } + + /** + * Execute the job. + * + * + * @return void + */ + public function handle() + { + if ($this->company->is_disabled) + return true; + + if ($this->contact->email) { + + MultiDB::setDb($this->company->db); + + $this->payment->load('invoices'); + $this->contact->load('client'); + + App::forgetInstance('translator'); + $t = app('translator'); + App::setLocale($this->contact->preferredLocale()); + $t->replace(Ninja::transformTranslations($this->settings)); + + $template_data['body'] = ''; + $template_data['subject'] = ''; + + $email_builder = (new PaymentEmailEngine($this->payment, $this->contact, $template_data))->build(); + + $invitation = null; + + if($this->payment->invoices && $this->payment->invoices->count() >=1) + $invitation = $this->payment->invoices->first()->invitations()->first(); + + $nmo = new NinjaMailerObject; + $nmo->mailable = new TemplateEmail($email_builder, $this->contact, $invitation); + $nmo->to_user = $this->contact; + $nmo->settings = $this->settings; + $nmo->company = $this->company; + $nmo->entity = $this->payment; + + NinjaMailerJob::dispatch($nmo); + + event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + } + } +} diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 113d9a1cde4c..584fef37652e 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -232,8 +232,6 @@ class Payment extends BaseModel public function refund(array $data) :self { return $this->service()->refundPayment($data); - - //return $this->processRefund($data); } /** diff --git a/app/Services/Payment/RefundPayment.php b/app/Services/Payment/RefundPayment.php index d846989cf8f3..c63ebc383404 100644 --- a/app/Services/Payment/RefundPayment.php +++ b/app/Services/Payment/RefundPayment.php @@ -64,6 +64,11 @@ class RefundPayment ->processGatewayRefund() //process the gateway refund if needed ->save(); + + if(array_key_exists('email_receipt', $this->refund_data) && $this->refund_data['email_receipt'] == 'true'){ + // $this->payment->service()->sendEmail(); + } + $transaction = [ 'invoice' => [], 'payment' => $this->payment->transaction_event(),