-
Notifications
You must be signed in to change notification settings - Fork 0
/
products_bankaccount.go
173 lines (146 loc) · 6.43 KB
/
products_bankaccount.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package capis
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"time"
querystring "github.com/google/go-querystring/query"
"go.opencensus.io/trace"
)
type (
NewBankAccountRequest struct {
ID string `json:"id"`
Issuer string `json:"issuer"`
Name string `json:"name"`
Description string `json:"description"`
URLApply string `json:"url_apply"`
URLLogo string `json:"url_logo"`
HighlightedPoints []string `json:"highlighted_points"`
TechnicalPoints []string `json:"technical_points"`
OfferInterestRate RatePeriod `json:"offer_interest_rate"`
StandardInterestRate Rate `json:"standard_interest_rate"`
InterestPaid string `json:"interest_paid"`
OfferOverdraftRate RatePeriod `json:"offer_overdraft_rate"`
StandardOverdraftRate Rate `json:"standard_overdraft_rate"`
StandardChargeRate Rate `json:"standard_charge_rate"`
OfferChargeRate Rate `json:"offer_charge_rate"`
MinimumDeposit Money `json:"deposit_minimum"`
MaximumDeposit Money `json:"deposit_maximum"`
AnnualFee Money `json:"annual_fee"`
MonthlyFee Money `json:"monthly_fee"`
ApprovalCriteria string `json:"approval_criteria"`
IsISA bool `json:"is_isa"`
IsCapitalProtected bool `json:"is_capital_protected"`
HasTransactionFees bool `json:"has_transaction_fees"`
HasOnlineBanking bool `json:"has_online_banking"`
BrokerOnly bool `json:"broker_only"`
Active bool `json:"active"`
Meta map[string]interface{} `json:"metadata"`
}
BankAccount struct {
ID string `json:"id"`
Issuer string `json:"issuer"`
Name string `json:"name"`
Description string `json:"description"`
URLApply string `json:"url_apply"`
URLLogo string `json:"url_logo"`
HighlightedPoints []string `json:"highlighted_points"`
TechnicalPoints []string `json:"technical_points"`
OfferInterestRate RatePeriod `json:"offer_interest_rate"`
StandardInterestRate Rate `json:"standard_interest_rate"`
InterestPaid string `json:"interest_paid"`
OfferOverdraftRate RatePeriod `json:"offer_overdraft_rate"`
StandardOverdraftRate Rate `json:"standard_overdraft_rate"`
StandardChargeRate Rate `json:"standard_charge_rate"`
OfferChargeRate Rate `json:"offer_charge_rate"`
MinimumDeposit Money `json:"deposit_minimum"`
MaximumDeposit Money `json:"deposit_maximum"`
AnnualFee Money `json:"annual_fee"`
MonthlyFee Money `json:"monthly_fee"`
ApprovalCriteria string `json:"approval_criteria"`
IsISA bool `json:"is_isa"`
IsCapitalProtected bool `json:"is_capital_protected"`
HasTransactionFees bool `json:"has_transaction_fees"`
HasOnlineBanking bool `json:"has_online_banking"`
BrokerOnly bool `json:"broker_only"`
Active bool `json:"active"`
Meta map[string]interface{} `json:"metadata"`
Created time.Time `json:"created"`
}
ListBankAccountsResponse struct {
Data []*BankAccount `json:"data"`
}
)
func (s *ProductsService) NewBankAccount(ctx context.Context, opts *NewBankAccountRequest) error {
ctx, span := trace.StartSpan(ctx, "lwebco.de/go-capis/ProductsService.NewBankAccount")
defer span.End()
rb, _ := json.Marshal(opts)
req, err := s.c.newRequest("POST", "/v1/bankaccounts", bytes.NewReader(rb))
if err != nil {
return err
}
res, err := s.c.Do(req.WithContext(ctx))
if err != nil {
s.c.logError(err)
return ErrUnreachable
}
defer res.Body.Close()
return statusCodeToError(res.StatusCode)
}
func (s *ProductsService) FindBankAccount(ctx context.Context, id string) (*BankAccount, error) {
ctx, span := trace.StartSpan(ctx, "lwebco.de/go-capis/ProductsService.FinkBankAccount")
defer span.End()
req, err := s.c.newRequest("GET", fmt.Sprintf("/v1/bankaccounts/%s", id), nil)
if err != nil {
return nil, err
}
res, err := s.c.Do(req.WithContext(ctx))
if err != nil {
s.c.logError(err)
return nil, ErrUnreachable
}
defer res.Body.Close()
ba := &BankAccount{}
return ba, unmarshalResponse(res, ba)
}
func (s *ProductsService) UpdateBankAccount(ctx context.Context, bankAccount *BankAccount) error {
ctx, span := trace.StartSpan(ctx, "lwebco.de/go-capis/ProductsService.UpdateBankAccount")
defer span.End()
if len(bankAccount.ID) == 0 {
return errors.New("can only update an existing bank account")
}
rb, _ := json.Marshal(bankAccount)
req, err := s.c.newRequest("PUT", fmt.Sprintf("/v1/bankaccounts/%s", bankAccount.ID), bytes.NewReader(rb))
if err != nil {
return err
}
res, err := s.c.Do(req.WithContext(ctx))
if err != nil {
s.c.logError(err)
return ErrUnreachable
}
defer res.Body.Close()
return statusCodeToError(res.StatusCode)
}
func (s *ProductsService) ListBankAccounts(ctx context.Context, filters *ProductFilters) (*ListBankAccountsResponse, error) {
ctx, span := trace.StartSpan(ctx, "lwebco.de/go-capis/ProductsService.ListBankAccounts")
defer span.End()
obj := &ListBankAccountsResponse{}
qs, _ := querystring.Values(filters)
req, err := s.c.newRequest("GET", "/v1/bankaccounts?"+qs.Encode(), nil)
if err != nil {
return nil, err
}
res, err := s.c.Do(req.WithContext(ctx))
if err != nil {
s.c.logError(err)
return nil, ErrUnreachable
}
defer res.Body.Close()
if err = statusCodeToError(res.StatusCode); err != nil {
return nil, err
}
return obj, unmarshalResponse(res, obj)
}