Reviewers (PMD-3368):

User Story

As a PortaBilling System Administrator of a CSP, I need to automatically transmit tax invoice data of post-paid customers to the Malawi Revenue Authority's (MRA) Electronic Invoicing System (EIS) in real-time when invoices are generated, so that CSP complies with mandatory VAT e-invoicing regulations, avoids penalties for non-compliance, and ensures uninterrupted business operations.

As a CSP customer, I want to scan an MRA-approved QR code on my invoice that confirms the tax amounts and invoice validity, so that I can be confident the CSP has correctly declared and paid taxes.

Example of Use

On 2025-02-01 at 00:15:00, PortaBilling completes the billing cycle for January 2025 and generates invoice INV-2025-000456 for customer "Blantyre Medical Supplies Ltd" (Customer ID 102345) totaling MWK 1,250,000.00 (including MWK 175,206.61 VAT at 16.5%). The EIS integration service automatically transmits this invoice details to MRA EIS via the API. MRA validates the invoice and returns an invoice validation URL (e.g. "https://eservices.mra.mw/doc/v/?vc=90241313200014&c=fdd8d5ccc06a49d6a1efbf7e3896f0b4") which must be converted to a QR code by the EIS integration service to appear at the bottom of invoice.

Current Solution

For pre-paid customers invoicing is done via custom built (by CSP) SAP integration and agreed by CSP to remain unchanged.

For post-paid customers, a 3rd party application currently collects invoices from PortaBilling, parses them, and reports the invoice data to the MRA. The application then stamps the invoices and saves them in a remote directory (outside of PortaBilling) so invoices are ready to be delivered to end customers. 

This process of reporting to the MRA and stamping invoices should be decommissioned in favor of using the EIS system and an MRA-approved QR code instead of a stamp.

Additional information:

  • Taxation is disabled in the system
  • VAT and excise included into the prices
  • There is a princeXML based invoice template (prepared by PortaOne in scope of PMD-2367), which back-calculates VAT and excise from the xDRs and shows charges summaries and aging details 

Business Model

The Malawi Revenue Authority has mandated that all VAT-registered taxpayers must use the Electronic Invoicing System (EIS) to transmit detailed sales transaction data in real-time. This replaces the legacy Electronic Fiscal Devices (EFDs) that transmitted summarized Z-reports once daily via FTP. Non-compliance results in penalties up to MWK 5,000,000 and potential business license suspension.

Financial Flow

  • VAT Collection: CSP collects 16.5% VAT on all taxable services (voice calls, data bundles, messaging, subscriptions). For a typical monthly billing cycle with MWK 500,000,000 in taxable revenue, VAT collected equals MWK 82,500,000.
  • Remittance Deadline: VAT must be remitted to MRA by the 25th of the next month. Integration ensures accurate tracking and reporting.
  • Penalty Avoidance: Late or incorrect submissions incur MWK 300,000 penalty plus 2% interest per month on outstanding VAT.

Technology (systems involved)

  • PortaBilling: Core billing system with customer records, xDRs, and invoice generation
  • MRA EIS API: REST API at https://eis-api.mra.mw/ accepting JSON payloads over HTTPS
  • MRA EIS Portal: https://eis-portal.mra.mw/ for terminal registration and configuration management

High-Level Scope of Integration Flows

  • Terminal Onboarding: One-time activation using Terminal Activation Code (TAC) obtained from MRA portal. TAC is exchanged for terminal configuration including API tokens.
  • Configuration Sync: Daily call to "Get Latest Configuration" endpoint to retrieve current tax rates and parameters.
  • Invoice Transmission: Real-time POST to sale transaction endpoint with invoice details; receive invoice validation URL in response.

Key MRA Data Objects

FieldExample Value
terminalId"3a6d3703-1c39-41e8-98ce-b38d9574540d"
invoiceDateTime2025-05-28T06:57:11.368Z
invoiceNumberINV-2025-000456 
sellerTIN5000123456 (The Taxpayer Identification Number of the seller)
buyerTIN1000234567 (Taxpayer Identification Number)
buyerNameBlantyre Medical Supplies Ltd
invoiceTotal1250000.00 (MWK)
totalVAT175206.61 (16.5% VAT)
invoiceLineItems[]Array of line items with productCode, description, quantity, unitPrice, taxRateId, ...
validationURLhttps://eservices.mra.mw/doc/v/?vc=90241313200014&c=fdd8d5ccc06a49d6a1efbf7e3896f0b4 (returned by MRA)

Stakeholders and Their Benefits

StakeholderBenefit
CSP Finance TeamInstant compliance status visibility
CSP ManagementZero compliance risk; avoided penalties of MWK 5,000,000+; uninterrupted operations
CSP CustomersValid QR-coded invoices for VAT claims; instant invoice verification via MRA portal
CSP PortaBilling AdministratorAutomated workflow; centralized configuration; comprehensive audit logs
Malawi Revenue AuthorityReal-time tax data; reduced fraud; improved compliance monitoring

Use Cases

Use Case #1: Terminal Onboarding and Activation

Role: PortaBilling System Administrator

Preconditions:

  • CSP has registered as a taxpayer with MRA (TIN: 5000123456)
  • CSP has applied for EIS terminal via MRA portal and received Terminal Activation Code: TAC-2025-CSP-00001
  • PortaBilling system is running on server pb.csp.mw
  • EIS integration service is deployed and interconnected with PortaBilling and MRA API
  • Administrator "admin@csp.mw" has "EIS Configuration" permission in EIS integration service
  • EIS integration service is certified by MRA with Product ID: PO-EIS-2025-001, Version: 1.0.0
  • Default customer class "business" is configured within PortaBilling with 16.5% custom tax enabled (VAT)

Use Scenario #1.1: Successful Terminal Activation

  1. At 2025-01-10 09:00:00, Administrator logs into EIS integration service UI with credentials "admin@csp.mw"
  2. Administrator navigates to MRA EIS Management panel
  3. Administrator enters Terminal Activation Code "TAC-2025-CSP-00001" and clicks "Activate Terminal"
  4. At 2025-01-10 09:00:03, EIS integration service sends POST request to https://eis-api.mra.mw/api/v1/onboarding/activate-terminal with TAC and Product ID
  5. At 2025-01-10 09:00:05, MRA API returns HTTP 200 with terminal configuration including terminalId "3a6d3703-1c39-41e8-98ce-b38d9574540d", terminalCredentials and configuration
  6. EIS integration service stores terminal id, credentials and configuration in EIS integration service storage
  7. At 2025-01-10 09:00:06, system sends POST to /api/v1/onboarding/terminal-activated-confirmation to acknowledge successful activation
  8. EIS integration service displays success message: "Terminal "3a6d3703-1c39-41e8-98ce-b38d9574540d" activated successfully. EIS integration is now operational."
  9. Administrator navigates to the "business" customer class and enables taxation post-processing action:
    • report to: EIS integration service
    • report model: aggregated per tax code type (also full transaction details might be supported in the future - see operational models section in Peculiarities).

Expected Result:

  • Terminal status in EIS integration service: "Active" with activation timestamp 2025-01-10 09:00:06
  • EIS integration service storage contains: terminal_id="3a6d3703-1c39-41e8-98ce-b38d9574540d", status="active"
  • TAC "TAC-2025-CSP-00001" is marked as consumed and cannot be reused in MRA
  • Audit log entry created: "EIS Terminal activated by admin@csp.mw at 2025-01-10 09:00:06"

Use Scenario #1.2: Terminal Activation with Invalid TAC

  1. At 2025-01-10 09:15:00, Administrator enters incorrect TAC "TAC-2025-CSP-99999" and clicks "Activate Terminal"
  2. At 2025-01-10 09:15:02, EIS integration service sends POST to activation endpoint
  3. At 2025-01-10 09:15:03, MRA API returns HTTP 400 with error code "INVALID_TAC" and message "Terminal Activation Code not found or expired"
  4. EIS integration service displays error: "Activation failed: Terminal Activation Code not found or expired. Please verify the code or request a new one from MRA portal."

Expected Result:

  • Terminal status remains "Not Configured"
  • Error logged: "EIS activation failed - INVALID_TAC - by admin@csp.mw at 2025-01-10 09:15:03"
  • Administrator can retry with correct TAC without system lockout


Use Case #1: Terminal activation preparation

Roles: CSP, EIS, EIS integration service 

Preconditions:

  1. CSP manually registers and activates terminal in the EIS platform
  2. CSP enters terminal secret key, terminal activation code and a terminal jwt token to the EIS integration service
  3. EIS integration service fetches current terminal configuration using EIS API

Use Case #1.1: Successful terminal activation

  1. Continuation of Use Case #1
  2. EIS API returns current terminal configuration including current tax rates (VAT, excise)
  3. EIS integration service shows "service is activated" notification message to the CSP

Use Case #1.2: Failed terminal activation (alternative to #1.1)

  1. Continuation of Use Case #1
  2. EIS API does not respond, or responds with a failure
  3. EIS integration service shows "Service activation failed. Terminal jwt token is invalid, re-check the terminal credentials." notification message to the CSP
  4. CSP starts over the Use Case #1


Use Case #2: Invoice Transmission to MRA EIS

Roles: CSP, EIS, EIS integration service 

Preconditions:

  • EIS integration service is activated with VAT tax 16.5%
  • Customer "Blantyre Medical Supplies Ltd" (Customer ID 102345) has custom field TIN: 1000234567
  • Customer has active account with billing period January 1-31, 2025
  • xDRs totaling MWK 1074793.39 (incl. VAT) have been rated for the period
  • PortaBilling invoice template includes placeholder for the QR code to be inserted (made via layout designer or custom html template)
  • Invoice review functionality is enabled

Use Scenario #2.1: Successful Monthly Invoice Transmission

  1. At the end of billing period PortaBilling regular invoice "11" is generated for Customer ID 102345
  2. PortaBilling sends notification to the CSP with invoice review request
  3. CSP opens invoice "11" and verifies total amount of MWK 1074793.39 (no QR code yet) and approves the invoice
  4. PortaBilling aggregates the invoice xDRs related to the invoice "11" and sends them to the EIS integration service
  5. EIS integration service constructs the JSON payload according to the MRA EIS API specification.
    • TODO: Mapping exercise with stakeholders
  6. EIS integration service back-calculates the 16.5% VAT from xDR and total amount (1074793.39 * 16.5% = 177340.91) 
  7. EIS integration service triggers invoice transmission event
  8. EIS integration service sends POST to https://eis-api.mra.mw/api/sale with signed payload
  9. MRA API returns HTTP 200 with validationURL "https://eservices.mra.mw/doc/v/?vc=90241313200014&c=fdd8d5ccc06a49d6a1efbf7e3896f0b4"
  10. EIS integration service downloads the invoice "11" PDF and puts the encoded validation URL to the previously defined placeholder position
  11. EIS integration service saves the invoice "11" PDF with the encoded QR code to the internal storage
  12. EIS integration service returns successful response code to the PortaBilling
  13. PortaBilling starts processing next invoice according to the scenario #2.1


Use Scenario #2.2: EIS integration service can't locate a QR code placeholder (alternative to #2.1)

  1. Continuation of Use Scenario #2.1 after step 9
  2. EIS integration service downloads the invoice "11" PDF, but can't locate the QR code placeholder
  3. EIS integration service appends new blank PDF page with the QR code in the middle  
  4. EIS integration service logs about failure to put QR code to the invoice "11" on pre-defined location, due to missing placeholder
  5. EIS integration service returns a success code to the PortaBilling
  6. PortaBilling starts processing next invoice according to the scenario #2.1


Use Scenario #2.3: MRA EIS is not responding (alternative to #2.1)

  1. Continuation of Use Scenario #2.1 after step 8
  2. MRA EIS does not respond (returns 408 request timeout code)
  3. EIS integration service returns error code to the PortaBilling
  4. PortaBilling creates notification to the CSP of unsuccessful MRA report delivery for the invoice "11"
  5. PortaBilling schedules retry attempt for the invoice "11" after an hour
  6. PortaBilling starts processing next invoice according to the scenario #2.1

Use Case #3: Defining product codes of the MRA EIS

Roles: CSP, PortaBilling, EIS integration service

TODO: can be created after mapping confirmation from the stakeholders.

preliminary it will be similar to https://wiki.portaone.com/x/wYgtBg 


Use Case #3: EIS Configuration Synchronization

Preconditions:

  • Terminal "3a6d3703-1c39-41e8-98ce-b38d9574540d" is active since 2025-01-10
  • Last configuration sync: 2025-01-31 06:00:00
  • MRA has updated VAT rate from 16.5% to 17.0% effective 2025-02-01
  • EIS integration service scheduled task "EIS Config Sync" runs daily at 06:00

Use Scenario #3.1: Daily Configuration Update with VAT Rate Change

  1. At 2025-02-01 06:00:00, EIS integration service triggers EIS Config Sync task
  2. EIS integration service sends GET request to https://eis-api.mra.mw/api/terminal/config with terminalId header
  3. At 2025-02-01 06:00:02, MRA returns configuration with updated taxRate=17.0
  4. EIS integration service detects change: previous taxRate=16.5, new taxRate=17.0
  5. EIS integration service updates EIS integration service storage with new tax rate and creates audit entry
  6. EIS integration service updates PortaBilling tax configuration: Tax ID 1001 "Malawi VAT" rate changed from 16.5% to 17.0%
  7. Alert email sent to admin@csp.mw and finance@csp.mw: "MRA EIS Configuration Updated: VAT rate changed from 16.5% to 17.0% effective 2025-02-01"

Expected Result:

  • EIS integration service storage tax_rate = 17.0, last_sync = "2025-02-01 06:00:02"
  • PortaBilling Tax ID 1001 updated: rate = 17.0%
  • All invoices generated from "2025-02-01 06:00:02" onward calculate VAT at 17.0%
  • Audit log: "EIS config sync: tax_rate 16.5→17.0 by EIS integration service at 2025-02-01 06:00:02"

Use Case #4: Monitoring and Reporting

Preconditions:

  • EIS integration active for 30+ days with transaction history
  • 2,847 invoices transmitted in January 2025 totaling MWK 487,500,000
  • Administrator "admin@csp.mw" needs to prepare monthly compliance report

Use Scenario #4.1: Generate Monthly EIS Compliance Report

  1. At 2025-02-02 09:00:00, Administrator navigates to Reports → MRA EIS → Monthly Summary
  2. Administrator selects period "January 2025" and clicks "Generate Report"
  3. EIS integration service queries transaction logs for date range 2025-01-01 to 2025-01-31
  4. Report displays: Total invoices: 2,847; Successful transmissions: 2,842 (99.82%); Failed/Pending: 5; Total amount: MWK 487,500,000; VAT collected: MWK 68,478,260.87
  5. Administrator clicks "Export to Excel" for MRA submission records
  6. Administrator clicks "Retry Failed" to attempt resubmission of 5 failed invoices

Expected Result:

  • Report generated in 3 seconds with drill-down capability per invoice
  • Excel export contains columns: Invoice Number, Customer TIN, Customer Name, Amount, VAT, Transmission Date, Validation URL, Status
  • Failed invoices retried; 4 succeed, 1 remains failed (invalid TIN requiring manual correction)
  • Successful transmissions rate updated to 99.96% (2,846/2,847)

Non-functional Requirements

  • Performance:
    • System generates 550 invoices during billing period closure. 
  • Availability:
    • EIS integration service must achieve 99.9% uptime monthly
  • Security:
    • API credentials must not appear in logs; use token masking (show first 4 and last 4 characters only)
  • Audit and Logging:
    • All EIS transactions must be logged with: timestamp, invoice_id, amount, MRA_response_code, duration_ms, user_id
    • Logs must be retained for 7 years per MRA regulations
    • Failed transmission attempts must be logged with full error details for troubleshooting
  • Compliance:
    • Integration must pass MRA API Compliance Certification before production deployment
    • QR codes must be generated according to MRA specifications and be verifiable via MRA portal
    • All amounts must be transmitted in Malawi Kwacha (MWK)
    • PortaBilling Charging categories must map to MRA standardized service codes

Peculiarities

  • Pre-paid billing model reporting to MRA EIS support is out of scope.
  • Invoice voiding and modification after successful upload to the MRA EIS shall be avoided, as these actions are not supported by MRA EIS. All the adjustments can be done in new invoices only.
  • PortaOne Assumptions
    • The only PortaBilling records for EIS integration service to report towards MRA (as Sale Transactions) are PortaBilling Customer Invoices
      • the other transactions are out of integration scope, e.g.
        • PortaBilling charges for customers with disabled invoicing
        • POS charges managed in external system (SAP)
    • CSP has already registered with MRA and has a valid Taxpayer Identification Number (TIN)
    • CSP will apply for Terminal Activation Code via MRA portal before integration begins
    • PortaOne will obtain MRA API Compliance Certification (Product ID and Version) before production deployment
    • Customers' TIN numbers are available in PortaBilling customer records for B2B invoices
    • B2C transactions may avoid supplying buyer information if individual TIN not available
    • As the invoice number reported to the MRA EIS and the invoice number in PortaBilling have different formats, PortaOne assumes it is acceptable to encode the invoice number mapping into the invoice file naming schema after the QR code is generated for debug purposes.
  • Edge Cases
    • Zero-value invoices: Invoices with zero total for charges (e.g., fully discounted) are NOT transmitted to MRA (confirmed here).
    • Backdated invoices: Invoices generated for past periods use the original billing period date, not generation date
    • Multi-currency: MRA EIS does not support multi-currency; Any non-MWK transaction  shall be skipped from reporting (confirmed here). 
  • Regulatory Specifics
    • VAT Rate: Standard VAT rate is 16.5% (as of December 2025); exempt and zero-rated items per Taxation Act schedules
    • Record Retention: All EIS records must be retained for 7 years per VAT Act requirements
    • Certification Requirement: Per MRA API Compliance Certification (Section 7), all third-party POS software must be certified before production use.
  • Operational models: countries regulations vary between countries


The report may be aggregated per line item (using product/service/tax code), or expect all transactions details.