diff --git a/app/Http/Controllers/CompanyGatewayController.php b/app/Http/Controllers/CompanyGatewayController.php index 08b0b9ce215b..1edef4345a2b 100644 --- a/app/Http/Controllers/CompanyGatewayController.php +++ b/app/Http/Controllers/CompanyGatewayController.php @@ -131,7 +131,10 @@ class CompanyGatewayController extends BaseController * @return \Illuminate\Http\Response */ public function update(UpdateCompanyGatewayRequest $request, CompanyGateway $company_gateway) + //public function update(CompanyGateway $company_gateway) { + \Log::error('wooppee'); + \Log::error(print_r($company_gateway,1)); $company_gateway->fill($request->all()); $company_gateway->save(); diff --git a/app/Http/Requests/CompanyGateway/CreateCompanyGatewayRequest.php b/app/Http/Requests/CompanyGateway/CreateCompanyGatewayRequest.php index 24bf160e57bc..54c9c4ec0d2b 100644 --- a/app/Http/Requests/CompanyGateway/CreateCompanyGatewayRequest.php +++ b/app/Http/Requests/CompanyGateway/CreateCompanyGatewayRequest.php @@ -29,4 +29,5 @@ class CreateCompanyGatewayRequest extends Request } + } \ No newline at end of file diff --git a/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php b/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php index 064d5f3e1b1d..16302fcdb24f 100644 --- a/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php +++ b/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php @@ -31,7 +31,9 @@ class UpdateCompanyGatewayRequest extends Request { $this->sanitize(); - $rules = []; + $rules = [ + 'gateway_key' => 'required', + ]; return $rules; } diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index d10513e36dae..798805d15fd2 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -107,6 +107,11 @@ class CompanyGateway extends BaseModel return json_decode(decrypt($this->config)); } + public function getConfigTransformed() + { + return $this->config ? decrypt($this->config) : ''; + } + /** * @param $field * diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 94efcb339181..aa7656c8af49 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -81,6 +81,10 @@ class RouteServiceProvider extends ServiceProvider return \App\Models\Company::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); + Route::bind('company_gateway', function ($value) { + return \App\Models\CompanyGateway::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); + }); + Route::bind('companies', function ($value) { return \App\Models\Company::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); diff --git a/app/Transformers/CompanyGatewayTransformer.php b/app/Transformers/CompanyGatewayTransformer.php index b25ab8d3109f..80227b7b4898 100644 --- a/app/Transformers/CompanyGatewayTransformer.php +++ b/app/Transformers/CompanyGatewayTransformer.php @@ -49,7 +49,7 @@ class CompanyGatewayTransformer extends EntityTransformer 'show_address' => (bool)$company_gateway->show_address, 'show_shipping_address' => (bool)$company_gateway->show_shipping_address, 'update_details' => (bool)$company_gateway->update_details, - 'config' => (string) decrypt($company_gateway->config) ?: '', + 'config' => (string) $company_gateway->getConfigTransformed(), 'priority_id' => (int)$company_gateway->priority_id, 'min_limit' => (float)$company_gateway->min_limit, 'max_limit' => (float)$company_gateway->max_limit, diff --git a/tests/Feature/CompanyGatewayApiTest.php b/tests/Feature/CompanyGatewayApiTest.php index ffe441ca65c8..1303608b4907 100644 --- a/tests/Feature/CompanyGatewayApiTest.php +++ b/tests/Feature/CompanyGatewayApiTest.php @@ -29,6 +29,7 @@ class CompanyGatewayApiTest extends TestCase use DatabaseTransactions; use MockAccountData; + public function setUp() :void { parent::setUp(); @@ -40,52 +41,84 @@ class CompanyGatewayApiTest extends TestCase $this->faker = \Faker\Factory::create(); Model::reguard(); + } - public function testCompanyGatewayPost() + public function testCompanyGatewayEndPoints() { $data = [ 'config' => 'random config', + 'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb', ]; - + /* POST */ $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token ])->post('/api/v1/company_gateways', $data); + $cg = $response->json(); + + $cg_id = $cg['data']['id']; + + $this->assertNotNull($cg_id); $response->assertStatus(200); - } - public function testCompanyGatewayPut() - { + + + /* GET */ + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token + ])->get("/api/v1/company_gateways/{$cg_id}"); + + + $response->assertStatus(200); + + + /* GET CREATE */ + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token + ])->get('/api/v1/company_gateways/create'); + + + $response->assertStatus(200); + + /* PUT */ $data = [ 'config' => 'changed', ]; + \Log::error('the id = '.$cg_id); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token - ])->put('/api/v1/company_gateways/'.$this->encodePrimaryKey($this->client->id), $data); - + ])->put("/api/v1/company_gateways/{$cg_id}", $data); $response->assertStatus(200); - } - - public function testCompanyGatewayGet() - { - $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token - ])->get('/api/v1/company_gateways/'.$this->encodePrimaryKey($this->client->id)); + ])->put("/api/v1/company_gateways/{$cg_id}", $data); $response->assertStatus(200); + + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token + ])->delete("/api/v1/company_gateways/{$cg_id}", $data); + + + $response->assertStatus(200); + + } diff --git a/tests/Integration/UploadLogoTest.php b/tests/Integration/UploadLogoTest.php index 9d39bf0fea37..7ea52308d61b 100644 --- a/tests/Integration/UploadLogoTest.php +++ b/tests/Integration/UploadLogoTest.php @@ -58,7 +58,7 @@ class UploadLogoTest extends TestCase $response->assertStatus(200); $acc = $response->json(); - $logo = $acc['data']['logo']; + $logo = $acc['data']['logo_url']; $logo_file = Storage::url($logo);