diff --git a/README.md b/README.md index 840c38c..b4b7741 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ import ( func main() { // Software is the information regarding the system used to report the invoices - software := NewSoftware( + software := nav.NewSoftware( tax.Identity{Country: l10n.ES.Tax(), Code: cbc.Code("B12345678")}, "Invopop", "ONLINE_SERVICE", @@ -71,43 +71,77 @@ func main() { ) // User is all the data obtained from the technical user that it is needed to report the invoices - user := NewUser( + user := nav.NewUser( "username", "password", "signature_key", "exchange_key", - "taxID" + "taxID", ) // Create a new client with the user and software data and choose if you want to issue the invoices in the testing or production environment - navClient := NewNav(user, software, InTesting()) + navClient := nav.NewNav(user, software, nav.InTesting()) //We load the invoice - inv, err := os.ReadFile("test/data/out/output.xml") + invoice, err := os.ReadFile("test/data/out/output.xml") if err != nil { panic(err) } // Report the invoice - transactionId, err := navClient.ReportInvoice(invoice) + transactionId, err := navClient.ReportInvoice(invoice, "CREATE") if err != nil { panic(err) } - // Once the invoice is reported, you can check the status - // If you check the status too early you would get a status of PROCESSING, which means that you should try again later to query the status - resultsList, err := navClient.GetTransactionStatus(transactionId) + // Keep the transaction ID for the status query +} +``` + +#### Invoice Status +Once an invoice is reported, you can query the status of the invoice at any time. + +```go +package main + +import ( + "os" + + "github.com/invopop/gobl" + nav "github.com/invopop/gobl.hu-nav" +) + +func main(){ + + // To query the status of an invoice, you need the transaction ID, which is returned by the ReportInvoice function. + transactionId := "4Q220PNVP43MOU5G" + + // Create a new client with the user and software data and choose if you want to issue the invoices in the testing or production environment + navClient := nav.NewNav(user, software, nav.InTesting()) - //The output contains the status and a list of technical and business validation messages. To visualize the output, you can create a XML output: - out, err := nav.BytesIndent(resultsList) + // Query the status of the invoice + resultsList, err := navClient.GetTransactionStatus(transactionId) if err != nil { panic(err) } - // TODO: do something with the output + // resultsList is a list of ProcessingResult, which contains the status of each invoice in the transaction + // You can access the status of each invoice by iterating through the list + for _, r := range resultsList { + fmt.Println(r.InvoiceStatus) + } + + // If you want to see the detailed messages, you can access the TechnicalValidationMessages and BusinessValidationMessages fields, that are also lists + for _, r := range resultsList { + for _, m := range r.TechnicalValidationMessages { + fmt.Println(m.Message) + } + for _, m := range r.BusinessValidationMessages { + fmt.Println(m.Message) + } + } } ``` - ### Command Line #### Conversion diff --git a/internal/gateways/status.go b/internal/gateways/status.go index 9330e87..d5eb7e8 100644 --- a/internal/gateways/status.go +++ b/internal/gateways/status.go @@ -38,13 +38,13 @@ type ProcessingResults struct { // ProcessingResult contains the status of an invoice in a transaction // It also contains the messages from the technical and business validations type ProcessingResult struct { - Index string `xml:"index"` - BatchIndex string `xml:"batchIndex,omitempty"` - InvoiceStatus string `xml:"invoiceStatus"` - TechnicalValidationMessages *TechnicalValidationMessages `xml:"technicalValidationMessages,omitempty"` - BusinessValidationMessages *BusinessValidationMessages `xml:"businessValidationMessages,omitempty"` - CompressedContentIndicator bool `xml:"compressedContentIndicator"` - OriginalRequest string `xml:"originalRequest,omitempty"` + Index string `xml:"index"` + BatchIndex string `xml:"batchIndex,omitempty"` + InvoiceStatus string `xml:"invoiceStatus"` + TechnicalValidationMessages []*TechnicalValidationMessages `xml:"technicalValidationMessages,omitempty"` + BusinessValidationMessages []*BusinessValidationMessages `xml:"businessValidationMessages,omitempty"` + CompressedContentIndicator bool `xml:"compressedContentIndicator"` + OriginalRequest string `xml:"originalRequest,omitempty"` } // TechnicalValidationMessages are the result of the technical validation diff --git a/internal/gateways/status_test.go b/internal/gateways/status_test.go index d90f43a..3536f59 100644 --- a/internal/gateways/status_test.go +++ b/internal/gateways/status_test.go @@ -39,7 +39,7 @@ func TestQueryTransactionStatus(t *testing.T) { client := New(user, software, Environment("testing")) - result, err := client.GetStatus("4P2PEVFLLNKYTV3I") + result, err := client.GetStatus("4Q220PNVP43MOU5G") // Assert the results assert.NoError(t, err) @@ -53,6 +53,7 @@ func TestQueryTransactionStatus(t *testing.T) { } fmt.Println(string(xmlData)) + fmt.Println(result[0].BusinessValidationMessages[1].Message) for _, r := range result { assert.Equal(t, "1", r.Index)