Added billing setupPaymentMethod doc + schema
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
],
"responses": {
"200": {
- "description": "Delete user payment methods",
+ "description": "Successfully deleted user payment method",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/BillingOperationResult"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ }
+ },
+ "/api/users/{id}/payment-methods/setup": {
+ "post": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Setup user's payment method",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/userID"
+ }
+ ],
+ "tags": [
+ "Billing"
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "paymentMethodId": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "Successfully setup user payment method",
"content": {
"application/json": {
"schema": {

MODIFY
src/assets/server/rest/v1/schemas/billing/billing-delete-payment-method.json
src/assets/server/rest/v1/schemas/billing/billing-delete-payment-method.json
{
"$id": "billing-delete-payment-method",
- "title": "Dele user payment method Request",
+ "title": "Delete user payment method Request",
"type": "object",
"properties": {
"userID": {

ADD
src/assets/server/rest/v1/schemas/billing/billing-setup-payment-method.json
+{
+ "$id": "billing-setup-payment-method",
+ "title": "Setup user payment method Request",
+ "type": "object",
+ "properties": {
+ "userID": {
+ "$ref": "common#/definitions/id"
+ },
+ "paymentMethodId": {
+ "type": "string",
+ "sanitize": "mongo"
+ }
+ },
+ "required": [
+ "userID"
+ ]
+}

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -491,7 +491,7 @@ export default class BillingService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,
Action.BILLING_SETUP_PAYMENT_METHOD, Entity.BILLING, MODULE_NAME, 'handleSetupSetupPaymentMethod');
// Filter
- const filteredRequest = BillingSecurity.filterSetupPaymentMethodRequest(req.body);
+ const filteredRequest = BillingValidator.getInstance().validateBillingSetupUserPaymentMethodReq(req.body);
if (!await Authorizations.canCreatePaymentMethod(req.user, filteredRequest.userID)) {
throw new AppAuthError({
errorCode: HTTPAuthError.FORBIDDEN,

MODIFY
src/server/rest/v1/validator/BillingValidator.ts
src/server/rest/v1/validator/BillingValidator.ts
@@ -11,12 +11,14 @@ export default class BillingValidator extends SchemaValidator {
private billingSettingUpdate: Schema;
private billingGetUserPaymentMethods: Schema;
private billingDeleteUserPaymentMethod: Schema;
+ private billingSetupUserPaymentMethod: 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'));
this.billingDeleteUserPaymentMethod = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/billing/billing-delete-payment-method.json`, 'utf8'));
+ this.billingSetupUserPaymentMethod = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/billing/billing-setup-payment-method.json`, 'utf8'));
}
public static getInstance(): BillingValidator {
@@ -37,4 +39,8 @@ export default class BillingValidator extends SchemaValidator {
public validateBillingDeleteUserPaymentMethodReq(data: Record<string, unknown>): HttpDeletePaymentMethod {
return this.validate(this.billingDeleteUserPaymentMethod, data);
}
+
+ public validateBillingSetupUserPaymentMethodReq(data: Record<string, unknown>): HttpDeletePaymentMethod {
+ return this.validate(this.billingSetupUserPaymentMethod, data);
+ }
}

Added billing setupPaymentMethod doc + schema