Skip to content

Commit

Permalink
GET /personal/corp/settings (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtopc authored Sep 6, 2023
1 parent f49c880 commit b0e61d9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
31 changes: 26 additions & 5 deletions corporate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ var ErrEmptyAuthMaker = errors.New("authMaker is nil")
type CorporateAPI interface {
CommonAPI

// Auth initializes access.
// https://api.monobank.ua/docs/corporate.html#operation--personal-auth-request-post
// Settings returns information about company.
// https://api.monobank.ua/docs/corporate.html#tag/Avtorizaciya-ta-nalashtuvannya-kompaniyi/paths/~1personal~1corp~1settings/get
Settings(ctx context.Context) (*CorpSettings, error)

// Auth initializes client access.
// https://api.monobank.ua/docs/corporate.html#tag/Kliyentski-personalni-dani/paths/~1personal~1auth~1request/post
Auth(ctx context.Context, callbackURL string, permissions ...string) (*TokenRequest, error)

// CheckAuth checks status of request for client's personal data.
// https://api.monobank.ua/docs/corporate.html#operation--personal-auth-request-get
// https://api.monobank.ua/docs/corporate.html#tag/Kliyentski-personalni-dani/paths/~1personal~1auth~1request/get
CheckAuth(ctx context.Context, requestID string) error

// ClientInfo - https://api.monobank.ua/docs/corporate.html#operation--personal-client-info-get
// ClientInfo
// https://api.monobank.ua/docs/corporate.html#tag/Kliyentski-personalni-dani/paths/~1personal~1client-info/get
ClientInfo(ctx context.Context, requestID string) (*ClientInfo, error)

// Transactions - gets bank account statements(transactions)
// https://api.monobank.ua/docs/corporate.html#operation--personal-statement--account---from---to--get
// https://api.monobank.ua/docs/corporate.html#tag/Kliyentski-personalni-dani/paths/~1personal~1statement~1{account}~1{from}~1{to}/get
Transactions(ctx context.Context, requestID, accountID string, from, to time.Time) (Transactions, error)
}

Expand Down Expand Up @@ -106,6 +111,22 @@ func (c CorporateClient) Transactions(ctx context.Context, requestID, accountID
return authClient.commonClient.Transactions(ctx, accountID, from, to)
}

func (c CorporateClient) Settings(ctx context.Context) (*CorpSettings, error) {
const urlPath = "/personal/corp/settings"

authClient := c.withAuth(c.authMaker.New(""))

req, err := http.NewRequestWithContext(ctx, http.MethodGet, urlPath, http.NoBody)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}

var v CorpSettings
err = authClient.do(req, &v, http.StatusOK)

return &v, err
}

// withAuth returns copy of CorporateClient with authorizer
// TODO: remove?
func (c CorporateClient) withAuth(auth Authorizer) CorporateClient {
Expand Down
8 changes: 8 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,11 @@ type TokenRequest struct {
RequestID string `json:"tokenRequestId"` // Unique token request ID.
AcceptURL string `json:"acceptUrl"` // URL to redirect client or build QR on top of it.
}

type CorpSettings struct {
Pubkey string `json:"pubkey"`
Name string `json:"name"`
Permission string `json:"permission"`
Logo string `json:"logo"`
Webhook *string `json:"webhook"`
}

0 comments on commit b0e61d9

Please sign in to comment.