This commit is contained in:
Benjamin Beganović 2021-01-12 16:30:11 +01:00
parent cdd62f7e2a
commit 0b4e85957c

View File

@ -13,6 +13,7 @@
namespace App\Http\Livewire;
use App\Models\ClientContact;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Livewire\Component;
@ -21,13 +22,47 @@ class RequiredClientInfo extends Component
{
public $fields = [];
/**
* @var ClientContact
*/
public $contact;
/**
* Instance of payment gateway. Used for getting the required fields.
*
* @var mixed
*/
private $gateway;
/**
* Mappings for updating the database. Left side is mapping from gateway,
* right side is column in database.
*
* @var string[]
*/
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',
'contact_first_name' => 'first_name',
'contact_last_name' => 'last_name',
'contact_email' => 'email',
'contact_phone' => 'phone',
];
@ -65,7 +100,7 @@ class RequiredClientInfo extends Component
$contact = [];
foreach ($data as $field => $value) {
if (Str::startsWith($field, 'client_', )) {
if (Str::startsWith($field, 'client_')) {
$client[$this->mappings[$field]] = $value;
}