From c6a7cc211096d5b576c41c781fd8d37426e2c8d3 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:43:46 +0300 Subject: [PATCH 1/3] GET /personal/corp/settings --- corporate.go | 33 ++++++++++++++++++++++++++++----- types.go | 8 ++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/corporate.go b/corporate.go index 4512e77..d0c8572 100644 --- a/corporate.go +++ b/corporate.go @@ -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 + // 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) } @@ -106,6 +111,24 @@ func (c CorporateClient) Transactions(ctx context.Context, requestID, accountID return authClient.commonClient.Transactions(ctx, accountID, from, to) } +// Settings +// https://api.monobank.ua/docs/corporate.html#tag/Avtorizaciya-ta-nalashtuvannya-kompaniyi/paths/~1personal~1corp~1settings/get +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 { diff --git a/types.go b/types.go index 3d76c9d..44fd828 100644 --- a/types.go +++ b/types.go @@ -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 []byte `json:"pubkey"` + Name string `json:"name"` + Permission string `json:"permission"` + Logo []byte `json:"logo"` + Webhook string `json:"webhook"` +} From 3b73b37239b2522d03351a580ad776e622609d64 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:46:10 +0300 Subject: [PATCH 2/3] doc --- corporate.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/corporate.go b/corporate.go index d0c8572..8a254ee 100644 --- a/corporate.go +++ b/corporate.go @@ -13,7 +13,7 @@ var ErrEmptyAuthMaker = errors.New("authMaker is nil") type CorporateAPI interface { CommonAPI - // Settings + // 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) @@ -111,8 +111,6 @@ func (c CorporateClient) Transactions(ctx context.Context, requestID, accountID return authClient.commonClient.Transactions(ctx, accountID, from, to) } -// Settings -// https://api.monobank.ua/docs/corporate.html#tag/Avtorizaciya-ta-nalashtuvannya-kompaniyi/paths/~1personal~1corp~1settings/get func (c CorporateClient) Settings(ctx context.Context) (*CorpSettings, error) { const urlPath = "/personal/corp/settings" From b8b20d0d7bd246cb7e4b1d2f2eed3d695c139fb1 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Wed, 6 Sep 2023 17:27:00 +0300 Subject: [PATCH 3/3] strings --- types.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/types.go b/types.go index 44fd828..712f052 100644 --- a/types.go +++ b/types.go @@ -111,9 +111,9 @@ type TokenRequest struct { } type CorpSettings struct { - Pubkey []byte `json:"pubkey"` - Name string `json:"name"` - Permission string `json:"permission"` - Logo []byte `json:"logo"` - Webhook string `json:"webhook"` + Pubkey string `json:"pubkey"` + Name string `json:"name"` + Permission string `json:"permission"` + Logo string `json:"logo"` + Webhook *string `json:"webhook"` }