diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index fcdbeacff4cd..f5cb923d5d68 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -114,7 +114,7 @@ class PaymentController extends Controller } else { $payment = PaymentFactory::create($payment_hash->fee_invoice->company_id, $payment_hash->fee_invoice->user_id); $payment->client_id = $payment_hash->fee_invoice->client_id; - $payment->save(); + $payment->saveQuietly(); $payment_hash->payment_id = $payment->id; $payment_hash->save(); @@ -122,6 +122,8 @@ class PaymentController extends Controller $payment = $payment->service()->applyCredits($payment_hash)->save(); + event('eloquent.created: App\Models\Payment', $payment); + if (property_exists($payment_hash->data, 'billing_context')) { $billing_subscription = \App\Models\Subscription::find($payment_hash->data->billing_context->subscription_id); diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 0e31981497c9..547638f0e1cb 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -236,7 +236,7 @@ class BaseDriver extends AbstractPaymentDriver $payment->type_id = $data['payment_type']; $payment->transaction_reference = $data['transaction_reference']; $payment->client_contact_id = $client_contact_id; - $payment->save(); + $payment->saveQuietly(); $this->payment_hash->payment_id = $payment->id; $this->payment_hash->save(); @@ -248,6 +248,8 @@ class BaseDriver extends AbstractPaymentDriver $payment->service()->updateInvoicePayment($this->payment_hash); + event('eloquent.created: App\Models\Payment', $payment); + if ($this->client->getSetting('client_online_payment_notification')) $payment->service()->sendEmail(); @@ -392,11 +394,9 @@ class BaseDriver extends AbstractPaymentDriver public function clientPaymentFailureMailer($error) { -nlog("outside"); if ($this->payment_hash && is_array($this->payment_hash->invoices())) { -nlog("inside"); $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer((new ClientPaymentFailureObject($this->client, $error, $this->client->company, $this->payment_hash))->build()); diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index 18a6cc1b3c89..2c21a228eff9 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -273,7 +273,9 @@ class BasePaymentDriver $paid_invoices = $payment_hash->invoices(); $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get(); $payment->invoices()->sync($invoices); - $payment->save(); + $payment->saveQuietly(); + + event('eloquent.created: App\Models\Payment', $payment); return $payment; } diff --git a/app/Services/Invoice/ApplyPaymentAmount.php b/app/Services/Invoice/ApplyPaymentAmount.php index e63de5e8b59a..4a71ae6c85d5 100644 --- a/app/Services/Invoice/ApplyPaymentAmount.php +++ b/app/Services/Invoice/ApplyPaymentAmount.php @@ -65,7 +65,7 @@ class ApplyPaymentAmount extends AbstractService $payment->currency_id = $this->invoice->client->getSetting('currency_id'); $payment->is_manual = true; /* Create a payment relationship to the invoice entity */ - $payment->save(); + $payment->saveQuietly(); $this->setExchangeRate($payment); @@ -103,6 +103,8 @@ class ApplyPaymentAmount extends AbstractService $this->invoice->service()->workFlow()->save(); + event('eloquent.created: App\Models\Payment', $payment); + return $this->invoice; } @@ -120,7 +122,7 @@ class ApplyPaymentAmount extends AbstractService //$payment->exchange_currency_id = $client_currency; // 23/06/2021 $payment->exchange_currency_id = $company_currency; - $payment->save(); + $payment->saveQuietly(); } diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 7b6bef89196b..98d003507ea4 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -175,6 +175,8 @@ class AutoBillInvoice extends AbstractService } + event('eloquent.created: App\Models\Payment', $payment); + $payment->ledger() ->updatePaymentBalance($amount * -1) ->save(); @@ -190,6 +192,7 @@ class AutoBillInvoice extends AbstractService ->updateCreditBalance($amount * -1, "Credit {$current_credit->number} used to pay down Invoice {$this->invoice->number}") ->save(); + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); return $this->invoice diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 654facfbc4f8..8f3db22f8921 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -64,7 +64,7 @@ class MarkPaid extends AbstractService if((int)$payment_type_id > 0) $payment->type_id = (int)$payment_type_id; - $payment->save(); + $payment->saveQuietly(); $this->setExchangeRate($payment); @@ -73,6 +73,8 @@ class MarkPaid extends AbstractService 'amount' => $payment->amount, ]); + event('eloquent.created: App\Models\Payment', $payment); + $this->invoice->next_send_date = null; $this->invoice->service() diff --git a/app/Services/Payment/PaymentService.php b/app/Services/Payment/PaymentService.php index 5e89ea905c31..39df23ef77ff 100644 --- a/app/Services/Payment/PaymentService.php +++ b/app/Services/Payment/PaymentService.php @@ -39,12 +39,14 @@ class PaymentService $payment->transaction_reference = ctrans('texts.manual_entry'); $payment->currency_id = $invoice->client->getSetting('currency_id'); /* Create a payment relationship to the invoice entity */ - $payment->save(); + $payment->saveQuietly(); $payment->invoices()->attach($invoice->id, [ 'amount' => $payment->amount, ]); + event('eloquent.created: App\Models\Payment', $payment); + return $payment; } @@ -145,7 +147,7 @@ class PaymentService public function save() { - $this->payment->save(); + $this->payment->saveQuietly(); return $this->payment->fresh(); }