Migrated getPaymentMethods route
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
}
}
},
+ "/api/users/{id}/payment-methods": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Get user's payment methods",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/userID"
+ },
+ {
+ "$ref": "#/components/parameters/Skip"
+ },
+ {
+ "$ref": "#/components/parameters/Limit"
+ }
+ ],
+ "tags": [
+ "Billing"
+ ],
+ "responses": {
+ "200": {
+ "description": "Retrieved user payment methods",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "count": {
+ "type": "number"
+ },
+ "result": {
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/BillingPaymentMethod"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ }
+ },
"/api/tags": {
"get": {
"security": [
}
}
}
+ },
+ "BillingPaymentMethod": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "readOnly": true
+ },
+ "brand": {
+ "type": "string"
+ },
+ "expiringOn": {
+ "type": "string",
+ "format": "date-time"
+ },
+ "last4": {
+ "type": "string"
+ },
+ "type": {
+ "type": "string"
+ },
+ "createdOn": {
+ "type": "string",
+ "format": "date-time"
+ },
+ "isDefault": {
+ "type": "boolean"
+ }
+ }
}
},
"parameters": {

ADD
src/assets/server/rest/v1/schemas/billing/billing-payment-methods-get.json
+{
+ "$id": "billing-payment-methods-get",
+ "title": "Get user payments methods",
+ "type": "object",
+ "properties": {
+ "userID": {
+ "$ref": "common#/definitions/id"
+ },
+ "Limit": {
+ "$ref": "common#/definitions/limit"
+ },
+ "Skip": {
+ "$ref": "common#/definitions/skip"
+ }
+ },
+ "required": [
+ "userID",
+ "Limit"
+ ]
+}

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -527,7 +527,7 @@ export default class BillingService {
public static async handleBillingGetPaymentMethods(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = BillingSecurity.filterPaymentMethodsRequest(req.query);
+ const filteredRequest = BillingValidator.getInstance().validateBillingGetUserPaymentMethodsReq(req.query);
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,
Action.BILLING_PAYMENT_METHODS, Entity.BILLING, MODULE_NAME, 'handleBillingGetPaymentMethods');

MODIFY
src/server/rest/v1/validator/BillingValidator.ts
src/server/rest/v1/validator/BillingValidator.ts
import { BillingSettings } from '../../../../types/Setting';
+import { HttpPaymentMethods } from '../../../../types/requests/HttpBillingRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from '../../../../validator/SchemaValidator';
import fs from 'fs';
@@ -7,10 +8,12 @@ import global from '../../../../types/GlobalType';
export default class BillingValidator extends SchemaValidator {
private static instance: BillingValidator|null = null;
private billingSettingUpdate: Schema;
+ private billingGetUserPaymentMethods: Schema;
private constructor() {
super('BillingValidator');
this.billingSettingUpdate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/billing/billing-setting-update.json`, 'utf8'));
+ this.billingGetUserPaymentMethods = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/billing/billing-payment-methods-get.json`, 'utf8'));
}
public static getInstance(): BillingValidator {
@@ -23,4 +26,8 @@ export default class BillingValidator extends SchemaValidator {
public validateBillingSettingUpdateReq(data: Record<string, unknown>): BillingSettings {
return this.validate(this.billingSettingUpdate, data);
}
+
+ public validateBillingGetUserPaymentMethodsReq(data: Record<string, unknown>): HttpPaymentMethods {
+ return this.validate(this.billingGetUserPaymentMethods, data);
+ }
}

Migrated getPaymentMethods route