Skip to content

Commit

Permalink
Changing status handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Menendez6 committed Sep 24, 2024
1 parent b775874 commit dd73881
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
60 changes: 47 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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

Expand Down
14 changes: 7 additions & 7 deletions internal/gateways/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion internal/gateways/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit dd73881

Please sign in to comment.