guard('contact')->user()->client->getSetting('client_initiated_payments_minimum'); $data['title'] = ctrans('texts.amount'). " " .auth()->guard('contact')->user()->client->currency()->code." (".auth()->guard('contact')->user()->client->currency()->symbol . ")"; return $this->render('pre_payments.index', $data); } public function process(StorePrePaymentRequest $request) { $invoices = collect(); $invoice = InvoiceFactory::create(auth()->guard('contact')->user()->company_id, auth()->guard('contact')->user()->user_id); $invoice->due_date = now()->format('Y-m-d'); $invoice->is_proforma = true; $invoice->client_id = auth()->guard('contact')->user()->client_id; $line_item = new InvoiceItem(); $line_item->cost = $request->amount; $line_item->quantity = 1; $line_item->product_key = ctrans('texts.pre_payment'); $line_item->notes = $request->notes; $line_item->type_id = 1; $items = []; $items[] = $line_item; $invoice->line_items = $items; $invoice->number = ctrans('texts.pre_payment') . " " . now()->format('Y-m-d : H:i:s'); $invoice_repo = new InvoiceRepository(); $data = [ 'client_id' => $invoice->client_id, 'quantity' => 1, 'date' => now()->format('Y-m-d'), ]; $invoice = $invoice_repo->save($data, $invoice) ->service() ->markSent() ->fillDefaults() ->save(); //format totals $formatted_total = Number::formatMoney($request->amount, auth()->guard('contact')->user()->client); $payment_methods = auth()->guard('contact')->user()->client->service()->getPaymentMethods($request->amount); //if there is only one payment method -> lets return straight to the payment page $invoices->push($invoice); $data = [ 'settings' => auth()->guard('contact')->user()->client->getMergedSettings(), 'invoices' => $invoices, 'formatted_total' => $formatted_total, 'payment_methods' => $payment_methods, 'hashed_ids' => $invoices->pluck('hashed_id'), 'total' => $request->amount, 'pre_payment' => true, ]; nlog($data); return $this->render('invoices.payment', $data); } }