mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 15:14:33 -04:00
Updated flow
This commit is contained in:
parent
fd7c28880c
commit
7189c494ea
41
app/Livewire/Flow2/PaymentMethod.php
Normal file
41
app/Livewire/Flow2/PaymentMethod.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Livewire\Flow2;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Libraries\MultiDB;
|
||||
|
||||
class PaymentMethod extends Component
|
||||
{
|
||||
public $invoice;
|
||||
|
||||
public $context;
|
||||
|
||||
public $variables;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->invoice = $this->context['invoice'];
|
||||
$this->variables = $this->context['variables'];
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
MultiDB::setDb($this->invoice->company->db);
|
||||
|
||||
$methods = $this->invoice->client->service()->getPaymentMethods($this->invoice->balance);
|
||||
|
||||
return render('components.livewire.payment_method-flow2', ['methods' => $methods, 'amount' => $this->invoice->balance]);
|
||||
}
|
||||
}
|
52
app/Livewire/Flow2/ProcessPayment.php
Normal file
52
app/Livewire/Flow2/ProcessPayment.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Livewire\Flow2;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Services\ClientPortal\InstantPayment;
|
||||
|
||||
class ProcessPayment extends Component
|
||||
{
|
||||
|
||||
public $context;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
MultiDB::setDb($this->context['invoice']->company->db);
|
||||
|
||||
$invitation = InvoiceInvitation::find($this->context['invitation_id']);
|
||||
|
||||
$data = [
|
||||
'company_gateway_id' => $this->context['company_gateway_id'],
|
||||
'payment_method_id' => $this->context['gateway_type_id'],
|
||||
'payable_invoices' => [$this->context['payable_invoices']],
|
||||
'signature' => isset($this->context['signature']) ? $this->context['signature'] : false,
|
||||
'contact_first_name' => $invitation->contact->first_name ?? '',
|
||||
'contact_last_name' => $invitation->contact->last_name ?? '',
|
||||
'contact_email' => $invitation->contact->email ?? ''
|
||||
];
|
||||
|
||||
request()->replace($data);
|
||||
|
||||
return (new InstantPayment(request()))->run();
|
||||
|
||||
// return render($view->view, $view->data);
|
||||
}
|
||||
}
|
25
app/Livewire/Flow2/Signature.php
Normal file
25
app/Livewire/Flow2/Signature.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Livewire\Flow2;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Signature extends Component
|
||||
{
|
||||
|
||||
public function render()
|
||||
{
|
||||
return render('components.livewire.signature');
|
||||
}
|
||||
}
|
||||
|
35
app/Livewire/Flow2/Terms.php
Normal file
35
app/Livewire/Flow2/Terms.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Livewire\Flow2;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Terms extends Component
|
||||
{
|
||||
public $invoice;
|
||||
|
||||
public $context;
|
||||
|
||||
public $variables;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->invoice = $this->context['invoice'];
|
||||
$this->variables = $this->context['variables'];
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return render('components.livewire.terms');
|
||||
}
|
||||
}
|
@ -12,15 +12,16 @@
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Livewire\Flow2\Terms;
|
||||
use Livewire\Component;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Livewire\Flow2\PaymentMethod;
|
||||
use App\Livewire\Flow2\Signature;
|
||||
use Livewire\Attributes\On;
|
||||
use App\Livewire\Flow2\Terms;
|
||||
use App\Livewire\Flow2\Signature;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Reactive;
|
||||
use App\Livewire\Flow2\PaymentMethod;
|
||||
use App\Livewire\Flow2\ProcessPayment;
|
||||
|
||||
class InvoicePay extends Component
|
||||
{
|
||||
@ -30,33 +31,58 @@ class InvoicePay extends Component
|
||||
|
||||
public $settings;
|
||||
|
||||
private $invite;
|
||||
|
||||
private $variables;
|
||||
|
||||
public $terms_accepted = false;
|
||||
|
||||
public $signature_accepted = false;
|
||||
|
||||
public $payment_method_accepted = false;
|
||||
|
||||
public array $context = [];
|
||||
|
||||
#[On('update.context')]
|
||||
public function handleContext(string $property, $value): self
|
||||
{
|
||||
|
||||
data_set($this->context, $property, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[On('terms-accepted')]
|
||||
public function termsAccepted()
|
||||
{
|
||||
nlog("Terms accepted");
|
||||
// $this->invite = \App\Models\InvoiceInvitation::withTrashed()->find($this->invitation_id)->withoutRelations();
|
||||
$this->terms_accepted =true;
|
||||
}
|
||||
|
||||
#[On('signature-captured')]
|
||||
public function signatureCaptured($base64)
|
||||
{
|
||||
nlog("signature captured");
|
||||
|
||||
$this->signature_accepted = true;
|
||||
$this->invite = \App\Models\InvoiceInvitation::withTrashed()->find($this->invitation_id)->withoutRelations();
|
||||
$this->invite->signature_base64 = $base64;
|
||||
$this->invite->signature_date = now()->addSeconds($this->invite->contact->client->timezone_offset());
|
||||
$this->invite->save();
|
||||
$invite = \App\Models\InvoiceInvitation::withTrashed()->find($this->invitation_id)->withoutRelations();
|
||||
$invite->signature_base64 = $base64;
|
||||
$invite->signature_date = now()->addSeconds($invite->contact->client->timezone_offset());
|
||||
$this->context['signature'] = $base64;
|
||||
$invite->save();
|
||||
|
||||
}
|
||||
|
||||
#[On('terms-accepted')]
|
||||
public function termsAccepted()
|
||||
{
|
||||
nlog("Terms accepted");
|
||||
$this->invite = \App\Models\InvoiceInvitation::withTrashed()->find($this->invitation_id)->withoutRelations();
|
||||
$this->terms_accepted =true;
|
||||
#[On('payment-method-selected')]
|
||||
public function paymentMethodSelected($company_gateway_id, $gateway_type_id, $amount)
|
||||
{
|
||||
$this->context['company_gateway_id'] = $company_gateway_id;
|
||||
$this->context['gateway_type_id'] = $gateway_type_id;
|
||||
$this->context['amount'] = $amount;
|
||||
$this->context['pre_payment'] = false;
|
||||
$this->context['is_recurring'] = false;
|
||||
$this->context['payable_invoices'] = ['invoice_id' => $this->context['invoice']->hashed_id, 'amount' => $this->context['invoice']->balance];
|
||||
$this->context['invitation_id'] = $this->invitation_id;
|
||||
|
||||
// $this->invite = \App\Models\InvoiceInvitation::withTrashed()->find($this->invitation_id)->withoutRelations();
|
||||
$this->payment_method_accepted =true;
|
||||
}
|
||||
|
||||
#[Computed()]
|
||||
@ -68,7 +94,10 @@ class InvoicePay extends Component
|
||||
if(!$this->signature_accepted)
|
||||
return Signature::class;
|
||||
|
||||
return PaymentMethod::class;
|
||||
if(!$this->payment_method_accepted)
|
||||
return PaymentMethod::class;
|
||||
|
||||
return ProcessPayment::class;
|
||||
}
|
||||
|
||||
#[Computed()]
|
||||
@ -83,25 +112,19 @@ class InvoicePay extends Component
|
||||
MultiDB::setDb($this->db);
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
$this->invite = \App\Models\InvoiceInvitation::with('invoice','contact.client','company')->withTrashed()->find($this->invitation_id);
|
||||
$invoice = $this->invite->invoice;
|
||||
$company = $this->invite->company;
|
||||
$contact = $this->invite->contact;
|
||||
$client = $this->invite->contact->client;
|
||||
$this->variables = ($this->invite && auth()->guard('contact')->user()->client->getSetting('show_accept_invoice_terms')) ? (new HtmlEngine($this->invite))->generateLabelsAndValues() : false;
|
||||
|
||||
$this->settings = $client->getMergedSettings();
|
||||
|
||||
$invite = \App\Models\InvoiceInvitation::with('invoice','contact.client','company')->withTrashed()->find($this->invitation_id);
|
||||
$client = $invite->contact->client;
|
||||
$variables = ($invite && auth()->guard('contact')->user()->client->getSetting('show_accept_invoice_terms')) ? (new HtmlEngine($invite))->generateLabelsAndValues() : false;
|
||||
$settings = $client->getMergedSettings();
|
||||
$this->context['variables'] = $variables;
|
||||
$this->context['invoice'] = $invite->invoice;
|
||||
$this->context['settings'] = $settings;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return render('components.livewire.invoice-pay', [
|
||||
'context' => [
|
||||
'settings' => $this->settings,
|
||||
'invoice' => $this->invite->invoice,
|
||||
'variables' => $this->variables,
|
||||
],
|
||||
'context' => $this->context
|
||||
]);
|
||||
}
|
||||
}
|
@ -179,6 +179,21 @@ class PaymentMethod
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (($this->client->getSetting('use_credits_payment') == 'option' || $this->client->getSetting('use_credits_payment') == 'always') && $this->client->service()->getCreditBalance() > 0) {
|
||||
// Show credits as only payment option if both statements are true. //?this does not really make sense as it does nothing....
|
||||
// if (
|
||||
// $this->client->service()->getCreditBalance() > $this->amount
|
||||
// && $this->client->getSetting('use_credits_payment') == 'always') {
|
||||
// $payment_urls = [];
|
||||
// }
|
||||
|
||||
$this->payment_urls[] = [
|
||||
'label' => ctrans('texts.apply_credit'),
|
||||
'company_gateway_id' => CompanyGateway::GATEWAY_CREDIT,
|
||||
'gateway_type_id' => GatewayType::CREDIT,
|
||||
];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
1
public/build/assets/app-4cad835a.css
vendored
Normal file
1
public/build/assets/app-4cad835a.css
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,10 @@
|
||||
<div>
|
||||
@foreach($methods as $index => $method)
|
||||
|
||||
<button @click="$wire.dispatch('payment-method-selected', { company_gateway_id: {{ $method['company_gateway_id'] }}, gateway_type_id: {{ $method['gateway_type_id'] }}, amount: {{ $amount }} })">
|
||||
{{ $method['label'] }}
|
||||
</button>
|
||||
|
||||
@endforeach
|
||||
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user