-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
accounts_endpoints.go
72 lines (61 loc) · 1.96 KB
/
accounts_endpoints.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
package gocardless
import (
"context"
"fmt"
"net/url"
"time"
)
// GetAccount retrieves an account by ID
func (c Client) GetAccount(ctx context.Context, accountID string) (*Account, error) {
var account Account
endpointURL := AccountsPath + accountID
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &account)
if err != nil {
return nil, err
}
return &account, nil
}
// GetAccountBalances retrieves balances for an account by ID
func (c Client) GetAccountBalances(ctx context.Context, accountID string) (*Balances, error) {
var balances Balances
endpointURL := AccountsPath + accountID + "/balances"
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &balances)
if err != nil {
return nil, err
}
return &balances, nil
}
// GetAccountDetails retrieves details for an account by ID
func (c Client) GetAccountDetails(ctx context.Context, accountID string) (*Details, error) {
var details Details
endpointURL := AccountsPath + accountID + "/details"
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &details)
if err != nil {
return nil, err
}
return &details, nil
}
// GetAccountTransactions retrieves transactions for an account by ID
// dateFrom and dateTo are optional parameters.
func (c Client) GetAccountTransactions(ctx context.Context, accountID string, dateFrom, dateTo *time.Time) (*Transactions, error) {
var transactions Transactions
endpointURL := AccountsPath + accountID + "/transactions"
// Build query parameters
u, err := url.Parse(endpointURL)
if err != nil {
return nil, fmt.Errorf("failed to parse URL: %w", err)
}
q := u.Query()
if dateFrom != nil {
q.Set("date_from", dateFrom.Format(time.RFC3339))
}
if dateTo != nil {
q.Set("date_to", dateTo.Format(time.RFC3339))
}
u.RawQuery = q.Encode()
err = c.HTTP.Get(ctx, u.String(), RequestHeadersWithAuth(c.Token.Access), &transactions)
if err != nil {
return nil, err
}
return &transactions, nil
}