Fixed invoices not deleted
MODIFY
src/integration/billing/BillingIntegration.ts
src/integration/billing/BillingIntegration.ts
@@ -243,6 +243,20 @@ export default abstract class BillingIntegration<T extends BillingSetting> {
});
continue;
}
+ // Delete in e-Mobility
+ if (!invoiceInBilling && invoice) {
+ await BillingStorage.deleteInvoiceByInvoiceID(tenantID, invoiceIDInBilling);
+ actionsDone.inSuccess++;
+ Logging.logDebug({
+ tenantID: tenantID,
+ user: user,
+ source: Constants.CENTRAL_SERVER,
+ action: ServerAction.BILLING_SYNCHRONIZE_INVOICES,
+ module: MODULE_NAME, method: 'synchronizeInvoices',
+ message: `Billing invoice with ID '${invoiceIDInBilling}' has been deleted in e-Mobility`
+ });
+ continue;
+ }
// Create / Update
let userInInvoice: User;
if (invoice) {
@@ -302,23 +316,6 @@ export default abstract class BillingIntegration<T extends BillingSetting> {
detailedMessages: { invoiceInBilling }
});
} catch (error) {
- if (error.statusCode === StatusCodes.NOT_FOUND) {
- const invoice = await BillingStorage.getInvoiceByBillingInvoiceID(tenantID, invoiceIDInBilling);
- // Delete in e-Mobility
- if (invoice) {
- await BillingStorage.deleteInvoiceByInvoiceID(tenantID, invoiceIDInBilling);
- actionsDone.inSuccess++;
- Logging.logDebug({
- tenantID: tenantID,
- user: user,
- source: Constants.CENTRAL_SERVER,
- action: ServerAction.BILLING_SYNCHRONIZE_INVOICES,
- module: MODULE_NAME, method: 'synchronizeInvoices',
- message: `Billing invoice with ID '${invoiceIDInBilling}' has been deleted in e-Mobility`
- });
- continue;
- }
- } else {
actionsDone.inError++;
Logging.logError({
tenantID: tenantID,
@@ -332,7 +329,6 @@ export default abstract class BillingIntegration<T extends BillingSetting> {
}
}
}
- }
// Log
Utils.logActionsResponse(tenantID, ServerAction.BILLING_SYNCHRONIZE_INVOICES,
MODULE_NAME, 'synchronizeInvoices', actionsDone,

MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -164,8 +164,8 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
// Check Stripe
await this.checkConnection();
// Get Invoice
+ try {
const stripeInvoice = await this.stripe.invoices.retrieve(id);
- if (stripeInvoice) {
return {
invoiceID: stripeInvoice.id,
customerID: stripeInvoice.customer.toString(),
@@ -177,9 +177,10 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
nbrOfItems: stripeInvoice.lines.total_count,
downloadUrl: stripeInvoice.invoice_pdf
} as BillingInvoice;
- }
+ } catch (e) {
return null;
}
+ }
public async getUpdatedUserIDsInBilling(): Promise<string[]> {
const createdSince = this.settings.usersLastSynchronizedOn ? `${moment(this.settings.usersLastSynchronizedOn).unix()}` : '0';

Fixed invoices not deleted