periodic billing - update Transaction Billing Data
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -20,6 +20,7 @@ import { ServerAction } from '../../../types/Server';
import Stripe from 'stripe';
import StripeHelpers from './StripeHelpers';
import Transaction from '../../../types/Transaction';
+import TransactionStorage from '../../../storage/mongodb/TransactionStorage';
import User from '../../../types/User';
import UserStorage from '../../../storage/mongodb/UserStorage';
import Utils from '../../../utils/Utils';
@@ -410,9 +411,36 @@ export default class StripeBillingIntegration extends BillingIntegration {
await StripeHelpers.updateInvoiceAdditionalData(this.tenantID, billingInvoice, operationResult);
// Send a notification to the user
void this.sendInvoiceNotification(billingInvoice);
+ if (FeatureToggles.isFeatureActive(Feature.BILLING_ASYNC_UPDATE_TRANSACTION)) {
+ await this._updateTransactionsBillingData(billingInvoice);
+ }
return billingInvoice;
}
+ private async _updateTransactionsBillingData(billingInvoice: BillingInvoice): Promise<void> {
+ await Promise.all(billingInvoice.sessions.map(async (session) => {
+ const transactionID = session.transactionID;
+ try {
+ const transaction = await TransactionStorage.getTransaction(this.tenantID, Number(transactionID));
+ // Update Billing Data
+ transaction.billingData.stop.invoiceStatus = billingInvoice.status;
+ transaction.billingData.stop.invoiceNumber = billingInvoice.number;
+ transaction.billingData.lastUpdate = new Date();
+ // Save
+ await TransactionStorage.saveTransaction(this.tenantID, transaction);
+ } catch (error) {
+ // catch stripe errors and send the information back to the client
+ await Logging.logError({
+ tenantID: this.tenantID,
+ action: ServerAction.BILLING_PERFORM_OPERATIONS,
+ module: MODULE_NAME, method: '_updateTransactionsBillingData',
+ message: 'Failed to update transaction billing data',
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
+ }
+ }));
+ }
+
private async _chargeStripeInvoice(invoiceID: string): Promise<BillingOperationResult> {
try {
// Fetch the invoice from stripe (do NOT TRUST the local copy)

MODIFY
src/utils/FeatureToggles.ts
src/utils/FeatureToggles.ts
@@ -10,6 +10,7 @@ export enum Feature {
BILLING_ITEM_WITH_PARKING_TIME,
BILLING_ITEM_WITH_START_DATE,
BILLING_ASYNC_BILL_TRANSACTION,
+ BILLING_ASYNC_UPDATE_TRANSACTION,
}
export default class FeatureToggles {
@@ -23,6 +24,7 @@ export default class FeatureToggles {
// Feature.BILLING_ITEM_WITH_PARKING_TIME,
Feature.BILLING_ITEM_WITH_START_DATE,
Feature.BILLING_ASYNC_BILL_TRANSACTION,
+ Feature.BILLING_ASYNC_UPDATE_TRANSACTION,
];
// Check whether the feature is active or not!

periodic billing - update Transaction Billing Data