Skip to content

Commit 7d1b6aa

Browse files
Feature | Extend Swagger Coverage for controller OAuth2PaymentGatewayProfileApiController (#372)
* feat: Extend Swagger Coverage for controller Apis/Protected/Summit/OAuth2PaymentGatewayProfileApiController.php * fix: incorrect types and descriptions for errors * fix: Change "namespace" word positioning * fix: add security schema * fix: security scopes * fix: Security schema * chore: Move the security schema for the controller to its own file * fix: format of the security definitions * chore: add operationId * chore: include PR requested changes * fix: incorrect merge --------- Co-authored-by: Matias Perrone <github@matiasperrone.com>
1 parent 46e1f13 commit 7d1b6aa

3 files changed

Lines changed: 420 additions & 13 deletions

File tree

app/Http/Controllers/Apis/Protected/Summit/OAuth2PaymentGatewayProfileApiController.php

Lines changed: 313 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<?php namespace App\Http\Controllers;
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
25
/**
36
* Copyright 2020 OpenStack Foundation
47
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,13 +14,18 @@
1114
* See the License for the specific language governing permissions and
1215
* limitations under the License.
1316
**/
17+
use App\Models\Foundation\Main\IGroup;
1418
use App\Models\Foundation\Summit\Repositories\IPaymentGatewayProfileRepository;
19+
use App\Security\SummitScopes;
1520
use App\Services\Model\IPaymentGatewayProfileService;
1621
use models\oauth2\IResourceServerContext;
1722
use models\summit\ISummitRepository;
1823
use models\summit\Summit;
1924
use models\utils\IEntity;
2025
use ModelSerializers\SerializerRegistry;
26+
use OpenApi\Attributes as OA;
27+
use Symfony\Component\HttpFoundation\Response;
28+
2129

2230
/**
2331
* Class OAuth2PaymentGatewayProfileApiController
@@ -49,8 +57,7 @@ public function __construct
4957
ISummitRepository $summit_repository,
5058
IPaymentGatewayProfileService $service,
5159
IResourceServerContext $resource_server_context
52-
)
53-
{
60+
) {
5461
parent::__construct($resource_server_context);
5562
$this->repository = $repository;
5663
$this->summit_repository = $summit_repository;
@@ -67,6 +74,293 @@ public function __construct
6774

6875
use DeleteSummitChildElement;
6976

77+
// OpenAPI Documentation
78+
79+
#[OA\Get(
80+
path: '/api/v1/summits/{id}/payment-gateway-profiles',
81+
summary: 'Get all payment gateway profiles for a summit',
82+
operationId: 'getAllPaymentGatewayProfiles',
83+
description: 'Retrieves a paginated list of payment gateway profiles configured for a specific summit. Payment profiles manage payment processing for registrations and bookable rooms.',
84+
x: [
85+
'required-groups' => [
86+
IGroup::SuperAdmins,
87+
IGroup::Administrators,
88+
IGroup::SummitAdministrators,
89+
IGroup::SummitRegistrationAdmins,
90+
]
91+
],
92+
security: [
93+
[
94+
'summit_payment_gateway_oauth2' => [
95+
SummitScopes::ReadAllSummitData,
96+
SummitScopes::ReadPaymentProfiles
97+
]
98+
]
99+
],
100+
tags: ['Payment Gateway Profiles'],
101+
parameters: [
102+
new OA\Parameter(
103+
name: 'id',
104+
in: 'path',
105+
required: true,
106+
description: 'Summit ID',
107+
schema: new OA\Schema(type: 'integer')
108+
),
109+
new OA\Parameter(
110+
name: 'page',
111+
in: 'query',
112+
required: false,
113+
description: 'Page number for pagination',
114+
schema: new OA\Schema(type: 'integer', example: 1)
115+
),
116+
new OA\Parameter(
117+
name: 'per_page',
118+
in: 'query',
119+
required: false,
120+
description: 'Items per page',
121+
schema: new OA\Schema(type: 'integer', example: 10, maximum: 100)
122+
),
123+
new OA\Parameter(
124+
name: 'filter[]',
125+
in: 'query',
126+
required: false,
127+
description: 'Filter expressions. Format: field<op>value. Available fields: application_type (=@, ==), active (==). Operators: == (equals), =@ (starts with)',
128+
style: 'form',
129+
explode: true,
130+
schema: new OA\Schema(
131+
type: 'array',
132+
items: new OA\Items(type: 'string', example: 'application_type==Registration')
133+
)
134+
),
135+
new OA\Parameter(
136+
name: 'order',
137+
in: 'query',
138+
required: false,
139+
description: 'Order by field(s). Available fields: id, application_type. Use "-" prefix for descending order.',
140+
schema: new OA\Schema(type: 'string', example: 'id')
141+
),
142+
],
143+
responses: [
144+
new OA\Response(
145+
response: 200,
146+
description: 'Payment gateway profiles retrieved successfully',
147+
content: new OA\JsonContent(ref: '#/components/schemas/PaginatedPaymentGatewayProfilesResponse')
148+
),
149+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
150+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
151+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not Found"),
152+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
153+
]
154+
)]
155+
156+
#[OA\Get(
157+
path: '/api/v1/summits/{id}/payment-gateway-profiles/{payment_profile_id}',
158+
summary: 'Get a payment gateway profile by ID',
159+
operationId: 'getPaymentGatewayProfile',
160+
description: 'Retrieves detailed information about a specific payment gateway profile.',
161+
x: [
162+
'required-groups' => [
163+
IGroup::SuperAdmins,
164+
IGroup::Administrators,
165+
IGroup::SummitAdministrators,
166+
IGroup::SummitRegistrationAdmins,
167+
]
168+
],
169+
security: [
170+
[
171+
'summit_payment_gateway_oauth2' => [
172+
SummitScopes::ReadAllSummitData,
173+
SummitScopes::ReadPaymentProfiles
174+
]
175+
]
176+
],
177+
tags: ['Payment Gateway Profiles'],
178+
parameters: [
179+
new OA\Parameter(
180+
name: 'id',
181+
in: 'path',
182+
required: true,
183+
description: 'Summit ID',
184+
schema: new OA\Schema(type: 'integer')
185+
),
186+
new OA\Parameter(
187+
name: 'payment_profile_id',
188+
in: 'path',
189+
required: true,
190+
description: 'Payment Gateway Profile ID',
191+
schema: new OA\Schema(type: 'integer')
192+
),
193+
],
194+
responses: [
195+
new OA\Response(
196+
response: 200,
197+
description: 'Payment gateway profile retrieved successfully',
198+
content: new OA\JsonContent(ref: '#/components/schemas/PaymentGatewayProfile')
199+
),
200+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
201+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
202+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not Found"),
203+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
204+
]
205+
)]
206+
207+
#[OA\Post(
208+
path: '/api/v1/summits/{id}/payment-gateway-profiles',
209+
summary: 'Create a new payment gateway profile',
210+
operationId: 'createPaymentGatewayProfile',
211+
description: 'Creates a new payment gateway profile for the summit. Supports Stripe and LawPay providers.',
212+
x: [
213+
'required-groups' => [
214+
IGroup::SuperAdmins,
215+
IGroup::Administrators,
216+
IGroup::SummitAdministrators,
217+
IGroup::SummitRegistrationAdmins,
218+
]
219+
],
220+
security: [
221+
[
222+
'summit_payment_gateway_oauth2' => [
223+
SummitScopes::WriteSummitData,
224+
SummitScopes::WritePaymentProfiles
225+
]
226+
]
227+
],
228+
tags: ['Payment Gateway Profiles'],
229+
parameters: [
230+
new OA\Parameter(
231+
name: 'id',
232+
in: 'path',
233+
required: true,
234+
description: 'Summit ID',
235+
schema: new OA\Schema(type: 'integer')
236+
),
237+
],
238+
requestBody: new OA\RequestBody(
239+
required: true,
240+
content: new OA\JsonContent(ref: '#/components/schemas/PaymentGatewayProfileCreateRequest')
241+
),
242+
responses: [
243+
new OA\Response(
244+
response: 201,
245+
description: 'Payment gateway profile created successfully',
246+
content: new OA\JsonContent(ref: '#/components/schemas/PaymentGatewayProfile')
247+
),
248+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
249+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
250+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
251+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not Found"),
252+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
253+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
254+
]
255+
)]
256+
257+
#[OA\Put(
258+
path: '/api/v1/summits/{id}/payment-gateway-profiles/{payment_profile_id}',
259+
summary: 'Update a payment gateway profile',
260+
operationId: 'updatePaymentGatewayProfile',
261+
description: 'Updates an existing payment gateway profile.',
262+
x: [
263+
'required-groups' => [
264+
IGroup::SuperAdmins,
265+
IGroup::Administrators,
266+
IGroup::SummitAdministrators,
267+
IGroup::SummitRegistrationAdmins,
268+
]
269+
],
270+
security: [
271+
[
272+
'summit_payment_gateway_oauth2' => [
273+
SummitScopes::WriteSummitData,
274+
SummitScopes::WritePaymentProfiles
275+
]
276+
]
277+
],
278+
tags: ['Payment Gateway Profiles'],
279+
parameters: [
280+
new OA\Parameter(
281+
name: 'id',
282+
in: 'path',
283+
required: true,
284+
description: 'Summit ID',
285+
schema: new OA\Schema(type: 'integer')
286+
),
287+
new OA\Parameter(
288+
name: 'payment_profile_id',
289+
in: 'path',
290+
required: true,
291+
description: 'Payment Gateway Profile ID',
292+
schema: new OA\Schema(type: 'integer')
293+
),
294+
],
295+
requestBody: new OA\RequestBody(
296+
required: true,
297+
content: new OA\JsonContent(ref: '#/components/schemas/PaymentGatewayProfileUpdateRequest')
298+
),
299+
responses: [
300+
new OA\Response(
301+
response: 200,
302+
description: 'Payment gateway profile updated successfully',
303+
content: new OA\JsonContent(ref: '#/components/schemas/PaymentGatewayProfile')
304+
),
305+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
306+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
307+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
308+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not Found"),
309+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
310+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
311+
]
312+
)]
313+
314+
#[OA\Delete(
315+
path: '/api/v1/summits/{id}/payment-gateway-profiles/{payment_profile_id}',
316+
summary: 'Delete a payment gateway profile',
317+
operationId: 'deletePaymentGatewayProfile',
318+
description: 'Deletes an existing payment gateway profile from the summit.',
319+
x: [
320+
'required-groups' => [
321+
IGroup::SuperAdmins,
322+
IGroup::Administrators,
323+
IGroup::SummitAdministrators,
324+
IGroup::SummitRegistrationAdmins,
325+
]
326+
],
327+
security: [
328+
[
329+
'summit_payment_gateway_oauth2' => [
330+
SummitScopes::WriteSummitData,
331+
SummitScopes::WritePaymentProfiles
332+
]
333+
]
334+
],
335+
tags: ['Payment Gateway Profiles'],
336+
parameters: [
337+
new OA\Parameter(
338+
name: 'id',
339+
in: 'path',
340+
required: true,
341+
description: 'Summit ID',
342+
schema: new OA\Schema(type: 'integer')
343+
),
344+
new OA\Parameter(
345+
name: 'payment_profile_id',
346+
in: 'path',
347+
required: true,
348+
description: 'Payment Gateway Profile ID',
349+
schema: new OA\Schema(type: 'integer')
350+
),
351+
],
352+
responses: [
353+
new OA\Response(
354+
response: 204,
355+
description: 'Payment gateway profile deleted successfully'
356+
),
357+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
358+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
359+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not Found"),
360+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
361+
]
362+
)]
363+
70364
/**
71365
* @return ISummitRepository
72366
*/
@@ -126,46 +420,52 @@ protected function updateChild(Summit $summit, int $child_id, array $payload): I
126420
/**
127421
* @return array
128422
*/
129-
protected function getFilterRules():array
423+
protected function getFilterRules(): array
130424
{
131425
return [
132426
'application_type' => ['=@', '=='],
133-
'active' => ['=='],
427+
'active' => ['=='],
134428
];
135429
}
136430

137431
/**
138432
* @return array
139433
*/
140-
protected function getFilterValidatorRules():array{
434+
protected function getFilterValidatorRules(): array
435+
{
141436
return [
142437
'application_type' => 'sometimes|required|string',
143-
'active' => 'sometimes|required|boolean',
438+
'active' => 'sometimes|required|boolean',
144439
];
145440
}
146441
/**
147442
* @return array
148443
*/
149-
protected function getOrderRules():array{
444+
protected function getOrderRules(): array
445+
{
150446
return [
151447
'id',
152448
'application_type',
153449
];
154450
}
155451

156-
protected function serializerType():string{
452+
protected function serializerType(): string
453+
{
157454
return SerializerRegistry::SerializerType_Private;
158455
}
159456

160-
protected function addSerializerType():string{
457+
protected function addSerializerType(): string
458+
{
161459
return SerializerRegistry::SerializerType_Private;
162460
}
163461

164-
protected function updateSerializerType():string{
462+
protected function updateSerializerType(): string
463+
{
165464
return SerializerRegistry::SerializerType_Private;
166465
}
167466

168-
public function getChildSerializer(){
467+
public function getChildSerializer()
468+
{
169469
return SerializerRegistry::SerializerType_Private;
170470
}
171-
}
471+
}

0 commit comments

Comments
 (0)