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
/
link_token.go
105 lines (90 loc) · 3.75 KB
/
link_token.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
package plaid
import (
"encoding/json"
"time"
)
type LinkTokenUser struct {
ClientUserID string `json:"client_user_id"`
LegalName string `json:"legal_name,omitempty"`
PhoneNumber string `json:"phone_number,omitempty"`
EmailAddress string `json:"email_address,omitempty"`
PhoneNumberVerifiedTime time.Time `json:"phone_number_verified_time,omitempty"`
EmailAddressVerifiedTime time.Time `json:"email_address_verified_time,omitempty"`
}
type CrossAppItemAdd struct {
TargetApplicationToken string `json:"target_application_token"`
ForeignID string `json:"foreign_id,omitempty"`
}
type PaymentInitiation struct {
PaymentID string `json:"payment_id"`
}
type LinkTokenConfigs struct {
User *LinkTokenUser `json:"user"`
ClientName string `json:"client_name"`
Products []string `json:"products,omitempty"`
AccessToken string `json:"access_token,omitempty"`
CountryCodes []string `json:"country_codes,omitempty"`
Webhook string `json:"webhook,omitempty"`
AccountFilters *map[string]map[string][]string `json:"account_filters,omitempty"`
CrossAppItemAdd *CrossAppItemAdd `json:"cross_app_item_add,omitempty"`
PaymentInitiation *PaymentInitiation `json:"payment_initiation,omitempty"`
Language string `json:"language,omitempty"`
LinkCustomizationName string `json:"link_customization_name,omitempty"`
RedirectUri string `json:"redirect_uri,omitempty"`
AndroidPackageName string `json:"android_package_name,omitempty"`
}
type createLinkTokenRequest struct {
ClientID string `json:"client_id"`
Secret string `json:"secret"`
LinkTokenConfigs
}
type getLinkTokenRequest struct {
ClientID string `json:"client_id"`
Secret string `json:"secret"`
LinkToken string `json:"link_token"`
}
type CreateLinkTokenResponse struct {
APIResponse
LinkToken string `json:"link_token"`
Expiration time.Time `json:"expiration"`
}
type GetLinkTokenMetadataResponse struct {
InitialProducts []string `json:"initial_products"`
Webhook string `json:"webhook"`
CountryCodes []string `json:"country_codes"`
Language string `json:"language"`
AccountFilters *map[string]map[string][]string `json:"account_filters"`
RedirectURI string `json:"redirect_uri"`
ClientName string `json:"client_name"`
}
type GetLinkTokenResponse struct {
APIResponse
LinkToken string `json:"link_token"`
CreatedAt time.Time `json:"created_at"`
Expiration time.Time `json:"expiration"`
Metadata GetLinkTokenMetadataResponse `json:"metadata"`
}
func (c *Client) CreateLinkToken(configs LinkTokenConfigs) (resp CreateLinkTokenResponse, err error) {
jsonBody, err := json.Marshal(createLinkTokenRequest{
ClientID: c.clientID,
Secret: c.secret,
LinkTokenConfigs: configs,
})
if err != nil {
return resp, err
}
err = c.Call("/link/token/create", jsonBody, &resp)
return resp, err
}
func (c *Client) GetLinkToken(linkToken string) (resp GetLinkTokenResponse, err error) {
jsonBody, err := json.Marshal(getLinkTokenRequest{
ClientID: c.clientID,
Secret: c.secret,
LinkToken: linkToken,
})
if err != nil {
return resp, err
}
err = c.Call("/link/token/get", jsonBody, &resp)
return resp, err
}