Trimitere in sistemul eFactura

Descriere - Trimitere in sistemul eFactura

  • Realizeaza trimiterea facturilor in sistemul eFactura

  • Factura trimisa trebuie sa fie deja validata

Model de utilizare API

  • Asa cum este explicat in zona de Informatii generale utilizare API orice apel catre API se face catre un URL de baza la care apoi se adauga endpoint-ul respectivei operatii

Notă

  • Verb: POST

  • Endpoint: /{clientEid}/invoices/efactura/submitted

  • Request parameter: {clientEid}

  • Request body: {data_body}

  • Returns: Success

Atenționare

  • A se observa parametru {clientEid} si tipul acestuia (path variable)

Model de request body

  • Request body-ul se creaza in prealabil, inaintea apelului catre API

  • Acesta va contine doar identificatorul Keez al facturii care se va anula: externalId

data_body = {
    'externalId': '{ID_EXTERN_FACTURA}'
}

Mod de folosire - Wrapper - Trimitere eFactura

  • Daca se foloseste wrapper -ul scris in Python se utilizeaza astfel:
    1. Se preia token-ul pe baza parametrilor specifici

    2. Se apeleaza metoda specifica acestui request POST

    token_url = 'https://staging.keez.ro/idp/connect/token'
    api_url = f'https://{ENVIRONMENT}.keez.ro/api/v1.0/public-api'
    
    client_eid = '{RECEIVED_CLIENT_EID}'
    application_id = '{RECEIVED_APPLICATION_ID}'
    secret = '{RECEIVED_SECRET}'
    
    api = KeezPublicApi(app=application, secret=secret, token_url=token_url, api_url=api_url)
    
    invoiceExternalId = '{ID_EXTERN_FACTURA}'
    
    result = api.submit_e_factura(client_eid, invoiceExternalId)
    

Mod de folosire - Fara Wrapper - Trimitere eFactura

class InvoiceService:
    def __init__(self):
        token = TokenService()
        self.auth_token = token.generate_token()
        self.token = f'{self.auth_token.get("token_type")} {self.auth_token.get("access_token")}'

        self.client_eid = token.client_eid
        self.api_endpoint = token.api_endpoint

    def submitInvoiceToEFactura(self):
        invoice_url = f'{self.api_endpoint}/{self.client_eid}/invoices/efactura/submitted'

        data_body = {
            'externalId': '{ID_EXTERN_FACTURA}'
        }

        _req = requests.post(url=invoice_url, headers={'Content-Type': 'application/json', 'Authorization': self.token}, json=data_body)
        return _req.json()


if __name__ == '__main__':
    service = InvoiceService()
    invoice = service.submitInvoiceToEFactura()
    print(invoice)

Notă

Clasa TokenService() se gaseste la sectiunea Autorizarea: Vezi Autorizarea