Skip to content

Commit

Permalink
feat: implement get webhook config endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vitords committed Oct 24, 2023
1 parent 39b1085 commit bf57303
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -58,6 +57,9 @@ type Client interface {
ctx context.Context,
request *ListTeamsRequest,
) (*ListTeamsResponse, error)

// Webhooks
GetWebhookConfig(ctx context.Context) (*GetWebhookConfigResponse, error)
}

// clientImpl to the Monta Partner API.
Expand Down Expand Up @@ -225,7 +227,7 @@ func execute[T any](
if httpResponse.StatusCode != http.StatusOK && httpResponse.StatusCode != http.StatusCreated {
return nil, newStatusError(httpResponse)
}
respBody, err := ioutil.ReadAll(httpResponse.Body)
respBody, err := io.ReadAll(httpResponse.Body)
if err != nil {
return nil, err
}
Expand Down
23 changes: 23 additions & 0 deletions client_webhooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package monta

import (
"context"
"net/url"
)

// GetWebhookConfigResponse is the response output from the [Client.GetWebhookConfig] method.
type GetWebhookConfigResponse struct {
// A HTTPS URL to send the webhook payload to when an event occurs.
WebhookURL string `json:"webhookUrl"`
// A cryptoghrapic secret used to sign the webhook payload.
WebhookSecret string `json:"webhookSecret"`
// A list of event types to subscribe to. Use of ["*"] means subscribe to all.
EventTypes []*WebhookEventType `json:"eventTypes"`
}

// GetWebhookConfig to get your webhook config.
func (c *clientImpl) GetWebhookConfig(ctx context.Context) (*GetWebhookConfigResponse, error) {
path := "/v1/webhooks/config"
query := url.Values{}
return doGet[GetWebhookConfigResponse](ctx, c, path, query)
}
1 change: 1 addition & 0 deletions scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ const (
ScopeChargeTransactions Scope = "charge-transactions"
ScopeWalletTransactions Scope = "wallet-transactions"
ScopeControlCharging Scope = "control-charging"
ScopeManageWebhooks Scope = "manage-webhooks"
)

0 comments on commit bf57303

Please sign in to comment.