Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enhance Go SDK with New Account Features #148

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
const (
accountsPath = "accounts"
entitiesPath = "entities"
membersPath = "members"
filesPath = "files"
instrumentsPath = "instruments"
payoutSchedulesPath = "payout-schedules"
filesPath = "files"
paymentInstrumentsPath = "payment-instruments"
)

Expand All @@ -21,6 +22,21 @@ const (
Government AccountHolderType = "government"
)

type InstrumentStatus string

const (
Verified InstrumentStatus = "verified"
Unverified InstrumentStatus = "unverified"
InstrumentPending InstrumentStatus = "pending"
)

type (
InstrumentDocument struct {
Type string `json:"type,omitempty"`
FileId string `json:"file_id,omitempty"`
}
)

type (
AccountHolder struct {
Type AccountHolderType `json:"type,omitempty"`
Expand Down
169 changes: 128 additions & 41 deletions accounts/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,59 @@ func NewClient(
}
}

func (c *Client) SubmitFile(file File) (*common.IdResponse, error) {
func (c *Client) CreateEntity(request OnboardEntityRequest) (*OnboardEntityResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}

req, err := common.BuildFileUploadRequest(&file)
var response OnboardEntityResponse
err = c.apiClient.Post(
common.BuildPath(accountsPath, entitiesPath),
auth,
request,
&response,
nil,
)
if err != nil {
return nil, err
}

var response common.IdResponse
err = c.filesClient.Upload(common.BuildPath(filesPath), auth, req, &response)
return &response, nil
}

func (c *Client) GetSubEntityMembers(entityId string) (*OnboardSubEntityDetailsResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}

var response OnboardSubEntityDetailsResponse
err = c.apiClient.Get(
common.BuildPath(accountsPath, entitiesPath, entityId, membersPath),
auth,
&response,
)
if err != nil {
return nil, err
}

return &response, nil
}

func (c *Client) CreateEntity(request OnboardEntityRequest) (*OnboardEntityResponse, error) {
func (c *Client) ReinviteSubEntityMember(
entityId string,
userId string,
request OnboardSubEntityRequest,
) (*OnboardSubEntityResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}

var response OnboardEntityResponse
err = c.apiClient.Post(
common.BuildPath(accountsPath, entitiesPath),
var response OnboardSubEntityResponse
err = c.apiClient.Put(
common.BuildPath(accountsPath, entitiesPath, entityId, membersPath, userId),
auth,
request,
&response,
Expand Down Expand Up @@ -156,31 +180,48 @@ func (c *Client) CreatePaymentInstrument(
return &response, nil
}

func (c *Client) QueryPaymentInstruments(
func (c *Client) RetrievePaymentInstrumentDetails(
entityId string,
query PaymentInstrumentsQuery,
) (*PaymentInstrumentQueryResponse, error) {
paymentInstrumentId string,
) (*PaymentInstrumentDetailsResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}

url, err := common.BuildQueryPath(
var response PaymentInstrumentDetailsResponse
err = c.apiClient.Get(
common.BuildPath(
accountsPath,
entitiesPath,
entityId,
paymentInstrumentsPath,
), query)
paymentInstrumentId,
),
auth,
&response,
)
if err != nil {
return nil, err
}

return &response, nil
}

func (c *Client) UpdatePaymentInstrumentDetails(
entityId, instrumentId string,
request UpdatePaymentInstrumentRequest,
) (*common.IdResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}

var response PaymentInstrumentQueryResponse
err = c.apiClient.Get(
url,
var response common.IdResponse
err = c.apiClient.Patch(
common.BuildPath(accountsPath, entitiesPath, entityId, paymentInstrumentsPath, instrumentId),
auth,
request,
&response,
)
if err != nil {
Expand All @@ -190,48 +231,31 @@ func (c *Client) QueryPaymentInstruments(
return &response, nil
}

func (c *Client) RetrievePaymentInstrumentDetails(
func (c *Client) QueryPaymentInstruments(
entityId string,
paymentInstrumentId string,
) (*PaymentInstrumentDetailsResponse, error) {
query PaymentInstrumentsQuery,
) (*PaymentInstrumentQueryResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}

var response PaymentInstrumentDetailsResponse
err = c.apiClient.Get(
url, err := common.BuildQueryPath(
common.BuildPath(
accountsPath,
entitiesPath,
entityId,
paymentInstrumentsPath,
paymentInstrumentId,
),
auth,
&response,
)
if err != nil {
return nil, err
}

return &response, nil
}
), query)

func (c *Client) UpdatePaymentInstrumentDetails(
entityId, instrumentId string,
request UpdatePaymentInstrumentRequest,
) (*common.IdResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}

var response common.IdResponse
err = c.apiClient.Patch(
common.BuildPath(accountsPath, entitiesPath, entityId, paymentInstrumentsPath, instrumentId),
var response PaymentInstrumentQueryResponse
err = c.apiClient.Get(
url,
auth,
request,
&response,
)
if err != nil {
Expand Down Expand Up @@ -288,3 +312,66 @@ func (c *Client) UpdatePayoutSchedule(

return &response, nil
}

func (c *Client) SubmitFile(file File) (*common.IdResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}

req, err := common.BuildFileUploadRequest(&file)
if err != nil {
return nil, err
}

var response common.IdResponse
err = c.filesClient.Upload(common.BuildPath(filesPath), auth, req, &response)
if err != nil {
return nil, err
}

return &response, nil
}

func (c *Client) UploadFile(
entityId string,
request File,
) (*UploadFileResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}

var response UploadFileResponse
err = c.apiClient.Post(
common.BuildPath(accountsPath, entityId, filesPath),
auth,
request,
&response,
nil,
)
if err != nil {
return nil, err
}

return &response, nil
}

func (c *Client) RetrieveFile(entityId, fileId string) (*FileDetailsResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}

var response FileDetailsResponse
err = c.apiClient.Get(
common.BuildPath(accountsPath, entityId, filesPath, fileId),
auth,
&response,
)
if err != nil {
return nil, err
}

return &response, nil
}
Loading
Loading