-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_services.go
166 lines (159 loc) · 5.41 KB
/
account_services.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
package jenga
import (
"errors"
"fmt"
// "log"
"encoding/json"
"io/ioutil"
"github.com/gats/jenga-go/utilities"
)
// GetAccountBalance - fetches account balance from the Jenga HQ API
// Accepts account and country code and returns a map[string]interface{} and or an error
func (j *JengaImpl) GetAccountBalance(account, countryCode string) (map[string]interface{}, error) {
ret := utilities.IsAllowedCountryCode(countryCode)
if !ret {
return nil, errors.New("Country code not allowed")
}
data := account + countryCode
signature, err := utilities.GenerateSignature(data, j.KeyPath)
if err != nil {
return nil, err
}
uridata := fmt.Sprintf("accounts/balances/%s/%s", countryCode, account)
endpoint := sandBoxAccountsEndpoint+uridata
resp := utilities.MakeGetRequest(signature, j.Token, j.BaseURL, endpoint)
defer resp.Body.Close()
resMap := make(map[string]interface{})
body, _ := ioutil.ReadAll(resp.Body)
err1 := json.Unmarshal([]byte(body), &resMap)
if err1 != nil {
return nil, err1
}
return resMap, nil
}
// GetMiniStatement - fetches the mini statement from the Jenga HQ API
// Accepts account and country code and returns a map[string]interface{} and or an error
func (j *JengaImpl) GetMiniStatement(account, countryCode string) (map[string]interface{}, error) {
ret := utilities.IsAllowedCountryCode(countryCode)
if !ret {
return nil, errors.New("Country code not allowed")
}
data := account + countryCode
signature, err := utilities.GenerateSignature(data, j.KeyPath)
if err != nil {
return nil, err
}
uridata := fmt.Sprintf("accounts/ministatement/%s/%s", countryCode, account)
endpoint := sandBoxAccountsEndpoint+uridata
resp := utilities.MakeGetRequest(signature, j.Token, j.BaseURL, endpoint)
defer resp.Body.Close()
resMap := make(map[string]interface{})
body, _ := ioutil.ReadAll(resp.Body)
err1 := json.Unmarshal([]byte(body), &resMap)
if err1 != nil {
return nil, err1
}
return resMap, nil
}
// GetFullStatement - fetches the full statement from the Jenga HQ API
// Current implementation only accepts account, countryCode, from date, to date and the limit.
// From and To Dates should be in the ISO 8601 format i.e. YYYY-MM-DD
// Other paramaters to be added later.
func (j *JengaImpl) GetFullStatement(account, countryCode, fromDate, toDate string, limit int) (map[string]interface{}, error) {
ret := utilities.IsAllowedCountryCode(countryCode)
if !ret {
return nil, errors.New("Country code not allowed")
}
// Technical Debt - To add other parameters as provided by the spec.
type FullStatement struct{
CCode string `json:"countryCode"`
AccNUmber string `json:"accountNumber"`
FromDate string `json:"fromDate"`
ToDate string `json:"toDate"`
Limit int `json:"limit"`
}
u := FullStatement{
CCode: countryCode,
AccNUmber: account,
FromDate: fromDate,
ToDate: toDate,
Limit: limit,
}
msg, _ := json.Marshal(u)
data := account + countryCode + toDate
signature, err := utilities.GenerateSignature(data, j.KeyPath)
if err != nil {
return nil, err
}
uridata := "accounts/fullstatement"
endpoint := sandBoxAccountsEndpoint+uridata
resp := utilities.MakePostRequest(signature, j.Token, j.BaseURL, endpoint, msg)
defer resp.Body.Close()
resMap := make(map[string]interface{})
body, _ := ioutil.ReadAll(resp.Body)
err1 := json.Unmarshal([]byte(body), &resMap)
if err1 != nil {
return nil, err1
}
return resMap, nil
}
// GetOpenAndCloseBalance - fetches the full statement from the Jenga HQ API
// Accepts account, countryCode and date.
// Date should be in the ISO 8601 format i.e. YYYY-MM-DD
func (j *JengaImpl) GetOpenAndCloseBalance(account, countryCode, date string) (map[string]interface{}, error) {
ret := utilities.IsAllowedCountryCode(countryCode)
if !ret {
return nil, errors.New("Country code not allowed")
}
type FullStatement struct{
CCode string `json:"countryCode"`
AccNUmber string `json:"accountId"`
Date string `json:"date"`
}
u := FullStatement{
CCode: countryCode,
AccNUmber: account,
Date: date,
}
msg, _ := json.Marshal(u)
data := account + countryCode + date
signature, err := utilities.GenerateSignature(data, j.KeyPath)
if err != nil {
return nil, err
}
uridata := "accounts/accountbalance/query"
endpoint := sandBoxAccountsEndpoint+uridata
resp := utilities.MakePostRequest(signature, j.Token, j.BaseURL, endpoint, msg)
defer resp.Body.Close()
resMap := make(map[string]interface{})
body, _ := ioutil.ReadAll(resp.Body)
err1 := json.Unmarshal([]byte(body), &resMap)
if err1 != nil {
return nil, err1
}
return resMap, nil
}
// GetAccountDetails - fetches the the details of an account (Account Inquiry)
// Accepts account and country code and returns a map[string]interface{} and or an error
func (j *JengaImpl) GetAccountDetails(account, countryCode string) (map[string]interface{}, error) {
ret := utilities.IsAllowedCountryCode(countryCode)
if !ret {
return nil, errors.New("Country code not allowed")
}
data := account + countryCode
signature, err := utilities.GenerateSignature(data, j.KeyPath)
if err != nil {
return nil, err
}
uridata := fmt.Sprintf("search/%s/%s", countryCode, account)
endpoint := sandBoxAccountsEndpoint+uridata
resp := utilities.MakeGetRequest(signature, j.Token, j.BaseURL, endpoint)
defer resp.Body.Close()
resMap := make(map[string]interface{})
body, _ := ioutil.ReadAll(resp.Body)
err1 := json.Unmarshal([]byte(body), &resMap)
if err1 != nil {
return nil, err1
}
return resMap, nil
}