Skip to content

Commit 62bd2ba

Browse files
committed
add invoice and chargepoint services
1 parent 08534a0 commit 62bd2ba

File tree

5 files changed

+119
-1
lines changed

5 files changed

+119
-1
lines changed

chargepoint.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package smartcharge
2+
3+
type ChargePointService struct {
4+
client *Client
5+
}

client_mock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewMockClient(response MockResponse) *Client {
6161
}
6262

6363
client := NewClient(c)
64-
client.SetAuthentication(auth)
64+
client.setAuthentication(auth)
6565

6666
return client
6767
}

invoice.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package smartcharge
2+
3+
import (
4+
"net/http"
5+
"strconv"
6+
)
7+
8+
type InvoiceService struct {
9+
client *Client
10+
}
11+
12+
type InvoiceResult struct {
13+
Result Data `json:"Result"`
14+
}
15+
16+
type Data struct {
17+
Data InvoiceData `json:"datas"`
18+
Success bool `json:"sucess"`
19+
}
20+
21+
type InvoiceData struct {
22+
Invoices []Invoice
23+
}
24+
25+
type Invoice struct {
26+
Id int `json:"PK_InvoiceID"`
27+
TotalPrice float64 `json:"TotalPrice"`
28+
TotalVAT float64 `json:"TotalVAT"`
29+
DateIssued string `json:"DateIssued"`
30+
TotalKWH float64 `json:"TotalKWH"`
31+
}
32+
33+
func (i *InvoiceService) GetInvoices(customerId int) (*InvoiceResult, *http.Response, error) {
34+
35+
reqUrl := "v2/Invoices/GetInvoicesByCustomer/" + strconv.Itoa(customerId)
36+
req, err := i.client.NewRequest("GET", reqUrl, nil)
37+
if err != nil {
38+
return nil, nil, err
39+
}
40+
41+
invoiceResult := &InvoiceResult{}
42+
resp, err := i.client.Do(req, invoiceResult)
43+
if err != nil {
44+
return nil, resp, err
45+
}
46+
47+
return invoiceResult, resp, err
48+
}

invoice_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package smartcharge
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"io/ioutil"
6+
"testing"
7+
)
8+
9+
func TestInvoiceService_GetInvoices(t *testing.T) {
10+
jsonBytes, _ := ioutil.ReadFile("testdata/invoices/invoices.json")
11+
12+
r := *NewMockResponseOkString(string(jsonBytes))
13+
c := NewMockClient(r)
14+
15+
data, _, err := c.Invoice.GetInvoices(123)
16+
17+
assert.NoError(t, err)
18+
assert.Equal(t, 414005, data.Result.Data.Invoices[0].Id)
19+
assert.Equal(t, 87.407, data.Result.Data.Invoices[0].TotalKWH)
20+
}

testdata/invoices/invoices.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"$id": "1",
3+
"Result": {
4+
"success": true,
5+
"datas": {
6+
"Invoices": [
7+
{
8+
"PK_InvoiceID": 414005,
9+
"Invoice_No": "377202",
10+
"TransactionFee": 0.00000,
11+
"TotalPrice": 169.8605,
12+
"TotalVAT": 33.9721,
13+
"DateIssued": "2021-02-01T06:36:28.017",
14+
"DateDue": "2021-02-01T06:36:28.017",
15+
"DatePaid": "2021-02-01T06:37:01.117",
16+
"Currency": "NOK",
17+
"TotalPriceExcludingVAT": 135.8884,
18+
"TransactionFeeVAT": 0.00000,
19+
"PaymentResult": "Paid",
20+
"TotalKWH": 87.407000,
21+
"StartupCost": 0.000000,
22+
"StartupCostVAT": 0.00000,
23+
"FK_CustomerID": 33227,
24+
"CustomerName": "Sjur Fredriksen",
25+
"PhoneNumber": null,
26+
"Email": null,
27+
"DialCode": "",
28+
"InvoiceType": "EndCustomer",
29+
"FK_CompanyID": null,
30+
"TotalPriceKWh": 131.07,
31+
"TotalPriceChargingTime": 0.00,
32+
"TotalPriceNotCharging": 7.7500,
33+
"TotalPriceOccupied": 0.00,
34+
"TotalTimeCharging": 87927,
35+
"TotalTimeOccupied": 925,
36+
"IsTripletexInvoice": false,
37+
"ExternalInvoiceNumber": null,
38+
"NonChargingItems": [],
39+
"NonChargingItemsGroupedByStation": []
40+
}
41+
],
42+
"Count": 1
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)