forked from plaid/plaid-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
152 lines (134 loc) · 4.23 KB
/
main.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
package main
import (
"fmt"
"strings"
"github.com/alphaspark/plaid-go/plaid"
)
// main contains example usage of all functions
func main() {
// GET /institutions
res, err := plaid.GetInstitutions(plaid.Tartan)
if err != nil {
fmt.Println(err)
}
fmt.Println(res[0].Name, "has type:", res[0].Type)
// GET /institutions/5301a93ac140de84910000e0
inst, err := plaid.GetInstitution(plaid.Tartan, "5301a93ac140de84910000e0")
if err != nil {
fmt.Println("Institution Error:", err)
}
fmt.Println(inst.Name, "has mfa:", strings.Join(inst.MFA, ", "))
// GET /categories
categories, err := plaid.GetCategories(plaid.Tartan)
if err != nil {
fmt.Println(err)
}
fmt.Println("First category:", categories[0])
// GET /categories/13001001
category, err := plaid.GetCategory(plaid.Tartan, "13001001")
if err != nil {
fmt.Println(err)
}
fmt.Println("category", category.ID, "is", strings.Join(category.Hierarchy, ", "))
client := plaid.NewClient("test_id", "test_secret", plaid.Tartan)
// POST /auth
postRes, mfaRes, err :=
client.AuthAddUser("plaid_test", "plaid_good", "", "citi", nil)
if err != nil {
fmt.Println(err)
} else if mfaRes != nil {
switch mfaRes.Type {
case "device":
fmt.Println("--Device MFA--")
fmt.Println("Message:", mfaRes.Device.Message)
case "list":
fmt.Println("--List MFA--")
fmt.Println("Mask:", mfaRes.List[0].Mask, "\nType:", mfaRes.List[0].Type)
case "questions":
fmt.Println("--Questions MFA--")
fmt.Println("Question:", mfaRes.Questions[0].Question)
case "selections":
fmt.Println("--Selections MFA--")
fmt.Println("Question:", mfaRes.Selections[1].Question)
fmt.Println("Answers:", mfaRes.Selections[1].Answers)
}
postRes2, mfaRes2, err := client.AuthStepSendMethod(mfaRes.AccessToken, "type", "email")
if err != nil {
fmt.Println("Error submitting send_method", err)
}
fmt.Printf("%+v\n", mfaRes2)
fmt.Printf("%+v\n", postRes2)
postRes2, mfaRes2, err = client.AuthStep(mfaRes.AccessToken, "tomato")
if err != nil {
fmt.Println("Error submitting mfa", err)
}
fmt.Printf("%+v\n", mfaRes2)
fmt.Printf("%+v\n", postRes2)
} else {
fmt.Println(postRes.Accounts)
fmt.Println("Auth Get")
fmt.Println(client.AuthGet("test_citi"))
fmt.Println("Auth DELETE")
fmt.Println(client.AuthDelete("test_citi"))
}
// POST /connect
postRes, mfaRes, err = client.ConnectAddUser("plaid_test", "plaid_good", "", "citi", nil)
if err != nil {
fmt.Println(err)
} else if mfaRes != nil {
switch mfaRes.Type {
case "device":
fmt.Println("--Device MFA--")
fmt.Println("Message:", mfaRes.Device.Message)
case "list":
fmt.Println("--List MFA--")
fmt.Println("Mask:", mfaRes.List[0].Mask, "\nType:", mfaRes.List[0].Type)
case "questions":
fmt.Println("--Questions MFA--")
fmt.Println("Question:", mfaRes.Questions[0].Question)
case "selections":
fmt.Println("--Selections MFA--")
fmt.Println("Question:", mfaRes.Selections[1].Question)
fmt.Println("Answers:", mfaRes.Selections[1].Answers)
}
postRes2, mfaRes2, err := client.ConnectStepSendMethod(mfaRes.AccessToken, "type", "email")
if err != nil {
fmt.Println("Error submitting send_method", err)
}
fmt.Printf("%+v\n", mfaRes2)
fmt.Printf("%+v\n", postRes2)
postRes2, mfaRes2, err = client.ConnectStep(mfaRes.AccessToken, "1234")
if err != nil {
fmt.Println("Error submitting mfa", err)
}
fmt.Printf("%+v\n", mfaRes2)
fmt.Printf("%+v\n", postRes2)
} else {
fmt.Println(postRes.Accounts)
fmt.Println("Connect GET")
connectRes, _, _ := client.ConnectGet("test_citi", &plaid.ConnectGetOptions{true, "", "", ""})
fmt.Println(len(connectRes.Transactions))
fmt.Println(connectRes.Transactions)
fmt.Println("Connect DELETE")
fmt.Println(client.ConnectDelete("test_citi"))
}
// POST /balance
fmt.Println("Balance")
postRes, err = client.Balance("test_citi")
if err != nil {
fmt.Println(err)
}
fmt.Printf("%+v\n", postRes)
// POST /upgrade
fmt.Println("Upgrade")
postRes, mfaRes, err = client.Upgrade("test_bofa", "connect", nil)
if err != nil {
fmt.Println(err)
}
fmt.Printf("%+v\n", mfaRes)
fmt.Printf("%+v\n", postRes)
// POST exchange_token
fmt.Println("ExchangeToken")
postRes, err = client.ExchangeToken("test,chase,connected")
fmt.Printf("%+v\n", postRes)
}