mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 23:37:33 -05:00 
			
		
		
		
	Force integer for client id
This commit is contained in:
		
							parent
							
								
									abe06f3d9b
								
							
						
					
					
						commit
						f3d1c35b7f
					
				@ -51,6 +51,8 @@ class StoreClientRequest extends Request
 | 
			
		||||
            $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');
 | 
			
		||||
 | 
			
		||||
@ -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.
 | 
			
		||||
     *
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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' => '<h3>Fast funding for your business. No paperwork.</h3>
 | 
			
		||||
<ul><li>Flexible business lines of credit and invoice factoring.</li></ul>',
 | 
			
		||||
    '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;
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user