diff --git a/app/Livewire/Flow2/RequiredFields.php b/app/Livewire/Flow2/RequiredFields.php index 5c4f93889ef1..5cce417df6f6 100644 --- a/app/Livewire/Flow2/RequiredFields.php +++ b/app/Livewire/Flow2/RequiredFields.php @@ -133,4 +133,4 @@ class RequiredFields extends Component 'contact' => $this->getContext()['contact'], ]); } -} \ No newline at end of file +} diff --git a/app/Livewire/InvoicePay.php b/app/Livewire/InvoicePay.php index 7296786f05bb..68a004f3912b 100644 --- a/app/Livewire/InvoicePay.php +++ b/app/Livewire/InvoicePay.php @@ -12,27 +12,74 @@ namespace App\Livewire; +use App\Utils\Number; +use App\Models\Invoice; use Livewire\Component; use App\Utils\HtmlEngine; use App\Libraries\MultiDB; use Livewire\Attributes\On; use App\Livewire\Flow2\Terms; +use App\Models\CompanyGateway; +use App\Utils\Traits\MakesHash; +use App\Utils\Traits\MakesDates; use App\Livewire\Flow2\Signature; use Livewire\Attributes\Computed; use Livewire\Attributes\Reactive; use App\Livewire\Flow2\PaymentMethod; use App\Livewire\Flow2\ProcessPayment; +use App\Livewire\Flow2\RequiredFields; use App\Livewire\Flow2\UnderOverPayment; -use App\Models\Invoice; -use App\Utils\Number; -use App\Utils\Traits\MakesDates; -use App\Utils\Traits\MakesHash; class InvoicePay extends Component { use MakesDates; use MakesHash; + private $mappings = [ + 'client_name' => 'name', + 'client_website' => 'website', + 'client_phone' => 'phone', + + 'client_address_line_1' => 'address1', + 'client_address_line_2' => 'address2', + 'client_city' => 'city', + 'client_state' => 'state', + 'client_postal_code' => 'postal_code', + 'client_country_id' => 'country_id', + + 'client_shipping_address_line_1' => 'shipping_address1', + 'client_shipping_address_line_2' => 'shipping_address2', + 'client_shipping_city' => 'shipping_city', + 'client_shipping_state' => 'shipping_state', + 'client_shipping_postal_code' => 'shipping_postal_code', + 'client_shipping_country_id' => 'shipping_country_id', + + 'client_custom_value1' => 'custom_value1', + 'client_custom_value2' => 'custom_value2', + 'client_custom_value3' => 'custom_value3', + 'client_custom_value4' => 'custom_value4', + + 'contact_first_name' => 'first_name', + 'contact_last_name' => 'last_name', + 'contact_email' => 'email', + // 'contact_phone' => 'phone', + ]; + + public $client_address_array = [ + 'address1', + 'address2', + 'city', + 'state', + 'postal_code', + 'country_id', + 'shipping_address1', + 'shipping_address2', + 'shipping_city', + 'shipping_state', + 'shipping_postal_code', + 'shipping_country_id', + ]; + public $invitation_id; public $invoices; @@ -97,19 +144,58 @@ class InvoicePay extends Component public function paymentMethodSelected($company_gateway_id, $gateway_type_id, $amount) { //@TODO only handles single invoice scenario - - $this->payment_method_accepted = true; - $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' => $amount]; - $this->context['invitation_id'] = $this->invitation_id; + + $this->payment_method_accepted = true; + $company_gateway = CompanyGateway::find($company_gateway_id); + + $this->checkRequiredFields($company_gateway); + + } + + #[On('required-fields')] + public function requiredFieldsFilled() + { + $this->required_fields = false; + } + + private function checkRequiredFields(CompanyGateway $company_gateway) + { + + $fields = $company_gateway->driver()->getClientRequiredFields(); + $this->context['fields'] = $fields; + + if($company_gateway->always_show_required_fields){ + return $this->required_fields = true; + } + + $contact = $this->context['contact']; + + foreach ($fields as $index => $field) { + $_field = $this->mappings[$field['name']]; + + if (\Illuminate\Support\Str::startsWith($field['name'], 'client_')) { + if (empty($contact->client->{$_field}) + || is_null($contact->client->{$_field}) + ) { + + return $this->required_fields = true; + + } + } + + if (\Illuminate\Support\Str::startsWith($field['name'], 'contact_')) { + if (empty($contact->{$_field}) || is_null($contact->{$_field}) || str_contains($contact->{$_field}, '@example.com')) { + return $this->required_fields = true; + } + } + } } @@ -128,10 +214,10 @@ class InvoicePay extends Component if(!$this->payment_method_accepted) return PaymentMethod::class; - // if($this->ready) - - - return ProcessPayment::class; + if($this->required_fields) + return RequiredFields::class; + + return ProcessPayment::class; } #[Computed()] @@ -149,6 +235,7 @@ class InvoicePay extends Component $invite = \App\Models\InvoiceInvitation::with('contact.client','company')->withTrashed()->find($this->invitation_id); $client = $invite->contact->client; $settings = $client->getMergedSettings(); + $this->context['contact'] = $invite->contact; $this->context['settings'] = $settings; $this->context['db'] = $this->db; diff --git a/resources/views/portal/ninja2020/components/livewire/required-fields.blade.php b/resources/views/portal/ninja2020/components/livewire/required-fields.blade.php index 42eb8c531dbf..0bc361df65c5 100644 --- a/resources/views/portal/ninja2020/components/livewire/required-fields.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/required-fields.blade.php @@ -1,3 +1,37 @@ -
- +
+ @foreach($fields as $field) + + @component('portal.ninja2020.components.general.card-element', ['title' => $field['label']]) + @if($field['name'] == 'client_country_id' || $field['name'] == 'client_shipping_country_id') + + @else + + @endif + + @if(session()->has('validation_errors') && array_key_exists($field['name'], session('validation_errors'))) +

{{ session('validation_errors')[$field['name']][0] }}

+ @endif + @endcomponent + + @endforeach + +
+ +
\ No newline at end of file