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

GET /personal/corp/settings #34

Merged
merged 3 commits into from
Sep 6, 2023
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
31 changes: 26 additions & 5 deletions corporate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@
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 @@
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)
}

Check warning on line 122 in corporate.go

View check run for this annotation

Codecov / codecov/patch

corporate.go#L114-L122

Added lines #L114 - L122 were not covered by tests

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

return &v, err

Check warning on line 127 in corporate.go

View check run for this annotation

Codecov / codecov/patch

corporate.go#L124-L127

Added lines #L124 - L127 were not covered by tests
}

// 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"`
}
Loading