Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AFIP WebService simulator PoC #108

Open
reingart opened this issue Mar 19, 2023 · 1 comment
Open

AFIP WebService simulator PoC #108

reingart opened this issue Mar 19, 2023 · 1 comment
Labels
good first issue Good for newcomers

Comments

@reingart
Copy link
Member

reingart commented Mar 19, 2023

Fake implementation for testing, mimicking government servers (WSDL SOAP based)

This idea should implement a standalone webserver with a SOAP XML interface, so new clients could use it to test implementations without using real world AFIP servers.

Also, to avoid flaky tests or recording XML requests and responses, this could be used in integration & end to end tests.

See server.py for an example using the SOAP library used in this project.

Major AFIP Web Services to simulate:

  • WSAA (authentication and authorization)
  • WSFEv1 (simple electronic invoice, for most customers)
  • WSMTXCA (electronic invoice with details for large tax contributors)
  • WSFEXv1 (electronic invoice for foreign trade)
  • WSBFEv1 (electronic invoice for tax bonous)

Methods to implement:

  • Query and retrieve last invoice number (CompUltConsultar)
  • Query and retrieve an invoice (CompConsultar)
  • Authorize an invoice (SolicitarCAE)

This could be done also with django or flask.
Example web2py-app for a Proof of Concept

For a quick initial ticket PoC, a minimal webservice using python http.server to respond with a basic XML response for the URL http://localhost/wsfev1/service.asmx.

Sample XML response for POST with header SOAPAction: "http://ar.gov.afip.dif.FEV1/FECompUltimoAutorizado":

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Header>
    <FEHeaderInfo xmlns="http://ar.gov.afip.dif.FEV1/"><ambiente>HomologacionExterno - efa</ambiente><fecha>2023-03-19T18:37:22.5736761-03:00</fecha><id>5.1.0.0</id>
   </FEHeaderInfo>
  </soap:Header>
  <soap:Body>
    <FECompUltimoAutorizadoResponse xmlns="http://ar.gov.afip.dif.FEV1/">
      <FECompUltimoAutorizadoResult>
        <PtoVta>3</PtoVta>
        <CbteTipo>3</CbteTipo>
        <CbteNro>1079</CbteNro>
      </FECompUltimoAutorizadoResult>
    </FECompUltimoAutorizadoResponse>
  </soap:Body>
</soap:Envelope>

Sample XML response for POST with header SOAPAction: "http://ar.gov.afip.dif.FEV1/FECAESolicitar":

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Header>
    <FEHeaderInfo xmlns="http://ar.gov.afip.dif.FEV1/"><ambiente>HomologacionExterno - efa</ambiente><fecha>2023-03-19T18:37:22.6518011-03:00</fecha><id>5.1.0.0</id></FEHeaderInfo>
  </soap:Header>
  <soap:Body>
    <FECAESolicitarResponse xmlns="http://ar.gov.afip.dif.FEV1/">
      <FECAESolicitarResult>
        <FeCabResp>
          <Cuit>20267565393</Cuit>
          <PtoVta>3</PtoVta>
          <CbteTipo>3</CbteTipo>
          <FchProceso>20230319183722</FchProceso>
          <CantReg>1</CantReg>
          <Resultado>A</Resultado>
          <Reproceso>N</Reproceso>
      </FeCabResp>
      <FeDetResp>
        <FECAEDetResponse>
          <Concepto>3</Concepto>
          <DocTipo>80</DocTipo>
          <DocNro>30500010912</DocNro>
          <CbteDesde>1080</CbteDesde>
          <CbteHasta>1080</CbteHasta>
          <CbteFch>20230319</CbteFch>
          <Resultado>A</Resultado>
          <Observaciones><Obs><Code>10217</Code><Msg>El credito fiscal discriminado en el presente comprobante solo podra ser computado a efectos del Procedimiento permanente de transicion al Regimen General.</Msg></Obs></Observaciones>
          <CAE>73123082701641</CAE><CAEFchVto>20230329</CAEFchVto>
        </FECAEDetResponse>
      </FeDetResp></FECAESolicitarResult>
    </FECAESolicitarResponse>
  </soap:Body>
</soap:Envelope>

For more info about http module: https://pymotw.com/3/http.server/

@reingart reingart added the good first issue Good for newcomers label Mar 19, 2023
@reingart reingart changed the title AFIP WebService simulator AFIP WebService simulator PoC Mar 19, 2023
@Aadiarya0
Copy link

To identify potential issues in the provided SOAP response, here are some common areas to investigate:
Check if the SOAP Envelope is properly formed: The soap:Envelope should have a matching opening and closing tag.
Namespace declarations: Ensure the namespaces (xmlns) are accurate and match the service specifications.
PtoVta (Point of Sale): Ensure the point of sale (3) is valid and correctly configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants