Documentation
¶
Index ¶
- type PlaidService
- type Service
- func (p *Service) GetAccessToken(ctx context.Context, publicToken string) (models.AccessResponse, error)
- func (p *Service) GetAccounts(ctx context.Context, accessToken string) ([]plaid.AccountBase, string, error)
- func (p *Service) GetBalances(ctx context.Context, accessToken string) (plaid.AccountsGetResponse, string, error)
- func (p *Service) GetItemInstitution(ctx context.Context, accessToken string) (string, error)
- func (p *Service) GetLinkToken(ctx context.Context, userID, webhookURL string) (string, error)
- func (p *Service) GetLinkTokenForUpdateMode(ctx context.Context, userID, accessToken, webhookURL string) (string, error)
- func (p *Service) GetTransactions(ctx context.Context, accessToken, cursor string) (added, modified []plaid.Transaction, removed []plaid.RemovedTransaction, ...)
- func (p *Service) GetWebhookVerificationKey(ctx context.Context, keyID string) (plaid.JWKPublicKey, error)
- func (p *Service) InvalidateAccessToken(ctx context.Context, accessToken models.AccessResponse) (models.AccessResponse, error)
- func (p *Service) RemoveItem(ctx context.Context, accessToken string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PlaidService ¶
type PlaidService interface {
GetLinkToken(ctx context.Context, userID, webhookURL string) (string, error)
GetLinkTokenForUpdateMode(ctx context.Context, userID, accessToken, webhookURL string) (string, error)
GetAccessToken(ctx context.Context, publicToken string) (models.AccessResponse, error)
InvalidateAccessToken(ctx context.Context, accessToken models.AccessResponse) (models.AccessResponse, error)
GetAccounts(ctx context.Context, accessToken string) ([]plaid.AccountBase, string, error)
GetItemInstitution(ctx context.Context, accessToken string) (string, error)
GetBalances(ctx context.Context, accessToken string) (plaid.AccountsGetResponse, string, error)
GetTransactions(ctx context.Context, accessToken, cursor string) (
added, modified []plaid.Transaction, removed []plaid.RemovedTransaction, nextCursor, reqID string, err error)
GetWebhookVerificationKey(ctx context.Context, keyID string) (plaid.JWKPublicKey, error)
RemoveItem(ctx context.Context, accessToken string) error
}
Plaid interface
type Service ¶
func NewPlaidService ¶
Creates a new APIClient for Plaid requests
func (*Service) GetAccessToken ¶
func (p *Service) GetAccessToken(ctx context.Context, publicToken string) (models.AccessResponse, error)
Exchanges a public token received from client for a permanent access token for item from Plaid API
func (*Service) GetAccounts ¶
func (p *Service) GetAccounts(ctx context.Context, accessToken string) ([]plaid.AccountBase, string, error)
Retrieves account data listed in a Plaid item
func (*Service) GetBalances ¶
func (p *Service) GetBalances(ctx context.Context, accessToken string) (plaid.AccountsGetResponse, string, error)
Updates account balances for item
func (*Service) GetItemInstitution ¶
Gets institution name for an item
func (*Service) GetLinkToken ¶
//Sandbox access token generation
func GetSandboxToken(p.Client *plaid.APIClient, ctx context.Context) (plaid.ItemPublicTokenExchangeResponse, error) {
sandboxPublicTokenResp, _, err := p.Client.PlaidApi.SandboxPublicTokenCreate(ctx).SandboxPublicTokenCreateRequest(
*plaid.NewSandboxPublicTokenCreateRequest(
"ins_109508",
[]plaid.Products{plaid.PRODUCTS_TRANSACTIONS},
),
).Execute()
if err != nil {
if apiErr, ok := err.(plaid.GenericOpenAPIError); ok {
fmt.Println("Plaid error body:", string(apiErr.Body()))
}
return plaid.ItemPublicTokenExchangeResponse{}, err
}
exchangePublicTokenResp, _, err := p.Client.PlaidApi.ItemPublicTokenExchange(ctx).ItemPublicTokenExchangeRequest(
*plaid.NewItemPublicTokenExchangeRequest(sandboxPublicTokenResp.GetPublicToken()),
).Execute()
if err != nil {
if apiErr, ok := err.(plaid.GenericOpenAPIError); ok {
fmt.Println("Plaid error body:", string(apiErr.Body()))
}
return plaid.ItemPublicTokenExchangeResponse{}, err
}
return exchangePublicTokenResp, nil
}
Requests Plaid API for a Link token for p.Client use
func (*Service) GetLinkTokenForUpdateMode ¶
func (p *Service) GetLinkTokenForUpdateMode(ctx context.Context, userID, accessToken, webhookURL string) (string, error)
Requests Plaid API for a Link token configured with a user's access token, to initiate Update mode
func (*Service) GetTransactions ¶
func (p *Service) GetTransactions(ctx context.Context, accessToken, cursor string) ( added, modified []plaid.Transaction, removed []plaid.RemovedTransaction, nextCursor, reqID string, err error, )
Called by transactions/sync Plaid endpoint, getting all transaction data for a specific account. Returns last Plaid request ID in loop
func (*Service) GetWebhookVerificationKey ¶
func (p *Service) GetWebhookVerificationKey(ctx context.Context, keyID string) (plaid.JWKPublicKey, error)
Gets the webhook verification key from Plaid
func (*Service) InvalidateAccessToken ¶
func (p *Service) InvalidateAccessToken(ctx context.Context, accessToken models.AccessResponse) (models.AccessResponse, error)
Invalidates an item's access token, requesting a new one from Plaid API