Skip to content

A middleware that eliminates the need to manually build XML and lets developers work with AFIP as if it were a REST API

License

Notifications You must be signed in to change notification settings

NehuenLian/AFRelay

Repository files navigation

AFRelay: Billing Microservice with integration to the Argentine Tax Agency

CI coverage

AFRelay is a middleware that eliminates the need to manually build XML and lets developers work with AFIP as if it were a REST API.
Total control.: Free. No SaaS. No closed-source infrastructure.
Without requiring the developer to get involved with SOAP.

  • Async network I/O keeps the event loop free while waiting for slow external services.
  • Automatically renews the access ticket each 11 hours and when the service starts.
  • Does not automatically handle errors or raise exceptions, only returns information as JSON.

Requirements

To use this service, you need a fiscal key and the corresponding certificates to authenticate with AFIP/ARCA web services.
The steps to obtain the certificates are available on the official website: https://www.arca.gob.ar/ws/documentacion/certificados.asp

Once authenticated, the authentication web service will provide two credentials:

  • A private key with the extension ".key"
  • An X.509 certificate with the extension ".pem"

Quick start with Docker

  1. Clone the repository
git clone https://github.com/NehuenLian/AFRelay
  1. Go to repository
cd AFRelay
  1. Start the container
docker compose up
  1. Health Check readiness:
curl -i http://localhost:8000/health/readiness
  1. See OpenAPI docs
http://localhost:8000/docs

Quick start without Docker

  1. Clone the repository
git clone https://github.com/NehuenLian/AFRelay
  1. Go to repository
cd AFRelay
  1. Install dependencies
pip install -r requirements-dev.txt
  1. Startup FastAPI
uvicorn service.api.app:app --reload
  1. Health Check readiness:
curl -i http://127.0.0.1:8000/health/readiness
  1. See OpenAPI docs
http://localhost:8000/docs

Run tests and see coverage

  • Full tests:

    pytest -v --cov
  • Unit tests:

    pytest tests/unit -v --cov
  • Integration tests:

    pytest tests/integration -v --cov

Additional Considerations

  • Access ticket persistence: If the container or server where the service is deployed goes down, there is no problem with access tickets (loginTicketResponse.xml). On restart, if a TA (Access Ticket) comes in and the files are missing, the service will detect it and automatically generate a new ticket.

  • Flexible deployment: Using Docker is optional. The service can run directly or inside any Python environment, as long as input and output file formats are respected. Protecting credentials (tokens, certificates) is the responsibility of the user or system administrator.

Architecture

AFRelay
├── config/
├── host_certs/
├── host_xml/
├── service/
│   ├── api/
│   ├── app_certs/
│   ├── controllers/
│   ├── crypto/
│   ├── payload_builder/
│   ├── soap_client/
│   ├── time/
│   ├── utils/
│   └── xml_management/
├── tests/
├── requirements-dev.txt
└── requirements.txt

License

This project is licensed under the MIT license (a permissive open-source license).

You are free to use, copy, modify, and distribute the software, always including the copyright notice and without any warranties.


Author: Nehuen Lián https://github.com/NehuenLian

About

A middleware that eliminates the need to manually build XML and lets developers work with AFIP as if it were a REST API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published