modified i18n newInvoices
added price to email notification
modified billingNewInvoiceNotification to add specific values needed for notifications
MODIFY
src/integration/billing/BillingIntegration.ts
src/integration/billing/BillingIntegration.ts
@@ -222,7 +222,10 @@ export default abstract class BillingIntegration {
invoiceDownloadUrl: Utils.buildEvseBillingDownloadInvoicesURL(tenant.subdomain, billingInvoice.id),
// Empty url allows to decide wether to display "pay" button in the email
payInvoiceUrl: billingInvoice.status === 'open' ? billingInvoice.payInvoiceUrl : '',
- invoice: billingInvoice,
+ // Stripe saves amount in cents
+ invoiceAmount: Utils.createDecimal(billingInvoice.amount).div(100),
+ invoiceNumber: billingInvoice.number,
+ invoiceStatus: billingInvoice.status,
}
);
}

MODIFY
src/notification/NotificationHandler.ts
src/notification/NotificationHandler.ts
import User, { UserRole } from '../types/User';
import UserNotifications, { AccountVerificationNotification, AdminAccountVerificationNotification, BillingInvoiceSynchronizationFailedNotification, BillingNewInvoiceNotification, BillingUserSynchronizationFailedNotification, CarCatalogSynchronizationFailedNotification, ChargingStationRegisteredNotification, ChargingStationStatusErrorNotification, ComputeAndApplyChargingProfilesFailedNotification, EndOfChargeNotification, EndOfSessionNotification, EndOfSignedSessionNotification, EndUserErrorNotification, NewRegisteredUserNotification, Notification, NotificationSeverity, NotificationSource, OCPIPatchChargingStationsStatusesErrorNotification, OICPPatchChargingStationsErrorNotification, OICPPatchChargingStationsStatusesErrorNotification, OfflineChargingStationNotification, OptimalChargeReachedNotification, PreparingSessionNotStartedNotification, RequestPasswordNotification, SessionNotStartedNotification, SmtpErrorNotification, TransactionStartedNotification, UnknownUserBadgedNotification, UserAccountInactivityNotification, UserAccountStatusChangedNotification, UserNotificationKeys, VerificationEmailNotification } from '../types/UserNotifications';
-import { BillingInvoiceStatus } from '../types/Billing';
import ChargingStation from '../types/ChargingStation';
import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants';
@@ -1073,7 +1072,7 @@ export default class NotificationHandler {
if (!hasBeenNotified) {
// Enabled?
if (sourceData.user.notificationsActive && sourceData.user.notifications.sendBillingNewInvoice) {
- if (sourceData.invoice?.status) {
+ if (sourceData.invoiceStatus) {
await NotificationHandler.saveNotification(
tenantID, notificationSource.channel, notificationID, ServerAction.BILLING_NEW_INVOICE, { user });
// Send

MODIFY
src/notification/remote-push-notification/RemotePushNotificationTask.ts
src/notification/remote-push-notification/RemotePushNotificationTask.ts
@@ -359,12 +359,20 @@ export default class RemotePushNotificationTask implements NotificationTask {
// Set the locale
const i18nManager = I18nManager.getInstanceForLocale(user.locale);
// Get Message Text
- const title = i18nManager.translate('notifications.billingNewInvoice.title');
- const body = i18nManager.translate('notifications.billingNewInvoice.body',
- { invoiceNumber: data.invoice.number });
+ let title = '';
+ let body = '';
+ if (data.invoiceStatus === 'open') {
+ title = i18nManager.translate('notifications.billingNewInvoiceOpen.title');
+ body = i18nManager.translate('notifications.billingNewInvoiceOpen.body',
+ { invoiceNumber: data.invoiceNumber, amount: data.invoiceAmount });
+ } else if (data.invoiceStatus === 'paid') {
+ title = i18nManager.translate('notifications.billingNewInvoicePaid.title');
+ body = i18nManager.translate('notifications.billingNewInvoicePaid.body',
+ { invoiceNumber: data.invoiceNumber, amount: data.invoiceAmount });
+ }
// Send Notification
return this.sendRemotePushNotificationToUser(tenant, UserNotificationType.BILLING_NEW_INVOICE,
- title, body, user, { 'invoiceNumber': data.invoice.number.toString() }, severity);
+ title, body, user, { 'invoiceNumber': data.invoiceNumber.toString() }, severity);
}
public async sendBillingNewInvoicePaid(data: BillingNewInvoiceNotification, user: User, tenant: Tenant, severity: NotificationSeverity): Promise<void> {
@@ -373,10 +381,10 @@ export default class RemotePushNotificationTask implements NotificationTask {
// Get Message Text
const title = i18nManager.translate('notifications.billingNewInvoicePaid.title');
const body = i18nManager.translate('notifications.billingNewInvoicePaid.body',
- { invoiceNumber: data.invoice.number });
+ { invoiceNumber: data.invoiceNumber });
// Send Notification
return this.sendRemotePushNotificationToUser(tenant, UserNotificationType.BILLING_NEW_INVOICE,
- title, body, user, { 'invoiceNumber': data.invoice.number.toString() }, severity);
+ title, body, user, { 'invoiceNumber': data.invoiceNumber.toString() }, severity);
}
public async sendBillingNewInvoiceOpen(data: BillingNewInvoiceNotification, user: User, tenant: Tenant, severity: NotificationSeverity): Promise<void> {
@@ -385,10 +393,10 @@ export default class RemotePushNotificationTask implements NotificationTask {
// Get Message Text
const title = i18nManager.translate('notifications.billingNewInvoiceOpen.title');
const body = i18nManager.translate('notifications.billingNewInvoiceOpen.body',
- { invoiceNumber: data.invoice.number });
+ { invoiceNumber: data.invoiceNumber });
// Send Notification
return this.sendRemotePushNotificationToUser(tenant, UserNotificationType.BILLING_NEW_INVOICE,
- title, body, user, { 'invoiceNumber': data.invoice.number.toString() }, severity);
+ title, body, user, { 'invoiceNumber': data.invoiceNumber.toString() }, severity);
}
public async sendAccountVerificationNotification(data: AccountVerificationNotification, user: User, tenant: Tenant, severity: NotificationSeverity): Promise<void> {

MODIFY
src/types/UserNotifications.ts
src/types/UserNotifications.ts
@@ -2,6 +2,7 @@ import User, { UserStatus } from './User';
import { BillingInvoice } from './Billing';
import ChargingStation from './ChargingStation';
+import Decimal from 'decimal.js';
import NotificationTask from '../notification/NotificationTask';
import { SMTPError } from 'emailjs';
@@ -266,9 +267,11 @@ export interface BillingNewInvoiceNotification extends BaseNotification {
evseDashboardURL: string;
evseDashboardInvoiceURL: string;
user: User;
- invoice: BillingInvoice;
invoiceDownloadUrl: string;
payInvoiceUrl: string;
+ invoiceNumber: string;
+ invoiceAmount: Decimal;
+ invoiceStatus: string;
}
export interface CarCatalogSynchronizationFailedNotification extends BaseNotification {

modified i18n newInvoices
added price to email notification
modified billingNewInvoiceNotification to add specific values needed for notifications