invoice = $invoice; } /** * Execute the job. * * * @return void */ public function handle() { /* Create Payment */ $payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id); $payment->amount = $this->invoice->balance; $payment->status_id = Payment::STATUS_COMPLETED; $payment->client_id = $this->invoice->client_id; $payment->save(); /* Create a payment relationship to the invoice entity */ $payment->invoices()->save($this->invoice); $data = [ 'payment_id' => $payment->id, 'invoice_ids' => [ $this->invoice->id ] ]; event(new PaymentWasCreated($data)); /* Update Invoice balance */ $invoice = ApplyPaymentToInvoice::dispatchNow($payment, $this->invoice); UpdateCompanyLedgerWithPayment::dispatchNow($payment, $payment->amount); return $invoice; } }