/
sendIncomeClassification.go
45 lines (38 loc) · 1.3 KB
/
sendIncomeClassification.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package mydata
import (
"bytes"
"context"
"encoding/xml"
"errors"
"github.com/buffos/go-aade/mydata/mydataInvoices"
"net/http"
)
// SendIncomeClassification sends the income classification of invoices already submitted to AADE
func (c *Client) SendIncomeClassification(changes *mydataInvoices.IncomeClassificationsDoc) (int, *mydataInvoices.ResponseDoc, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.client.Timeout)
defer cancel()
body, err := xml.Marshal(changes)
//fmt.Println(string(body))
if err != nil {
return InternalErrorCode, nil, ErrorXMLMarshal
}
request, err := http.NewRequestWithContext(ctx, http.MethodPost, c.getURL(URLSendIncomeClassification, nil), bytes.NewBuffer(body))
if err != nil {
return InternalErrorCode, nil, ErrorRequestSendIncomeClassification
}
c.authorize(request)
response, err := c.client.Do(request)
if err != nil {
return InternalErrorCode, nil, ErrorGettingResponse
}
//b, _ := c.responseToString(response)
//fmt.Printf("%s\n", b)
result, err := ParseXMLResponse[mydataInvoices.ResponseDoc](response)
if err != nil {
return InternalErrorCode, nil, errors.Join(ErrorXMLParsingResponse, err)
}
if result.HasErrors() {
return response.StatusCode, result, result.Errors("send invoices")
}
return response.StatusCode, result, nil
}