diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index 651fd146a2b5..5b7c1ae7b94f 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -50,6 +50,8 @@ class StoreClientRequest extends Request if (isset($this->number)) { $rules['number'] = Rule::unique('clients')->where('company_id', auth()->user()->company()->id); } + + $rules['country_id'] = 'integer|nullable'; if(isset($this->currency_code)){ $rules['currency_code'] = 'sometimes|exists:currencies,code'; @@ -120,6 +122,10 @@ class StoreClientRequest extends Request $settings->currency_id = $this->getCurrencyCode($input['currency_code']); } + if (isset($input['language_code'])) { + $settings->language_id = $this->getLanguageId($input['language_code']); + } + $input['settings'] = $settings; if (isset($input['country_code'])) { @@ -147,6 +153,21 @@ class StoreClientRequest extends Request ]; } + private function getLanguageId($language_code) + { + $languages = Cache::get('languages'); + + $language = $languages->filter(function ($item) use ($language_code) { + return $item->locale == $language_code; + })->first(); + + if($language) + return (string) $language->id; + + return ""; + } + + private function getCountryCode($country_code) { $countries = Cache::get('countries'); diff --git a/app/Http/Requests/Client/UpdateClientRequest.php b/app/Http/Requests/Client/UpdateClientRequest.php index 2976c5baee38..c8d60ceeb5ec 100644 --- a/app/Http/Requests/Client/UpdateClientRequest.php +++ b/app/Http/Requests/Client/UpdateClientRequest.php @@ -16,6 +16,7 @@ use App\Http\Requests\Request; use App\Http\ValidationRules\ValidClientGroupSettingsRule; use App\Utils\Traits\ChecksEntityStatus; use App\Utils\Traits\MakesHash; +use Illuminate\Support\Facades\Cache; use Illuminate\Validation\Rule; class UpdateClientRequest extends Request @@ -103,6 +104,10 @@ class UpdateClientRequest extends Request $input['settings']['currency_id'] = (string) auth()->user()->company()->settings->currency_id; } + if (isset($input['language_code'])) { + $input['settings']['language_id'] = $this->getLanguageId($input['language_code']); + } + $input = $this->decodePrimaryKeys($input); if (array_key_exists('settings', $input)) { @@ -112,6 +117,22 @@ class UpdateClientRequest extends Request $this->replace($input); } + + private function getLanguageId($language_code) + { + $languages = Cache::get('languages'); + + $language = $languages->filter(function ($item) use ($language_code) { + return $item->locale == $language_code; + })->first(); + + if($language) + return (string) $language->id; + + return ""; + } + + /** * For the hosted platform, we restrict the feature settings. * diff --git a/app/PaymentDrivers/Sample/PaymentDriver.php b/app/PaymentDrivers/Sample/PaymentDriver.php index 71cbb77e540d..ad827919bd5b 100644 --- a/app/PaymentDrivers/Sample/PaymentDriver.php +++ b/app/PaymentDrivers/Sample/PaymentDriver.php @@ -17,6 +17,7 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentHash; use App\Models\SystemLog; +use App\PaymentDrivers\BaseDriver; use App\Utils\Traits\MakesHash; class PaymentDriver extends BaseDriver diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 83d1876a814a..e4db031e75a8 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1985,38 +1985,6 @@ $LANG = array( 'authorization' => 'Authorization', 'signed' => 'Signed', - // BlueVine - 'bluevine_promo' => 'Get flexible business lines of credit and invoice factoring using BlueVine.', - 'bluevine_modal_label' => 'Sign up with BlueVine', - 'bluevine_modal_text' => '

Fast funding for your business. No paperwork.

-', - 'bluevine_create_account' => 'Create an account', - 'quote_types' => 'Get a quote for', - 'invoice_factoring' => 'Invoice factoring', - 'line_of_credit' => 'Line of credit', - 'fico_score' => 'Your FICO score', - 'business_inception' => 'Business Inception Date', - 'average_bank_balance' => 'Average bank account balance', - 'annual_revenue' => 'Annual revenue', - 'desired_credit_limit_factoring' => 'Desired invoice factoring limit', - 'desired_credit_limit_loc' => 'Desired line of credit limit', - 'desired_credit_limit' => 'Desired credit limit', - 'bluevine_credit_line_type_required' => 'You must choose at least one', - 'bluevine_field_required' => 'This field is required', - 'bluevine_unexpected_error' => 'An unexpected error occurred.', - 'bluevine_no_conditional_offer' => 'More information is required before getting a quote. Click continue below.', - 'bluevine_invoice_factoring' => 'Invoice Factoring', - 'bluevine_conditional_offer' => 'Conditional Offer', - 'bluevine_credit_line_amount' => 'Credit Line', - 'bluevine_advance_rate' => 'Advance Rate', - 'bluevine_weekly_discount_rate' => 'Weekly Discount Rate', - 'bluevine_minimum_fee_rate' => 'Minimum Fee', - 'bluevine_line_of_credit' => 'Line of Credit', - 'bluevine_interest_rate' => 'Interest Rate', - 'bluevine_weekly_draw_rate' => 'Weekly Draw Rate', - 'bluevine_continue' => 'Continue to BlueVine', - 'bluevine_completed' => 'BlueVine signup completed', - 'vendor_name' => 'Vendor', 'entity_state' => 'State', 'client_created_at' => 'Date Created', @@ -4572,6 +4540,9 @@ $LANG = array( 'reminder_message' => 'Reminder for invoice :number for :balance', 'gmail_credentials_invalid_subject' => 'Send with GMail invalid credentials', 'gmail_credentials_invalid_body' => 'Your GMail credentials are not correct, please log into the administrator portal and navigate to Settings > User Details and disconnect and reconnect your GMail account. We will send you this notification daily until this issue is resolved', + 'notification_invoice_sent' => 'Invoice Sent', + 'total_columns' => 'Total Fields', + ); return $LANG; diff --git a/tests/Feature/ClientApiTest.php b/tests/Feature/ClientApiTest.php index 0e67928252a4..70d615697598 100644 --- a/tests/Feature/ClientApiTest.php +++ b/tests/Feature/ClientApiTest.php @@ -42,6 +42,95 @@ class ClientApiTest extends TestCase Model::reguard(); } + + public function testClientCountryCodeBe() + { + + $data = [ + 'name' => $this->faker->firstName, + 'id_number' => 'Coolio', + 'country_id' => '056' + ]; + + $response = false; + + try{ + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/clients/', $data); + } catch (ValidationException $e) { + $message = json_decode($e->validator->getMessageBag(), 1); + nlog($message); + } + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals("56", $arr['data']['country_id']); + } + + public function testClientLanguageCodeIllegal() + { + + $data = [ + 'name' => $this->faker->firstName, + 'id_number' => 'Coolio', + 'language_code' => 'not_really_a_VALID-locale' + ]; + + $response = false; + + try{ + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/clients/', $data); + } catch (ValidationException $e) { + $message = json_decode($e->validator->getMessageBag(), 1); + nlog($message); + } + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertFalse(array_key_exists('language_id', $arr['data']['settings'])); + + } + + + public function testClientLanguageCodeValidationTrue() + { + + $data = [ + 'name' => $this->faker->firstName, + 'id_number' => 'Coolio', + 'language_code' => 'de' + ]; + + $response = false; + + try{ + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/clients/', $data); + } catch (ValidationException $e) { + $message = json_decode($e->validator->getMessageBag(), 1); + nlog($message); + } + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals("3", $arr['data']['settings']['language_id']); + + } + + public function testClientCountryCodeValidationTrue() {