This repository has been archived by the owner on Nov 4, 2022. It is now read-only.
forked from plaid/plaid-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deposit_switch.go
111 lines (95 loc) · 3.17 KB
/
deposit_switch.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
package plaid
import (
"encoding/json"
"errors"
)
type getDepositSwitchRequest struct {
ClientID string `json:"client_id"`
Secret string `json:"secret"`
DepositSwitchID string `json:"deposit_switch_id"`
}
// GetDepositSwitchResponse details the response from /deposit_switch/get.
type GetDepositSwitchResponse struct {
DepositSwitchID string `json:"deposit_switch_id"`
TargetItemID string `json:"target_item_id"`
TargetAccountID string `json:"target_account_id"`
State string `json:"state"`
RequestID string `json:"request_id"`
DateCreated string `json:"date_created,omitempty"`
DateCompleted string `json:"date_completed,omitempty"`
}
// GetDepositSwitch retrieves deposit switch data.
func (c *Client) GetDepositSwitch(
depositSwitchID string,
) (resp GetDepositSwitchResponse, err error) {
if depositSwitchID == "" {
return resp, errors.New("/deposit_switch/get - deposit switch id must be specified")
}
req := getDepositSwitchRequest{
ClientID: c.clientID,
Secret: c.secret,
DepositSwitchID: depositSwitchID,
}
jsonBody, err := json.Marshal(req)
if err != nil {
return resp, err
}
err = c.Call("/deposit_switch/get", jsonBody, &resp)
return resp, err
}
type createDepositSwitchRequest struct {
ClientID string `json:"client_id"`
Secret string `json:"secret"`
TargetAccountID string `json:"target_account_id"`
TargetAccessToken string `json:"target_access_token"`
}
type createDepositSwitchResponse struct {
DepositSwitchID string `json:"deposit_switch_id"`
}
func (c *Client) CreateDepositSwitch(targetAccountID string, targetAccessToken string) (resp createDepositSwitchResponse, err error) {
if targetAccountID == "" {
return resp, errors.New("/deposit_switch/create - target account id must be specified")
}
if targetAccessToken == "" {
return resp, errors.New("/deposit_switch/create - target access token must be specified")
}
req := createDepositSwitchRequest{
ClientID: c.clientID,
Secret: c.secret,
TargetAccountID: targetAccountID,
TargetAccessToken: targetAccessToken,
}
jsonBody, err := json.Marshal(req)
if err != nil {
return resp, err
}
err = c.Call("/deposit_switch/create", jsonBody, &resp)
return resp, err
}
type createDepositSwitchTokenRequest struct {
ClientID string `json:"client_id"`
Secret string `json:"secret"`
DepositSwitchID string `json:"deposit_switch_id"`
}
type createDepositSwitchTokenResponse struct {
DepositSwitchToken string `json:"deposit_switch_token"`
DepositSwitchTokenExpirationTime string `json:"deposit_switch_token_expiration_time"`
}
func (c *Client) CreateDepositSwitchToken(
depositSwitchID string,
) (resp createDepositSwitchTokenResponse, err error) {
if depositSwitchID == "" {
return resp, errors.New("/deposit_switch/token/create - deposit switch id must be specified")
}
req := createDepositSwitchTokenRequest{
ClientID: c.clientID,
Secret: c.secret,
DepositSwitchID: depositSwitchID,
}
jsonBody, err := json.Marshal(req)
if err != nil {
return resp, err
}
err = c.Call("/deposit_switch/token/create", jsonBody, &resp)
return resp, err
}