-
Notifications
You must be signed in to change notification settings - Fork 1
/
customer_bank_account.go
146 lines (123 loc) · 5.61 KB
/
customer_bank_account.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
package gocardless
import (
"encoding/json"
"fmt"
"net/url"
"log"
"os"
"net/http"
)
type CustomerBankAccountService service
type CustomerBankAccount struct {
Id string `json:"id,omitempty"`
BankName string `json:"bank_name,omitempty"`
CountryCode string `json:"country_code,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Currency string `json:"currency,omitempty"`
AccountHolderName string `json:"account_holder_name,omitempty"`
AccountNumberEnding string `json:"account_number_ending,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Links []CustomerLink `json:"links,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
ResponseUrl string `json:"responseurl,omitempty"`
}
type CustomerBankListRequest struct {
CreatedAt CreatedAt `json:"created_at,omitempty"`
Limit int `json:"limit,omitempty"`
Before string `json:"before,omitempty"`
After string `json:"after,omitempty"`
}
// CustomerBankAccountList is a list object for customer bank accounts.
type CustomerBankAccountList struct {
Meta ListMeta
Values []CustomerBankAccount `json:"data"`
}
type CustomerBankAccountCreateRequest struct {
Iban string `json:"iban,omitempty"`
BankCode string `json:"bank_code,omitempty"`
BranchCode string `json:"branch_code,omitempty"`
CountryCode string `json:"country_code,omitempty"`
Currency string `json:"currency,omitempty"`
AccountHolderName string `json:"account_holder_name,omitempty"`
AccountNumber string `json:"account_number,omitempty"`
Links []CustomerLink `json:"links,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
ResponseUrl string `json:"responseurl,omitempty"`
}
type CustomerBankAccountDisableRequest struct {
Identity string `json:"identity,omitempty"`
}
// Create creates a new customer bank account
func (s *CustomerBankAccountService) CreateCustomerBankAccount(bankAccount *CustomerBankAccountCreateRequest) (*CustomerBankAccount, error) {
// do something with error
fmt.Sprintf("The error while creating a customer bank account is :%s", "About to create")
u := fmt.Sprintf("/customer_bank_accounts")
account := &CustomerBankAccount{}
rel := map[string]interface{}{
"customer_bank_accounts": bankAccount,
}
custJson, _ := json.Marshal(rel)
customerObject := string(custJson[:])
fmt.Sprintf("Making the request with params %s", customerObject)
if rel == nil {
fmt.Println("Rubbish call")
}
err := s.client.Call("POST", u, rel, account)
if err != nil {
fmt.Println("Successful call")
}
return account, err
}
// ListN Returns a cursor-paginated list of your customer bank accounts.
// https://developer.gocardless.com/api-reference/#customer-bank-accounts-list-customer-bank-accounts
func (s *CustomerBankAccountService) ListCustomerBankAccounts(req *CustomerBankListRequest) (*CustomerBankAccountList, error) {
reqd, err := http.NewRequest("GET", "/customer_bank_accounts", nil)
if err != nil {
log.Print(err)
os.Exit(1)
}
params := reqd.URL.Query()
if req.After != "" { params.Add("after", req.After) }
if req.Before != "" { params.Add("before", req.Before) }
if req.CreatedAt.Gt != "" { params.Add("created_at[gt]", req.CreatedAt.Gt) }
if req.CreatedAt.Gte != "" { params.Add("created_at[gte]", req.CreatedAt.Gte) }
if req.CreatedAt.Lt != "" { params.Add("created_at[lt]", req.CreatedAt.Lt) }
if req.CreatedAt.Lte != "" {params.Add("created_at[lte]", req.CreatedAt.Lte)}
if req.Limit > 0 {params.Add("limit", string(req.Limit))}
reqd.URL.RawQuery = params.Encode()
path := reqd.URL.String()
bankAccounts := &CustomerBankAccountList{}
err = s.client.Call("GET", path, nil, bankAccounts)
return bankAccounts, err
}
// Retrieves the details of an existing customer bank account.
// https://developer.gocardless.com/api-reference/#customer-bank-accounts-get-a-single-customer-bank-account
func (s *CustomerBankAccountService) GetCustomerBankAccount(id string) (*CustomerBankAccount, error) {
u := fmt.Sprintf("/customer_bank_accounts/%s", id)
account := &CustomerBankAccount{}
err := s.client.Call("GET", u, nil, account)
return account, err
}
// Update updates a customer's properties.
// For more details see https://developer.gocardless.com/api-reference/#customer-bank-accounts-update-a-customer-bank-account
func (s *CustomerBankAccountService) UpdateCustomerBankAccount(customerBankAccount *CustomerBankAccount, metadata map[string]string) (*CustomerBankAccount, error) {
u := fmt.Sprintf("customer_bank_accounts/%s", customerBankAccount.Id)
params := url.Values{}
metadataString, _ := json.Marshal(metadata)
customerBankAccount.Metadata = metadata
rel := map[string]interface{}{
"customer_bank_accounts": customerBankAccount,
}
params.Add("metadata", string(metadataString))
account := &CustomerBankAccount{}
err := s.client.Call("PUT", u, rel, account)
return account, err
}
// Immediately disables the bank account, no money can be paid out to a disabled account.
// https://developer.gocardless.com/api-reference/#customer-bank-accounts-disable-a-customer-bank-account
func (s *CustomerBankAccountService) DisableCustomerBankAccount(bankAccount *CustomerBankAccount) (*Response, error) {
u := fmt.Sprintf("/customer_bank_accounts/%s/actions/disable", bankAccount.Id)
resp := &Response{}
err := s.client.Call("POST", u, bankAccount, resp)
return resp, err
}