paymentMethodsList renamed getPaymentMethods
MODIFY
src/integration/billing/BillingIntegration.ts
src/integration/billing/BillingIntegration.ts
@@ -591,7 +591,7 @@ export default abstract class BillingIntegration<T extends BillingSetting> {
abstract consumeBillingEvent(req: Request): Promise<boolean>;
- abstract paymentMethodsList(user: User): Promise<BillingPaymentMethodResult>;
+ abstract getPaymentMethods(user: User): Promise<BillingPaymentMethodResult>;
abstract deletePaymentMethod(user: User, paymentMethodId: string): Promise<BillingPaymentMethodResult>;
}

MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -585,7 +585,7 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
return billingOperationResult;
}
- public async paymentMethodsList(user: User): Promise<DataResult<BillingPaymentMethod>> {
+ public async getPaymentMethods(user: User): Promise<DataResult<BillingPaymentMethod>> {
// Check Stripe
await this.checkConnection();
// Check billing data consistency
@@ -597,12 +597,12 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
message: 'User is not known in Stripe',
source: Constants.CENTRAL_SERVER,
module: MODULE_NAME,
- method: 'paymentMethodsList',
+ method: 'getPaymentMethods',
action: ServerAction.BILLING_TRANSACTION
});
}
- const paymentMethodResult: BillingPaymentMethodResult = await this._getPaymentMethodsList(user, user.billingData.customerID);
+ const paymentMethodResult: BillingPaymentMethodResult = await this._getPaymentMethods(user, user.billingData.customerID);
return paymentMethodResult;
}
@@ -710,8 +710,8 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
}
}
- private async _getPaymentMethodsList(user: User, customerID: string): Promise<DataResult<BillingPaymentMethod>> {
- const paymentMethodsList = [] as BillingPaymentMethod[];
+ private async _getPaymentMethods(user: User, customerID: string): Promise<DataResult<BillingPaymentMethod>> {
+ const paymentMethods: BillingPaymentMethod[] = [];
try {
let request;
const requestParams : Stripe.PaymentMethodListParams = {
@@ -723,25 +723,25 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
do {
request = await this.stripe.paymentMethods.list(requestParams);
for (const paymentMethod of request.data) {
- paymentMethodsList.push({
+ paymentMethods.push({
id: paymentMethod.id,
brand: paymentMethod.card.brand,
- expiringOn: (paymentMethod.card.exp_month).toString().padStart(2, '0') + '/' + paymentMethod.card.exp_year,
+ expiringOn: new Date(paymentMethod.card.exp_year, paymentMethod.card.exp_month, 0),
last4: paymentMethod.card.last4,
type: paymentMethod.type,
- createdOn: new Date((paymentMethod.created) * 1000),
+ createdOn: moment.unix(paymentMethod.created).toDate(),
isDefault: paymentMethod.id === customer.invoice_settings.default_payment_method
});
}
if (request.has_more) {
- requestParams.starting_after = paymentMethodsList[paymentMethodsList.length - 1].id;
+ requestParams.starting_after = paymentMethods[paymentMethods.length - 1].id;
}
} while (request.has_more);
await Logging.logInfo({
tenantID: this.tenantID,
source: Constants.CENTRAL_SERVER,
- action: ServerAction.BILLING_PAYMENT_METHODS_LIST,
- module: MODULE_NAME, method: '_getPaymentMethodsList',
+ action: ServerAction.BILLING_PAYMENT_METHODS,
+ module: MODULE_NAME, method: '_getPaymentMethods',
message: `Payment method has been listed for customer '${customerID}' - (${user.email})`
});
} catch (e) {
@@ -750,18 +750,18 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
tenantID: this.tenantID,
action: ServerAction.BILLING_SETUP_PAYMENT_METHOD,
actionOnUser: user,
- module: MODULE_NAME, method: '_getPaymentMethodsList',
+ module: MODULE_NAME, method: '_getPaymentMethods',
message: `Stripe operation failed - ${e?.message as string}`
});
}
return {
- count: paymentMethodsList.length,
- result: paymentMethodsList
+ count: paymentMethods.length,
+ result: paymentMethods
};
}
private async _detachPaymentMethod(paymentMethodId: string, customerID: string): Promise<BillingPaymentMethodResult> {
- const detachedPaymentMethod = [] as BillingPaymentMethod[];
+ const detachedPaymentMethod: BillingPaymentMethod[] = [];
try {
// Verify payment method to be deleted is not the default one
const customer = await this.getStripeCustomer(customerID);
@@ -779,10 +779,10 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
detachedPaymentMethod.push({
id: paymentMethod.id,
brand: paymentMethod.card.brand,
- expiringOn: (paymentMethod.card.exp_month).toString().padStart(2, '0') + '/' + paymentMethod.card.exp_year,
+ expiringOn: new Date(paymentMethod.card.exp_year, paymentMethod.card.exp_month, 0),
last4: paymentMethod.card.last4,
type: paymentMethod.type,
- createdOn: new Date((paymentMethod.created) * 1000),
+ createdOn: moment.unix(paymentMethod.created).toDate(),
isDefault: paymentMethod.id === customer.invoice_settings.default_payment_method
});
await Logging.logInfo({
@@ -820,7 +820,7 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
tenantID: this.tenantID,
action: ServerAction.BILLING_SETUP_PAYMENT_METHOD,
actionOnUser: customerID,
- module: MODULE_NAME, method: '_getPaymentMethodsList',
+ module: MODULE_NAME, method: '_getPaymentMethods',
message: `Stripe operation failed - ${e?.message as string}`
});
}

MODIFY
src/server/rest/CentralRestServerService.ts
src/server/rest/CentralRestServerService.ts
@@ -196,7 +196,7 @@ class RequestMapper {
[ServerAction.BILLING_TAXES]: BillingService.handleGetBillingTaxes.bind(this),
[ServerAction.BILLING_INVOICES]: BillingService.handleGetInvoices.bind(this),
[ServerAction.BILLING_DOWNLOAD_INVOICE]: BillingService.handleDownloadInvoice.bind(this),
- [ServerAction.BILLING_PAYMENT_METHODS_LIST]: BillingService.handleBillingGetPaymentMethodsList.bind(this),
+ [ServerAction.BILLING_PAYMENT_METHODS]: BillingService.handleBillingGetPaymentMethods.bind(this),
[ServerAction.OCPI_ENDPOINTS]: OCPIEndpointService.handleGetOcpiEndpoints.bind(this),
[ServerAction.OCPI_ENDPOINT]: OCPIEndpointService.handleGetOcpiEndpoint.bind(this),
[ServerAction.OICP_ENDPOINTS]: OICPEndpointService.handleGetOicpEndpoints.bind(this),

MODIFY
src/server/rest/v1/router/api/BillingRouter.ts
src/server/rest/v1/router/api/BillingRouter.ts
@@ -13,12 +13,13 @@ export default class BillingRouter {
}
public buildRoutes(): express.Router {
- this.buildRouteSetupPaymentMethod();
- this.buildRoutePaymentMethodsList();
+ this.buildRouteBillingSetupPaymentMethod();
+ this.buildRouteBillingPaymentMethods();
+ this.buildRouteBillingDeletePaymentMethod();
return this.router;
}
- protected buildRouteSetupPaymentMethod(): void {
+ protected buildRouteBillingSetupPaymentMethod(): void {
this.router.put(`/${ServerAction.BILLING_SETUP_PAYMENT_METHOD}`, async (req: Request, res: Response, next: NextFunction) => {
await RouterUtils.handleServerAction(BillingService.handleBillingSetupPaymentMethod.bind(this), ServerAction.BILLING_SETUP_PAYMENT_METHOD, req, res, next);
});
@@ -26,15 +27,15 @@ export default class BillingRouter {
// why in other routers we can see ServerRoute.REST_BILLING_PAYMENT_METHODS ????
// don't get the difference
- protected buildRoutePaymentMethodsList(): void {
- this.router.get(`/${ServerAction.BILLING_PAYMENT_METHODS_LIST}`, async (req: Request, res: Response, next: NextFunction) => {
+ protected buildRouteBillingPaymentMethods(): void {
+ this.router.get(`/${ServerAction.BILLING_PAYMENT_METHODS}`, async (req: Request, res: Response, next: NextFunction) => {
// req.query.ID = req.params.id;
- await RouterUtils.handleServerAction(BillingService.handleBillingGetPaymentMethodsList.bind(this), ServerAction.BILLING_PAYMENT_METHODS_LIST, req, res, next);
+ await RouterUtils.handleServerAction(BillingService.handleBillingGetPaymentMethods.bind(this), ServerAction.BILLING_PAYMENT_METHODS, req, res, next);
});
}
// delete ou post ?
- protected buildRouteDeletePaymentMethod(): void {
+ protected buildRouteBillingDeletePaymentMethod(): void {
this.router.delete(`/${ServerAction.BILLING_DELETE_PAYMENT_METHOD}`, async (req: Request, res: Response, next: NextFunction) => {
req.query.ID = req.params.id;
await RouterUtils.handleServerAction(BillingService.handleBillingDeletePaymentMethod.bind(this), ServerAction.BILLING_DELETE_PAYMENT_METHOD, req, res, next);

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -512,18 +512,18 @@ export default class BillingService {
res.json(operationResult);
}
- public static async handleBillingGetPaymentMethodsList(action: ServerAction, req: Request, res: Response): Promise<void> {
+ public static async handleBillingGetPaymentMethods(action: ServerAction, req: Request, res: Response): Promise<void> {
// Filter
- const filteredRequest = BillingSecurity.filterPaymentMethodsListRequest(req);
+ const filteredRequest = BillingSecurity.filterPaymentMethodsRequest(req);
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(filteredRequest.loggedUser, TenantComponents.BILLING,
- Action.BILLING_PAYMENT_METHODS_LIST, Entity.BILLING, MODULE_NAME, 'handleBillingGetPaymentMethodsList');
+ Action.BILLING_PAYMENT_METHODS, Entity.BILLING, MODULE_NAME, 'handleBillingGetPaymentMethods');
if (!Authorizations.canListPaymentMethod(filteredRequest.loggedUser)) {
throw new AppAuthError({
errorCode: HTTPAuthError.FORBIDDEN,
user: filteredRequest.loggedUser,
action: Action.CREATE, entity: Entity.PAYMENT_METHOD,
- module: MODULE_NAME, method: 'handleBillingGetPaymentMethodsList'
+ module: MODULE_NAME, method: 'handleBillingGetPaymentMethods'
});
}
// Get the billing impl
@@ -533,7 +533,7 @@ export default class BillingService {
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
message: 'Billing service is not configured',
- module: MODULE_NAME, method: 'handleBillingGetPaymentMethodsList',
+ module: MODULE_NAME, method: 'handleBillingGetPaymentMethods',
action: action,
user: filteredRequest.loggedUser
});
@@ -541,9 +541,9 @@ export default class BillingService {
// Get user
const user: User = await UserStorage.getUser(filteredRequest.loggedUser.tenantID, filteredRequest.selectedUserID);
UtilsService.assertObjectExists(action, user, `User '${filteredRequest.selectedUserID}' does not exist`,
- MODULE_NAME, 'handleBillingGetPaymentMethodsList', filteredRequest.loggedUser);
+ MODULE_NAME, 'handleBillingGetPaymentMethods', filteredRequest.loggedUser);
// Invoke the billing implementation
- const paymentMethodResult: BillingPaymentMethodResult = await billingImpl.paymentMethodsList(user);
+ const paymentMethodResult: BillingPaymentMethodResult = await billingImpl.getPaymentMethods(user);
if (paymentMethodResult) {
console.log(paymentMethodResult);
}
@@ -555,7 +555,7 @@ export default class BillingService {
const filteredRequest = BillingSecurity.filterDeletePaymentMethodRequest(req);
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(filteredRequest.loggedUser, TenantComponents.BILLING,
- Action.BILLING_PAYMENT_METHODS_LIST, Entity.BILLING, MODULE_NAME, 'handleBillingDeletePaymentMethod');
+ Action.BILLING_PAYMENT_METHODS, Entity.BILLING, MODULE_NAME, 'handleBillingDeletePaymentMethod');
if (!Authorizations.canDeletePaymentMethod(filteredRequest.loggedUser)) {
throw new AppAuthError({
errorCode: HTTPAuthError.FORBIDDEN,

MODIFY
src/server/rest/v1/service/security/BillingSecurity.ts
src/server/rest/v1/service/security/BillingSecurity.ts
-import { HttpBillingInvoiceRequest, HttpBillingWebHookRequest, HttpDeletePaymentMethod, HttpPaymentMethodsList, HttpSetupPaymentMethod } from '../../../../../types/requests/HttpBillingRequest';
+import { HttpBillingInvoiceRequest, HttpBillingWebHookRequest, HttpDeletePaymentMethod, HttpPaymentMethods, HttpSetupPaymentMethod } from '../../../../../types/requests/HttpBillingRequest';
import { HttpCreateTransactionInvoiceRequest, HttpForceSynchronizeUserInvoicesRequest, HttpSynchronizeUserRequest } from '../../../../../types/requests/HttpUserRequest';
import HttpByIDRequest from '../../../../../types/requests/HttpByIDRequest';
@@ -78,8 +78,8 @@ export default class BillingSecurity {
};
}
- static filterPaymentMethodsListRequest(request: any): HttpPaymentMethodsList {
- const filteredRequest: HttpPaymentMethodsList = {
+ static filterPaymentMethodsRequest(request: any): HttpPaymentMethods {
+ const filteredRequest: HttpPaymentMethods = {
loggedUser: sanitize(request.user),
selectedUserID: sanitize(request.query.userID)
};

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -127,7 +127,7 @@ export enum Action {
SYNCHRONIZE_BILLING_USERS = 'SynchronizeBillingUsers',
SYNCHRONIZE_BILLING_USER = 'SynchronizeBillingUser',
BILLING_SETUP_PAYMENT_METHOD = 'BillingSetupPaymentMethod',
- BILLING_PAYMENT_METHODS_LIST = 'BillingPaymentMethodsList',
+ BILLING_PAYMENT_METHODS = 'BillingPaymentMethods',
BILLING_DELETE_PAYMENT_METHOD = 'BillingDeletePaymentMethod',
BILLING_CHARGE_INVOICE = 'BillingChargeInvoice',
CHECK_CONNECTION = 'CheckConnection',

MODIFY
src/types/Billing.ts
src/types/Billing.ts
@@ -120,7 +120,7 @@ export interface BillingOperationResult {
export interface BillingPaymentMethod {
id: string;
brand: string;
- expiringOn: string;
+ expiringOn: Date;
last4: string;
type: string;
createdOn: Date;

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -409,7 +409,7 @@ export enum ServerAction {
BILLING_CREATE_TRANSACTION_INVOICE = 'BillingCreateTransactionInvoice',
BILLING_NEW_INVOICE = 'BillingNewInvoice',
BILLING_SETUP_PAYMENT_METHOD = 'BillingSetupPaymentMethod',
- BILLING_PAYMENT_METHODS_LIST = 'BillingPaymentMethodsList',
+ BILLING_PAYMENT_METHODS = 'BillingPaymentMethods',
BILLING_DELETE_PAYMENT_METHOD = 'BillingDeletePaymentMethod',
BILLING_CHARGE_INVOICE = 'BillingChargeInvoice',
BILLING_WEB_HOOK = 'BillingWebHook',

MODIFY
src/types/requests/HttpBillingRequest.ts
src/types/requests/HttpBillingRequest.ts
@@ -24,7 +24,7 @@ export interface HttpSetupPaymentMethod {
paymentMethodId?: string;
}
-export interface HttpPaymentMethodsList {
+export interface HttpPaymentMethods {
loggedUser: UserToken;
selectedUserID: string;
}

paymentMethodsList renamed getPaymentMethods