diff --git a/app/Livewire/Flow2/PaymentMethod.php b/app/Livewire/Flow2/PaymentMethod.php index 2014159e98be..794cee2535d4 100644 --- a/app/Livewire/Flow2/PaymentMethod.php +++ b/app/Livewire/Flow2/PaymentMethod.php @@ -26,7 +26,7 @@ class PaymentMethod extends Component public $methods = []; - public $isLoading = true; + public $isLoading = false; public $amount = 0; diff --git a/app/Livewire/Flow2/ProcessPayment.php b/app/Livewire/Flow2/ProcessPayment.php index dd9b8641afe1..54e1490e3637 100644 --- a/app/Livewire/Flow2/ProcessPayment.php +++ b/app/Livewire/Flow2/ProcessPayment.php @@ -30,18 +30,6 @@ class ProcessPayment extends Component public $isLoading = true; - private string $component_view = ''; - - private array $payment_data_payload = []; - - public $isLoading = true; - - - // public function toJSON() - // { - // nlog("why"); - // } - public function mount() { @@ -71,12 +59,12 @@ class ProcessPayment extends Component } $driver = $company_gateway - ->driver($invitation->contact->client) // @phpstan-ignore-line + ->driver($invitation->contact->client) ->setPaymentMethod($data['payment_method_id']) ->setPaymentHash($responder_data['payload']['ph']); $this->payment_data_payload = $driver->processPaymentViewData($responder_data['payload']); - + $this->payment_view = $driver->livewirePaymentView( $this->payment_data_payload, ); @@ -95,4 +83,4 @@ class ProcessPayment extends Component return render($this->payment_view, $this->payment_data_payload); } -} +} \ No newline at end of file diff --git a/app/Livewire/Flow2/RequiredFields.php b/app/Livewire/Flow2/RequiredFields.php index e3a31830755c..5c4f93889ef1 100644 --- a/app/Livewire/Flow2/RequiredFields.php +++ b/app/Livewire/Flow2/RequiredFields.php @@ -88,7 +88,7 @@ class RequiredFields extends Component $rff = new RFFService( fields: $this->getContext()['fields'], database: $this->getContext()['db'], - company_gateway_id: (string)$this->company_gateway->id, + company_gateway_id: $this->company_gateway->id, ); /** @var \App\Models\ClientContact $contact */ @@ -111,7 +111,7 @@ class RequiredFields extends Component $rff = new RFFService( fields: $this->fields, database: $this->getContext()['db'], - company_gateway_id: (string) $this->company_gateway->id, + company_gateway_id: $this->company_gateway->id, ); $contact = auth()->user(); @@ -133,4 +133,4 @@ class RequiredFields extends Component 'contact' => $this->getContext()['contact'], ]); } -} +} \ No newline at end of file diff --git a/app/Livewire/Flow2/UnderOverPayment.php b/app/Livewire/Flow2/UnderOverPayment.php index 93865ee6a0bd..b703e36cbdc8 100644 --- a/app/Livewire/Flow2/UnderOverPayment.php +++ b/app/Livewire/Flow2/UnderOverPayment.php @@ -18,6 +18,7 @@ use Livewire\Component; class UnderOverPayment extends Component { + use WithSecureContext; public $payableAmount; @@ -44,28 +45,29 @@ class UnderOverPayment extends Component $settings = $this->getContext()['settings']; - foreach($payableInvoices as $key => $invoice) { + foreach($payableInvoices as $key => $invoice){ $payableInvoices[$key]['amount'] = Number::parseFloat($invoice['formatted_amount']); } $input_amount = collect($payableInvoices)->sum('amount'); - if($settings->client_portal_allow_under_payment && $settings->client_portal_under_payment_minimum != 0) { - if($input_amount <= $settings->client_portal_under_payment_minimum) { + if($settings->client_portal_allow_under_payment && $settings->client_portal_under_payment_minimum != 0) + { + if($input_amount <= $settings->client_portal_under_payment_minimum){ // return error message under payment too low. $this->errors = ctrans('texts.minimum_required_payment', ['amount' => $settings->client_portal_under_payment_minimum]); $this->dispatch('errorMessageUpdate', errors: $this->errors); } } - if(!$settings->client_portal_allow_over_payment && ($input_amount > $this->invoice_amount)) { + if(!$settings->client_portal_allow_over_payment && ($input_amount > $this->invoice_amount)){ $this->errors = ctrans('texts.over_payments_disabled'); $this->dispatch('errorMessageUpdate', errors: $this->errors); } - if(!$this->errors) { + if(!$this->errors){ $this->setContext('payable_invoices', $payableInvoices); - $this->dispatch('payable-amount', payable_amount: $input_amount); + $this->dispatch('payable-amount', payable_amount: $input_amount ); } } @@ -73,4 +75,4 @@ class UnderOverPayment extends Component { return render('flow2.under-over-payments'); } -} +} \ No newline at end of file diff --git a/app/Livewire/InvoicePay.php b/app/Livewire/InvoicePay.php index 0ae0d0db36b8..336859bfaacc 100644 --- a/app/Livewire/InvoicePay.php +++ b/app/Livewire/InvoicePay.php @@ -22,6 +22,8 @@ use Livewire\Attributes\Computed; use Livewire\Attributes\Reactive; use App\Livewire\Flow2\PaymentMethod; use App\Livewire\Flow2\ProcessPayment; +use App\Livewire\Flow2\UnderOverPayment; +use App\Utils\Number; class InvoicePay extends Component { @@ -37,6 +39,12 @@ class InvoicePay extends Component public $payment_method_accepted = false; + public $under_over_payment = false; + + public $required_fields = false; + + public $ready = true; + public array $context = []; #[On('update.context')] @@ -70,9 +78,17 @@ class InvoicePay extends Component } + #[On('payable-amount')] + public function payableAmount($payable_amount) + { + $this->context['payable_invoices'][0]['amount'] = Number::parseFloat($payable_amount); + $this->under_over_payment = false; + } + #[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; @@ -83,6 +99,8 @@ class InvoicePay extends Component // $this->invite = \App\Models\InvoiceInvitation::withTrashed()->find($this->invitation_id)->withoutRelations(); $this->payment_method_accepted =true; + + } #[Computed()] @@ -94,10 +112,14 @@ class InvoicePay extends Component if(!$this->signature_accepted) return Signature::class; + if($this->under_over_payment) + return UnderOverPayment::class; + if(!$this->payment_method_accepted) return PaymentMethod::class; - return ProcessPayment::class; + // if($this->ready) + return ProcessPayment::class; } #[Computed()] @@ -116,13 +138,23 @@ class InvoicePay extends Component $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['settings'] = $settings; + + //under-over / payment + + //required fields $this->terms_accepted = !$settings->show_accept_invoice_terms; $this->signature_accepted = !$settings->require_invoice_signature; - + $this->under_over_payment = $settings->client_portal_allow_over_payment || $settings->client_portal_allow_under_payment; + $this->required_fields = false; + $this->context['variables'] = $variables; $this->context['invoice'] = $invite->invoice; $this->context['settings'] = $settings; + + $this->context['payable_invoices'] = ['invoice_id' => $this->context['invoice']->hashed_id, 'amount' => $invite->invoice->partial > 0 ? $invite->invoice->partial : $invite->invoice->balance]; + } public function render() diff --git a/resources/views/portal/ninja2020/components/livewire/payment_method-flow2.blade.php b/resources/views/portal/ninja2020/components/livewire/payment_method-flow2.blade.php index 09afec9c68a0..249c7d120e01 100644 --- a/resources/views/portal/ninja2020/components/livewire/payment_method-flow2.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/payment_method-flow2.blade.php @@ -29,6 +29,10 @@ isLoading = false; }); + Livewire.on('singlePaymentMethodFound', (event) => { + $wire.dispatch('payment-method-selected', {company_gateway_id: event.company_gateway_id, gateway_type_id: event.gateway_type_id, amount: event.amount }) + }); + const buttons = document.querySelectorAll('.payment-method'); buttons.forEach(button => { diff --git a/resources/views/portal/ninja2020/components/livewire/required-fields.blade.php b/resources/views/portal/ninja2020/components/livewire/required-fields.blade.php new file mode 100644 index 000000000000..42eb8c531dbf --- /dev/null +++ b/resources/views/portal/ninja2020/components/livewire/required-fields.blade.php @@ -0,0 +1,3 @@ +
+ +
\ No newline at end of file diff --git a/resources/views/portal/ninja2020/components/livewire/under-over-payments.blade.php b/resources/views/portal/ninja2020/components/livewire/under-over-payments.blade.php new file mode 100644 index 000000000000..6001075a453e --- /dev/null +++ b/resources/views/portal/ninja2020/components/livewire/under-over-payments.blade.php @@ -0,0 +1,37 @@ +
+ +
+ {{ ctrans('texts.payment_amount') }} +
+
+ +
+ +
+ + @if($settings->client_portal_allow_under_payment) + {{ ctrans('texts.minimum_payment') }}: {{ $settings->client_portal_under_payment_minimum }} + @endif +
+ +
+ +
+ +
\ No newline at end of file