-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
154 lines (145 loc) · 3.82 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"context"
"fmt"
"net/http"
"github.com/sumup/sii-certification/internal/adapters"
"github.com/sumup/sii-certification/internal/appconfig"
"github.com/sumup/sii-certification/internal/batches"
"github.com/sumup/sii-certification/internal/entities"
)
func Auth(ctx context.Context, s *batches.Gateway) (string, error) {
seed, err := s.GetSeed(ctx)
if err != nil {
return "", fmt.Errorf("errGetSeedReturnsError")
}
token, err := s.GetToken(ctx, seed)
if err != nil {
return "", fmt.Errorf("errGetTokenReturnsError")
}
return token, nil
}
func main() {
appConfig := appconfig.FromEnv()
httpClient := http.DefaultClient
httpAdapter := adapters.NewAdapter(httpClient)
taxAuthorityGateway := batches.NewTaxAuthorityGateway(httpAdapter, appConfig.TaxAuthorityChile)
ctx := context.TODO()
token, err := Auth(ctx, taxAuthorityGateway)
if err != nil {
fmt.Errorf("Authentication error")
return
}
//fmt.Println(token)
batchesMatrix := GenerateBatches()
taxAuthorityGateway.SendMany(ctx, token, batchesMatrix)
}
func GenerateBatches() [][]entities.Batch {
batchesMatrix := make([][]entities.Batch, 0)
// document 48 with amount distinct to zero
batchesMatrix = append(batchesMatrix, []entities.Batch{
{
VatID: "96965568-3", // valid rut
Day: "2023-04-12",
DocumentType: "48",
Channel: "1", // 1 for cnp
Amount: 10000,
NTransactions: 2,
ExternalTrackID: "0",
},
{
VatID: "96978044-5", // valid rut
Day: "2023-04-10",
DocumentType: "48",
Channel: "1", // 1 for cnp
Amount: 2042,
NTransactions: 2,
ExternalTrackID: "0",
},
{
VatID: "65537690-9", // valid rut
Day: "2023-04-10",
DocumentType: "48",
Channel: "0", // 0 for cnp
Amount: 500,
NTransactions: 2,
ExternalTrackID: "0",
},
{
VatID: "39020493-0", // valid rut
Day: "2023-04-10",
DocumentType: "48",
Channel: "0", // 0 for cnp
Amount: 500,
NTransactions: 2,
ExternalTrackID: "0",
},
})
// document 48 with amount zero
batchesMatrix = append(batchesMatrix, []entities.Batch{
{
VatID: "69610726-2", // valid rut
Day: "2023-04-10",
DocumentType: "48",
Channel: "1", // 1 for cnp
Amount: 0,
NTransactions: 1,
ExternalTrackID: "0",
},
{
VatID: "28474336-9", // valid rut
Day: "2023-04-10",
DocumentType: "48",
Channel: "1", // 1 for cnp
Amount: 0,
NTransactions: 1,
ExternalTrackID: "0",
},
{
VatID: "85445473-0", // valid rut
Day: "2023-04-10",
DocumentType: "48",
Channel: "0", // 0 for cnp
Amount: 0,
NTransactions: 1,
ExternalTrackID: "0",
},
})
// document 33 (bill)
batchesMatrix = append(batchesMatrix, []entities.Batch{
{
VatID: "94690304-3", // valid rut
Day: "2023-04-10",
DocumentType: "33",
Channel: "1", // 1 for cnp
Amount: 10000,
NTransactions: 2,
ExternalTrackID: "0",
},
})
// document 99 (no sell)
batchesMatrix = append(batchesMatrix, []entities.Batch{
{
VatID: "99040414-3", // valid rut
Day: "2023-04-10",
DocumentType: "99",
Channel: "1", // 1 for cnp
Amount: 10000,
NTransactions: 2,
ExternalTrackID: "0",
},
})
// document 00 (unknown)
batchesMatrix = append(batchesMatrix, []entities.Batch{
{
VatID: "61116878-0", // valid rut
Day: "2023-04-10",
DocumentType: "00",
Channel: "1", // 1 for cnp
Amount: 2000,
NTransactions: 2,
ExternalTrackID: "0",
},
})
return batchesMatrix
}