Skip to main content

Spanish Tax Agency Electronic Office (AEAT) Integration

Project description

Master

https://travis-ci.org/initios/aeat-web-services.svg?branch=master https://coveralls.io/repos/github/initios/aeat-web-services/badge.svg?branch=master

Spanish Tax Agency Electronic Office (AEAT) Integration.

Make requests AEAT Web Services and sign your connection and xml using your certificate.


Integración con la Agencia Estatal de Administración Tributaria Española

Realiza peticiones a los Servicios Web de AEAT y firma tu conexión y mensajes XML utilizando tu certificado.

Usage (English)

Example for requesting a list of ENS’s.

Initialize a Config object with the desired preconfigured service and if you want to request AEAT test or production endpoints (test_mode). Finally initialize controller with the config and the desired certificate and make the request with your payload.

If you need more control just build the controller by hand, see build_from_config method for inspiration.

import aeat

config = aeat.Config('ens_query', test_mode=True)
ctrl = aeat.Controller.build_from_config(config, 'cert.pem', 'key.pem')
payload = {'TraModAtBorHEA76': '1', 'ExpDatOfArr': '20110809',  'ConRefNum': '9294408'}
result = ctrl.request(payload)

assert result.valid, f'Error requesting aeat: {result.error}'
assert result.data is not None

Usage (Spanish)

Ejemplo de consulta de ENSs.

Inicializa el objecto Config con el servicio preconfigurado y si quieres usar los endpoints de AEAT de test o de producción (test_mode). Por último inicializa el controlador con la config y el certificado que gustes y realiza la petición pasándole los datos que necesites.

Si necesitas un mayor control simplemente construye el controlador a mano, puedes inspirarte en el método build_from_config.

import aeat

config = aeat.Config('ens_query', test_mode=True)
ctrl = aeat.Controller.build_from_config(config, 'cert.pem', 'key.pem')
payload = {'TraModAtBorHEA76': '1', 'ExpDatOfArr': '20110809',  'ConRefNum': '9294408'}
result = ctrl.request(payload)

assert result.valid, f'Error requesting aeat: {result.error}'
assert result.data is not None

Django Rest Framework

Several AEAT Validators and Serializers are provided.

  • Validators: Validate input data to send to AEAT

  • Serializers: Serialize AEAT request

from aeat.rest_framework import validators

validator = validators.ENSPresentationValidator(data=payload)
assert validator.is_valid(raise_exception=True)

# Send the request to AEAT
import aeat

config = aeat.Config(service_name, test_mode=settings.AEAT_TEST_MODE)
ctrl = aeat.Controller.build_from_config(config, cert_path, key_path)
result = ctrl.request(validator.data)
assert result.valid

# Parse the response
from aeat.rest_framework import serializers

serializer = serializers.get_class_for_aeat_response(data=result.data)
assert serializer.is_valid(raise_exception=False)
assert {'mrn': 'XXXX'} == serializer.data
assert not serializer.is_error

Prerequisites

Install xmlsec prerequisites. Check https://github.com/mehcode/python-xmlsec

Install

$ pip install aeat-web-services

Develop

$ python setup.py develop
$ pip install -r requirements_test.txt

Test

$ pip install tox
$ tox

Releases

https://github.com/initios/aeat-web-services/releases

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aeat-web-services-2.0.0.dev1.tar.gz (69.5 kB view details)

Uploaded Source

Built Distribution

aeat_web_services-2.0.0.dev1-py2.py3-none-any.whl (17.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file aeat-web-services-2.0.0.dev1.tar.gz.

File metadata

File hashes

Hashes for aeat-web-services-2.0.0.dev1.tar.gz
Algorithm Hash digest
SHA256 2658f325eea4b29e8d6a14956d18ca2c0292a668852803f469d3a9001d6e1e47
MD5 0c61c56c816c9a06435adc116ddb654b
BLAKE2b-256 28d36132079ff65a0ba3d781d669cc47f7b214d3c06cdcbb434e726cb8eb50e2

See more details on using hashes here.

Provenance

File details

Details for the file aeat_web_services-2.0.0.dev1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for aeat_web_services-2.0.0.dev1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a56ffb24b6048820dc75074cac11c2fa72100f1eb8df5a21c13c184fd9421172
MD5 29bbaf5a3acb8843a35ec00f7e2b9747
BLAKE2b-256 b63c59e7ea2163eda15748463477632db04d11febbd8e59f389d8d11738c21e2

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page