diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index e0bb998939e3..5bcc6d6ce959 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -35,35 +35,6 @@ class CompanySettings extends BaseSettings public $custom_value3 = ''; public $custom_value4 = ''; - // public $custom_label1 = ''; - // public $custom_label2 = ''; - // public $custom_label3 = ''; - // public $custom_label4 = ''; - // public $custom_client_label1 = ''; - // public $custom_client_label2 = ''; - // public $custom_client_label3 = ''; - // public $custom_client_label4 = ''; - // public $custom_client_contact_label1 = ''; - // public $custom_client_contact_label2 = ''; - // public $custom_client_contact_label3 = ''; - // public $custom_client_contact_label4 = ''; - // public $custom_invoice_label1 = ''; - // public $custom_invoice_label2 = ''; - // public $custom_invoice_label3 = ''; - // public $custom_invoice_label4 = ''; - // public $custom_product_label1 = ''; - // public $custom_product_label2 = ''; - // public $custom_product_label3 = ''; - // public $custom_product_label4 = ''; - // public $custom_task_label1 = ''; - // public $custom_task_label2 = ''; - // public $custom_task_label3 = ''; - // public $custom_task_label4 = ''; - // public $custom_expense_label1 = ''; - // public $custom_expense_label2 = ''; - // public $custom_expense_label3 = ''; - // public $custom_expense_label4 = ''; - public $custom_invoice_taxes1 = false; public $custom_invoice_taxes2 = false; public $custom_invoice_taxes3 = false; @@ -113,21 +84,19 @@ class CompanySettings extends BaseSettings public $design = 'views/pdf/design1.blade.php'; - public $design_id = '1';//todo new - public $auto_update_products = true; - - public $company_gateways = ''; + public $update_products = true; + public $fill_products = false; + public $convert_products = false; public $invoice_terms = ''; public $quote_terms = ''; public $invoice_taxes = false; public $invoice_item_taxes = false; - public $invoice_design_id = ''; - public $quote_design_id = ''; + public $invoice_design_id = '1'; + public $quote_design_id = '1'; public $invoice_footer = ''; public $invoice_labels = ''; public $show_item_taxes = false; - public $fill_products = false; public $tax_name1 = ''; public $tax_rate1 = 0; public $tax_name2 = ''; @@ -135,8 +104,7 @@ class CompanySettings extends BaseSettings public $tax_name3 = ''; public $tax_rate3 = 0; public $enable_second_tax_rate = false; - public $payment_type_id = ''; - public $convert_products = false; + public $payment_type_id = '1'; public $custom_fields = ''; public $invoice_fields = ''; public $email_footer = ''; @@ -175,20 +143,79 @@ class CompanySettings extends BaseSettings public $id_number = ''; public static $casts = [ - 'auto_update_products' => 'bool', - 'design_id' => 'string', - 'name' => 'string', - 'company_logo' => 'string', - 'website' => 'string', 'address1' => 'string', 'address2' => 'string', 'city' => 'string', - 'state' => 'string', - 'postal_code' => 'string', - 'phone' => 'string', - 'email' => 'string', + 'company_logo' => 'string', + 'convert_products' => 'bool', 'country_id' => 'string', + 'client_number_prefix' => 'string', + 'client_number_pattern' => 'string', + 'client_number_counter' => 'integer', + 'credit_number_prefix' => 'string', + 'credit_number_pattern' => 'string', + 'credit_number_counter' => 'integer', 'currency_id' => 'string', + 'custom_value1' => 'string', + 'custom_value2' => 'string', + 'custom_value3' => 'string', + 'custom_value4' => 'string', + 'custom_invoice_taxes1' => 'bool', + 'custom_invoice_taxes2' => 'bool', + 'custom_invoice_taxes3' => 'bool', + 'custom_invoice_taxes4' => 'bool', + 'custom_message_dashboard' => 'string', + 'custom_message_unpaid_invoice' => 'string', + 'custom_message_paid_invoice' => 'string', + 'custom_message_unapproved_quote' => 'string', + 'custom_fields' => 'string', + 'default_task_rate' => 'float', + 'email_footer' => 'string', + 'email_subject_invoice' => 'string', + 'email_subject_quote' => 'string', + 'email_subject_payment' => 'string', + 'email_template_invoice' => 'string', + 'email_template_quote' => 'string', + 'email_template_payment' => 'string', + 'email_subject_reminder1' => 'string', + 'email_subject_reminder2' => 'string', + 'email_subject_reminder3' => 'string', + 'email_template_reminder1' => 'string', + 'email_template_reminder2' => 'string', + 'email_template_reminder3' => 'string', + 'enable_portal_password' => 'bool', + 'enable_second_tax_rate' => 'bool', + 'fill_products' => 'bool', + 'inclusive_taxes' => 'bool', + 'invoice_number_prefix' => 'string', + 'invoice_number_pattern' => 'string', + 'invoice_number_counter' => 'integer', + 'invoice_design_id' => 'string', + 'invoice_fields' => 'string', + 'invoice_taxes' => 'bool', + 'invoice_item_taxes' => 'bool', + 'invoice_footer' => 'string', + 'invoice_labels' => 'string', + 'invoice_terms' => 'string', + 'name' => 'string', + 'payment_terms' => 'integer', + 'payment_type_id' => 'string', + 'phone' => 'string', + 'postal_code' => 'string', + 'quote_design_id' => 'string', + 'quote_number_prefix' => 'string', + 'quote_number_pattern' => 'string', + 'quote_number_counter' => 'integer', + 'quote_terms' => 'string', + 'recurring_invoice_number_prefix' => 'string', + 'reset_counter_frequency_id' => 'integer', + 'reset_counter_date' => 'string', + 'require_invoice_signature' => 'bool', + 'require_quote_signature' => 'bool', + 'show_item_taxes' => 'bool', + 'update_products' => 'bool', + 'state' => 'string', + 'email' => 'string', 'vat_number' => 'string', 'id_number' => 'string', 'tax_name1' => 'string', @@ -197,8 +224,6 @@ class CompanySettings extends BaseSettings 'tax_rate1' => 'float', 'tax_rate2' => 'float', 'tax_rate3' => 'float', - 'require_invoice_signature' => 'bool', - 'require_quote_signature' => 'bool', 'show_accept_quote_terms' => 'bool', 'show_accept_invoice_terms' => 'bool', 'timezone_id' => 'string', @@ -206,72 +231,14 @@ class CompanySettings extends BaseSettings 'military_time' => 'bool', 'language_id' => 'string', 'show_currency_code' => 'bool', - 'payment_terms' => 'integer', - 'custom_value1' => 'string', - 'custom_value2' => 'string', - 'custom_value3' => 'string', - 'custom_value4' => 'string', - // 'custom_label1' => 'string', - // 'custom_label2' => 'string', - // 'custom_label3' => 'string', - // 'custom_label4' => 'string', - // 'custom_client_label1' => 'string', - // 'custom_client_label2' => 'string', - // 'custom_client_label3' => 'string', - // 'custom_client_label4' => 'string', - // 'custom_client_contact_label1' => 'string', - // 'custom_client_contact_label2' => 'string', - // 'custom_client_contact_label3' => 'string', - // 'custom_client_contact_label4' => 'string', - // 'custom_invoice_label1' => 'string', - // 'custom_invoice_label2' => 'string', - // 'custom_invoice_label3' => 'string', - // 'custom_invoice_label4' => 'string', - // 'custom_product_label1' => 'string', - // 'custom_product_label2' => 'string', - // 'custom_product_label3' => 'string', - // 'custom_product_label4' => 'string', - // 'custom_task_label1' => 'string', - // 'custom_task_label2' => 'string', - // 'custom_task_label3' => 'string', - // 'custom_task_label4' => 'string', - // 'custom_expense_label1' => 'string', - // 'custom_expense_label2' => 'string', - // 'custom_expense_label3' => 'string', - // 'custom_expense_label4' => 'string', - 'custom_invoice_taxes1' => 'bool', - 'custom_invoice_taxes2' => 'bool', - 'custom_invoice_taxes3' => 'bool', - 'custom_invoice_taxes4' => 'bool', - 'default_task_rate' => 'float', 'send_reminders' => 'bool', 'show_tasks_in_portal' => 'bool', - 'custom_message_dashboard' => 'string', - 'custom_message_unpaid_invoice' => 'string', - 'custom_message_paid_invoice' => 'string', - 'custom_message_unapproved_quote' => 'string', 'lock_sent_invoices' => 'bool', 'auto_archive_invoice' => 'bool', - 'inclusive_taxes' => 'bool', - 'invoice_number_prefix' => 'string', - 'invoice_number_pattern' => 'string', - 'invoice_number_counter' => 'integer', - 'quote_number_prefix' => 'string', - 'quote_number_pattern' => 'string', - 'quote_number_counter' => 'integer', - 'client_number_prefix' => 'string', - 'client_number_pattern' => 'string', - 'client_number_counter' => 'integer', - 'credit_number_prefix' => 'string', - 'credit_number_pattern' => 'string', - 'credit_number_counter' => 'integer', 'shared_invoice_quote_counter' => 'bool', - 'recurring_invoice_number_prefix' => 'string', - 'reset_counter_frequency_id' => 'integer', - 'reset_counter_date' => 'string', 'counter_padding' => 'integer', 'design' => 'string', - 'company_gateways' => 'string', + 'website' => 'string', ]; /** diff --git a/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php b/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php index 9de28dc1ffbf..e8eb41d73699 100644 --- a/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php +++ b/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php @@ -4,35 +4,31 @@ * schema="CompanySettings", * type="object", * @OA\Property(property="timezone_id", type="string", example="15", description="The timezone id"), - * @OA\Property(property="design_id", type="string", example="15", description="The design id (invoice, quote etc)"), - * @OA\Property(property="auto_update_products", type="boolean", example=true, description="Determines if client fields are updated from third party APIs"), * @OA\Property(property="date_format_id", type="string", example="15", description="____________"), - * @OA\Property(property="financial_year_start", type="string", example="2000-01-01", description="____________"), + * @OA\Property(property="military_time", type="boolean", example=true, description="____________"), * @OA\Property(property="language_id", type="string", example="1", description="____________"), - * @OA\Property(property="company_logo", type="string", example="https://example.com/logo.png", description="The URL to the company Logo"), - * @OA\Property(property="custom_label1", type="string", example="Custom Label", description="____________"), - * @OA\Property(property="custom_label2", type="string", example="Custom Label", description="____________"), - * @OA\Property(property="custom_label3", type="string", example="Custom Label", description="____________"), - * @OA\Property(property="custom_label4", type="string", example="Custom Label", description="____________"), + * @OA\Property(property="show_currency_code", type="boolean", example=true, description="____________"), + * @OA\Property(property="currency_id", type="string", example=true, description="The settings currency id"), + * @OA\Property(property="payment_terms", type="integer", example="1", description="-1 sets no payment term, 0 sets payment due immediately, positive integers indicates payment terms in days"), * @OA\Property(property="custom_value1", type="string", example="Custom Label", description="____________"), * @OA\Property(property="custom_value2", type="string", example="Custom Label", description="____________"), * @OA\Property(property="custom_value3", type="string", example="Custom Label", description="____________"), * @OA\Property(property="custom_value4", type="string", example="Custom Label", description="____________"), + * @OA\Property(property="custom_invoice_taxes1", type="boolean", example=true, description="____________"), + * @OA\Property(property="custom_invoice_taxes2", type="boolean", example=true, description="____________"), + * @OA\Property(property="custom_invoice_taxes3", type="boolean", example=true, description="____________"), + * @OA\Property(property="custom_invoice_taxes4", type="boolean", example=true, description="____________"), + * @OA\Property(property="default_task_rate", type="number", format="float", example="10.00", description="____________"), + * @OA\Property(property="send_reminders", type="boolean", example=true, description="____________"), + * @OA\Property(property="show_tasks_in_portal", type="boolean", example=true, description="____________"), * @OA\Property(property="custom_message_dashboard", type="string", example="Please pay invoices immediately", description="____________"), * @OA\Property(property="custom_message_unpaid_invoice", type="string", example="Please pay invoices immediately", description="____________"), * @OA\Property(property="custom_message_paid_invoice", type="string", example="Thanks for paying this invoice!", description="____________"), * @OA\Property(property="custom_message_unapproved_quote", type="string", example="Please approve quote", description="____________"), - * @OA\Property(property="military_time", type="boolean", example=true, description="____________"), - * @OA\Property(property="custom_taxes1", type="boolean", example=true, description="____________"), - * @OA\Property(property="custom_taxes2", type="boolean", example=true, description="____________"), - * @OA\Property(property="send_reminders", type="boolean", example=true, description="____________"), * @OA\Property(property="lock_sent_invoices", type="boolean", example=true, description="____________"), * @OA\Property(property="auto_archive_invoice", type="boolean", example=true, description="____________"), * @OA\Property(property="inclusive_taxes", type="boolean", example=true, description="____________"), - * @OA\Property(property="show_tasks_in_portal", type="boolean", example=true, description="____________"), - * @OA\Property(property="show_currency_code", type="boolean", example=true, description="____________"), - * @OA\Property(property="shared_invoice_quote_counter", type="boolean", example=true, description="Flags whether to share the counter for invoices and quotes"), - * @OA\Property(property="first_day_of_week", type="integer", example="1", description="____________"), + * @OA\Property(property="translations", type="object", example="", description="JSON payload of customized translations"), * @OA\Property(property="invoice_number_prefix", type="string", example="R", description="This string is prepended to the invoice number"), * @OA\Property(property="invoice_number_pattern", type="string", example="{$year}-{$counter}", description="Allows customisation of the invoice number pattern"), * @OA\Property(property="invoice_number_counter", type="integer", example="1", description="____________"), @@ -46,13 +42,62 @@ * @OA\Property(property="credit_number_pattern", type="string", example="{$year}-{$counter}", description="Allows customisation of the credit number pattern"), * @OA\Property(property="credit_number_counter", type="integer", example="1", description="____________"), * @OA\Property(property="recurring_invoice_number_prefix", type="string", example="R", description="This string is prepended to the recurring invoice number"), - * @OA\Property(property="default_task_rate", type="number", format="float", example="10.00", description="____________"), - * @OA\Property(property="translations", type="object", example="", description="JSON payload of customized translations"), - * @OA\Property(property="payment_terms", type="integer", example="1", description="-1 sets no payment term, 0 sets payment due immediately, positive integers indicates payment terms in days"), * @OA\Property(property="reset_counter_frequency_id", type="integer", example="1", description="CONSTANT which is used to apply the frequency which the counters are reset"), - * @OA\Property(property="counter_padding", type="integer", example="1", description="Pads the counter with leading zeros"), - * @OA\Property(property="default_gateway", type="integer", example="1", description="The default payment gateway"), * @OA\Property(property="reset_counter_date", type="string", example="2019-01-01", description="The explicit date which is used to reset counters"), + * @OA\Property(property="counter_padding", type="integer", example="1", description="Pads the counter with leading zeros"), + * @OA\Property(property="shared_invoice_quote_counter", type="boolean", example=true, description="Flags whether to share the counter for invoices and quotes"), + * @OA\Property(property="update_products", type="boolean", example=true, description="Determines if client fields are updated from third party APIs"), + * @OA\Property(property="convert_products", type="boolean", example=true, description=""), + * @OA\Property(property="fill_products", type="boolean", example=true, description="Automatically fill products based on product_key"), + * @OA\Property(property="invoice_terms", type="string", example="Invoice Terms are...", description="The default invoice terms"), + * @OA\Property(property="quote_terms", type="string", example="Quote Terms are...", description="The default quote terms"), + * @OA\Property(property="invoice_taxes", type="boolean", example=true, description="Taxes can be applied to the invoice"), + * @OA\Property(property="invoice_item_taxes", type="boolean", example=true, description="Taxes can be applied to the invoice items"), + * @OA\Property(property="invoice_design_id", type="string", example="1", description="The default design id (invoice, quote etc)"), + * @OA\Property(property="quote_design_id", type="string", example="1", description="The default design id (invoice, quote etc)"), + * @OA\Property(property="invoice_footer", type="string", example="1", description="The default invoice footer"), + * @OA\Property(property="invoice_labels", type="string", example="1", description="JSON string of invoice labels"), + * @OA\Property(property="show_item_taxes", type="boolean", example=true, description="Toggles whether the itemised taxes are displayed"), + * @OA\Property(property="tax_rate1", type="float", example="10", description="The tax rate (float)"), + * @OA\Property(property="tax_name1", type="string", example="GST", description="The tax name"), + * @OA\Property(property="tax_rate2", type="float", example="10", description="The tax rate (float)"), + * @OA\Property(property="tax_name2", type="string", example="GST", description="The tax name"), + * @OA\Property(property="tax_rate3", type="float", example="10", description="The tax rate (float)"), + * @OA\Property(property="tax_name3", type="string", example="GST", description="The tax name"), + * @OA\Property(property="enable_second_tax_rate", type="boolean", example=true, description="Toggles whether the a second tax rate can be applied"), + * @OA\Property(property="payment_type_id", type="string", example="1", description="The default payment type id"), + * @OA\Property(property="custom_fields", type="string", example="{}", description="JSON string of custom fields"), + * @OA\Property(property="invoice_fields", type="string", example="{}", description="JSON string of invoice fields"), + * @OA\Property(property="email_footer", type="string", example="A default email footer", description="The default email footer"), + * @OA\Property(property="email_subject_invoice", type="string", example="Your Invoice Subject", description=""), + * @OA\Property(property="email_subject_quote", type="string", example="Your Quote Subject", description=""), + * @OA\Property(property="email_subject_payment", type="string", example="Your Payment Subject", description=""), + * @OA\Property(property="email_template_invoice", type="string", example="", description="The full template for invoice emails"), + * @OA\Property(property="email_template_quote", type="string", example="", description="The full template for quote emails"), + * @OA\Property(property="email_template_payment", type="string", example="", description="The full template for payment emails"), + * @OA\Property(property="email_subject_reminder1", type="string", example="", description="Email subject for Reminder"), + * @OA\Property(property="email_subject_reminder2", type="string", example="", description="Email subject for Reminder"), + * @OA\Property(property="email_subject_reminder3", type="string", example="", description="Email subject for Reminder"), + * @OA\Property(property="email_template_reminder1", type="string", example="", description="The full template for Reminder 1"), + * @OA\Property(property="email_template_reminder2", type="string", example="", description="The full template for Reminder 2"), + * @OA\Property(property="email_template_reminder3", type="string", example="", description="The full template for Reminder 3"), + * @OA\Property(property="enable_portal_password", type="boolean", example=true, description="Toggles whether a password is required to log into the client portal"), + * @OA\Property(property="show_accept_invoice_terms", type="boolean", example=true, description="Toggles whether the terms dialogue is shown to the client"), + * @OA\Property(property="show_accept_quote_terms", type="boolean", example=true, description="Toggles whether the terms dialogue is shown to the client"), + * @OA\Property(property="require_invoice_signature", type="boolean", example=true, description="Toggles whether a invoice signature is required"), + * @OA\Property(property="require_quote_signature", type="boolean", example=true, description="Toggles whether a quote signature is required"), + * @OA\Property(property="name", type="string", example="Acme Co", description="The company name"), + * @OA\Property(property="company_logo", type="file", example="logo.png", description="The company logo file"), + * @OA\Property(property="website", type="string", example="www.acme.com", description="The company website URL"), + * @OA\Property(property="address1", type="string", example="Suite 888", description="____________"), + * @OA\Property(property="address2", type="string", example="5 Jimbo Way", description="____________"), + * @OA\Property(property="city", type="string", example="Sydney", description="____________"), + * @OA\Property(property="state", type="string", example="Florisa", description="____________"), + * @OA\Property(property="postal_code", type="string", example="90210", description="____________"), + * @OA\Property(property="phone", type="string", example="555-213-3948", description="____________"), + * @OA\Property(property="email", type="string", example="joe@acme.co", description="____________"), + * @OA\Property(property="country_id", type="string", example="1", description="The country ID"), + * @OA\Property(property="vat_number", type="string", example="32 120 377 720", description="____________"), + * @OA\Property(property="id_number", type="string", example="ACME-CO-123", description="____________"), * ) - */ - * \ No newline at end of file + */ \ No newline at end of file diff --git a/app/Http/Middleware/PasswordProtection.php b/app/Http/Middleware/PasswordProtection.php index d2bbc9ca6ced..f49e4a0ce752 100644 --- a/app/Http/Middleware/PasswordProtection.php +++ b/app/Http/Middleware/PasswordProtection.php @@ -14,6 +14,8 @@ namespace App\Http\Middleware; use App\Libraries\MultiDB; use App\Models\CompanyToken; use Closure; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Hash; class PasswordProtection { diff --git a/app/Utils/Traits/SettingsSaver.php b/app/Utils/Traits/SettingsSaver.php index 87b7adb408be..4275127388e9 100644 --- a/app/Utils/Traits/SettingsSaver.php +++ b/app/Utils/Traits/SettingsSaver.php @@ -64,13 +64,18 @@ trait SettingsSaver $settings = (object)$settings; $casts = CompanySettings::$casts; + ksort($casts); + foreach ($casts as $key => $value){ - + /*Separate loop if it is a _id field which is an integer cast as a string*/ if(substr($key, -3) == '_id' || substr($key, -14) == 'number_counter'){ $value = "integer"; - if(!$this->checkAttribute($value, $settings->{$key})){ + if(!property_exists($settings, $key)){ + continue; + } + else if(!$this->checkAttribute($value, $settings->{$key})){ return [$key, $value]; } @@ -78,14 +83,14 @@ trait SettingsSaver } /* Handles unset settings or blank strings */ - if(is_null($settings->{$key}) || !isset($settings->{$key}) || $settings->{$key} == ''){ + if(!property_exists($settings, $key) || is_null($settings->{$key}) || !isset($settings->{$key}) || $settings->{$key} == '') continue; - } + /*Catch all filter */ - if(!$this->checkAttribute($value, $settings->{$key})){ - return [$key, $value]; - } + if(!$this->checkAttribute($value, $settings->{$key})) + return [$key, $value]; + } @@ -114,7 +119,10 @@ trait SettingsSaver if(substr($key, -3) == '_id' || substr($key, -14) == 'number_counter'){ $value = "integer"; - if($this->checkAttribute($value, $settings->{$key})){ + if(!property_exists($settings, $key)){ + continue; + } + elseif($this->checkAttribute($value, $settings->{$key})){ settype($settings->{$key}, $value); } else { @@ -125,7 +133,7 @@ trait SettingsSaver } /* Handles unset settings or blank strings */ - if(is_null($settings->{$key}) || !isset($settings->{$key}) || $settings->{$key} == ''){ + if(!property_exists($settings, $key) || is_null($settings->{$key}) || !isset($settings->{$key}) || $settings->{$key} == ''){ continue; } diff --git a/routes/api.php b/routes/api.php index e31e10271a0c..bd8132c4f4be 100644 --- a/routes/api.php +++ b/routes/api.php @@ -68,7 +68,8 @@ Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefi Route::post('payments/bulk', 'PaymentController@bulk')->name('payments.bulk'); - Route::resource('users', 'UserController')->middleware('password_protected'); // name = (users. index / create / show / update / destroy / edit +// Route::resource('users', 'UserController')->middleware('password_protected'); // name = (users. index / create / show / update / destroy / edit + Route::resource('users', 'UserController'); // name = (users. index / create / show / update / destroy / edit Route::post('users/bulk', 'UserController@bulk')->name('users.bulk')->middleware('password_protected'); diff --git a/tests/Feature/ClientModelTest.php b/tests/Feature/ClientModelTest.php index 3c063d8fb2f5..766a1bb23839 100644 --- a/tests/Feature/ClientModelTest.php +++ b/tests/Feature/ClientModelTest.php @@ -29,77 +29,77 @@ class ClientModelTest extends TestCase } - public function testPaymentMethods() - { + // public function testPaymentMethods() + // { - $amount = 40; + // $amount = 40; - $company_gateways = $this->client->getSetting('company_gateways'); + // $company_gateways = $this->client->getSetting('company_gateways'); - //todo create a test where we actually SET a value in the settings->company_gateways object and test if we can harvest. + // //todo create a test where we actually SET a value in the settings->company_gateways object and test if we can harvest. - if($company_gateways) - $gateways = $this->company->company_gateways->whereIn('id', $payment_gateways); - else - $gateways = $this->company->company_gateways; + // if($company_gateways) + // $gateways = $this->company->company_gateways->whereIn('id', $payment_gateways); + // else + // $gateways = $this->company->company_gateways; - $this->assertNotNull($gateways); + // $this->assertNotNull($gateways); - $pre_count = $gateways->count(); + // $pre_count = $gateways->count(); - $gateways->filter(function ($method) use ($amount){ - if($method->min_limit !== null && $amount < $method->min_limit) - return false; + // $gateways->filter(function ($method) use ($amount){ + // if($method->min_limit !== null && $amount < $method->min_limit) + // return false; - if($method->max_limit !== null && $amount > $method->min_limit) - return false; - }); + // if($method->max_limit !== null && $amount > $method->min_limit) + // return false; + // }); - $post_count = $gateways->count(); + // $post_count = $gateways->count(); - $this->assertEquals($pre_count, $post_count); + // $this->assertEquals($pre_count, $post_count); - $payment_methods = []; + // $payment_methods = []; - foreach($gateways as $gateway) - foreach($gateway->driver($this->client)->gatewayTypes() as $type) - $payment_methods[] = [$gateway->id => $type]; + // foreach($gateways as $gateway) + // foreach($gateway->driver($this->client)->gatewayTypes() as $type) + // $payment_methods[] = [$gateway->id => $type]; - $this->assertEquals(8, count($payment_methods)); + // $this->assertEquals(8, count($payment_methods)); - $payment_methods_collections = collect($payment_methods); + // $payment_methods_collections = collect($payment_methods); - //** Plucks the remaining keys into its own collection - $payment_methods_intersect = $payment_methods_collections->intersectByKeys( $payment_methods_collections->flatten(1)->unique() ); + // //** Plucks the remaining keys into its own collection + // $payment_methods_intersect = $payment_methods_collections->intersectByKeys( $payment_methods_collections->flatten(1)->unique() ); - $this->assertEquals(4, $payment_methods_intersect->count()); + // $this->assertEquals(4, $payment_methods_intersect->count()); - $payment_urls = []; + // $payment_urls = []; - foreach($payment_methods_intersect as $key => $child_array) - { - foreach($child_array as $gateway_id => $gateway_type_id) - { + // foreach($payment_methods_intersect as $key => $child_array) + // { + // foreach($child_array as $gateway_id => $gateway_type_id) + // { - $gateway = $gateways->where('id', $gateway_id)->first(); + // $gateway = $gateways->where('id', $gateway_id)->first(); - $this->assertNotNull($gateway); + // $this->assertNotNull($gateway); - $fee_label = $gateway->calcGatewayFeeLabel($amount, $this->client); + // $fee_label = $gateway->calcGatewayFeeLabel($amount, $this->client); - $payment_urls[] = [ - 'label' => ctrans('texts.' . $gateway->getTypeAlias($gateway_type_id)) . $fee_label, - 'url' => URL::signedRoute('client.payments.process', [ - 'company_gateway_id' => $gateway_id, - 'gateway_type_id' => $gateway_type_id]) - ]; - } + // $payment_urls[] = [ + // 'label' => ctrans('texts.' . $gateway->getTypeAlias($gateway_type_id)) . $fee_label, + // 'url' => URL::signedRoute('client.payments.process', [ + // 'company_gateway_id' => $gateway_id, + // 'gateway_type_id' => $gateway_type_id]) + // ]; + // } - } + // } - $this->assertEquals(4, count($payment_urls)); - } + // $this->assertEquals(4, count($payment_urls)); + // } } diff --git a/tests/Feature/CompanyTest.php b/tests/Feature/CompanyTest.php index 32cb238906ff..a17bc6c11dec 100644 --- a/tests/Feature/CompanyTest.php +++ b/tests/Feature/CompanyTest.php @@ -87,6 +87,7 @@ class CompanyTest extends TestCase ] ) ->assertStatus(200)->decodeResponseJson(); + $company = Company::find($this->decodePrimaryKey($response['data'][0]['company']['id'])); $response = $this->withHeaders([ @@ -116,11 +117,27 @@ class CompanyTest extends TestCase ->assertStatus(200); + $settings = new \stdClass; + $settings->custom_value1 = 'test'; + + $company->settings = $settings; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $token, + ])->put('/api/v1/companies/'.$this->encodePrimaryKey($company->id), $company->toArray()) + ->assertStatus(200)->decodeResponseJson(); + +\Log::error($response); + //$this->assertEquals(1, $response['data']['size_id']); + $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $token, ])->delete('/api/v1/companies/'.$this->encodePrimaryKey($company->id)) ->assertStatus(200); - } + + + } } diff --git a/tests/Unit/CompanySettingsTest.php b/tests/Unit/CompanySettingsTest.php index c85f99e3211b..7ff580c741b6 100644 --- a/tests/Unit/CompanySettingsTest.php +++ b/tests/Unit/CompanySettingsTest.php @@ -49,4 +49,14 @@ class CompanySettingsTest extends TestCase } + public function testSettingsArrayAgainstCastsArray() + { + $company_settings = json_decode(json_encode(CompanySettings::defaults()),true); + $casts = CompanySettings::$casts; + + $diff = array_diff_key($company_settings, $casts); + + $this->assertEquals(1, count($diff)); + } + }