Commit e61590f6 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel

Added listing & creating bank accounts

parent 4b4ed560
......@@ -80,7 +80,7 @@ func (c *Client) NewRequest(method, endpoint string, payload interface{}) *http.
case "device-server", "session-server":
req.Header.Set(headerXBunqClientAuthentication, c.creds.InstallationToken)
default:
// TODO: use token from session-server response
req.Header.Set(headerXBunqClientAuthentication, c.session.Token)
}
return req
......
package bunqapi
import (
"fmt"
"github.com/sirupsen/logrus"
)
type wrappedMonetaryAccountBankResponse struct {
Response []monetaryAccountBankResponse `json:"Response"`
}
type monetaryAccountBankResponse struct {
MonetaryAccountBank MonetaryAccountBank `json:"MonetaryAccountBank"`
}
type wrappedMonetaryAccountBankCreateResponse struct {
Response []monetaryAccountBankCreateResponse `json:"Response"`
}
type monetaryAccountBankCreateResponse struct {
ID BunqID `json:"Id"`
}
type MonetaryAccountBank struct {
ID int `json:"id,omitempty"`
Created *Time `json:"created,omitempty"`
Updated *Time `json:"updated,omitempty"`
Avatar *Avatar `json:"avatar,omitempty"`
Currency string `json:"currency"`
Description string `json:"description,omitempty"`
DailyLimit *Amount `json:"daily_limit,omitempty"`
DailySpent *Amount `json:"daily_spent,omitempty"`
OverdraftLimit *Amount `json:"overdraft_limit,omitempty"`
Balance *Amount `json:"balance,omitempty"`
Alias []Alias `json:"alias,omitempty"`
PublicUUID string `json:"public_uuid,omitempty"`
Status string `json:"status,omitempty"`
SubStatus string `json:"sub_status,omitempty"`
Reason string `json:"reason,omitempty"`
ReasonDescription string `json:"reason_description,omitempty"`
UserID int `json:"user_id,omitempty"`
NotificationFilters []NotificationFilter `json:"notification_filters,omitempty"`
Setting *MonetaryAccountSetting `json:"setting,omitempty"`
// monetary_account_profile is not yet implemented
}
type MonetaryAccountSetting struct {
Color string `json:"color"`
DefaultAvatarStatus string `json:"default_avatar_status"`
RestrictionChat string `json:"restriction_chat"`
}
func (c *Client) GetMonetaryAccountBankList() {
wrappedResponse := wrappedMonetaryAccountBankResponse{}
url := fmt.Sprintf("user/%d/monetary-account-bank", c.session.UserPerson.ID)
errResp := c.DoRequest("GET", url, nil, &wrappedResponse)
if errResp != nil {
logrus.WithFields(errResp.LogFields()).Fatal("error performing session creation request")
}
}
func (c *Client) CreateMonetaryAccountBank(account MonetaryAccountBank) {
wrappedResponse := wrappedMonetaryAccountBankCreateResponse{}
url := fmt.Sprintf("user/%d/monetary-account-bank", c.session.UserPerson.ID)
errResp := c.DoRequest("POST", url, &account, &wrappedResponse)
if errResp != nil {
logrus.WithFields(errResp.LogFields()).Fatal("error performing session creation request")
}
response := monetaryAccountBankCreateResponse{}
MergeStructs(wrappedResponse.Response, &response)
logrus.WithField("bankAccountID", response.ID.ID).Info("bank account created")
}
......@@ -23,6 +23,11 @@ func main() {
"62.251.18.36",
"2001:984:42c1:1:712e:7ce7:8e46:1fdb",
})
client.SessionStart()
bankAccount := bunqapi.MonetaryAccountBank{
Currency: "EUR",
}
client.CreateMonetaryAccountBank(bankAccount)
client.GetMonetaryAccountBankList()
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment