diff --git a/partnerapi/kiotviet/const.go b/partnerapi/kiotviet/const.go index e537320..88f12c4 100644 --- a/partnerapi/kiotviet/const.go +++ b/partnerapi/kiotviet/const.go @@ -3,6 +3,7 @@ package kiotviet const ( apiPathListBranches = "/branches" apiPathListProductOnHands = "/productOnHands" + apiPathListWebhook = "/webhooks" apiPathRegisterWebhook = "/webhooks" apiPathUnregisterWebhook = "/webhooks/%d" // %s -> webhook id diff --git a/partnerapi/kiotviet/kiotviet.go b/partnerapi/kiotviet/kiotviet.go index 38800dd..7730733 100644 --- a/partnerapi/kiotviet/kiotviet.go +++ b/partnerapi/kiotviet/kiotviet.go @@ -122,6 +122,34 @@ func (c *Client) GetBranches(req ListBranchesReq) (*ListBranchesRes, error) { return &data, nil } +func (c *Client) ListWebhooks(req ListWebhookReq) (*ListWebhookRes, error) { + apiURL := c.getURL(apiPathListWebhook) + natsPayload := model.CommunicationRequestHttp{ + ResponseImmediately: true, + Payload: model.HttpRequest{ + URL: apiURL, + Method: http.MethodGet, + Header: c.getRequestHeader(), + }, + LogTarget: logTarget, + } + + r, err := c.requestHttpViaNats(natsPayload) + if err != nil { + log.Printf("kiotviet.Client.ListWebhooks - requestHttpViaNats: %v, %s\n", err, apiURL) + return nil, err + } + res := r.Response + if res.StatusCode >= http.StatusBadRequest { + return nil, fmt.Errorf("kiotviet.Client.ListWebhooks - requestHttpViaNats bad request %s", res.Body) + } + var data ListWebhookRes + if err = r.ParseResponseData(&data); err != nil { + return nil, fmt.Errorf("kiotviet.Client.ListWebhooks - requestHttpViaNats parse response %v, %s", err, res.Body) + } + return &data, nil +} + func (c *Client) RegisterWebhook(req RegisterWebhookReq) (*RegisterWebhookRes, error) { apiURL := c.getURL(apiPathRegisterWebhook) natsPayload := model.CommunicationRequestHttp{ diff --git a/partnerapi/kiotviet/model_req.go b/partnerapi/kiotviet/model_req.go index 1520e89..1fe10f1 100644 --- a/partnerapi/kiotviet/model_req.go +++ b/partnerapi/kiotviet/model_req.go @@ -23,6 +23,9 @@ type ListBranchesReq struct { IncludeRemoveIDs string `json:"includeRemoveIds,omitempty"` // true/ false } +type ListWebhookReq struct { +} + type WebhookReq struct { Type string `json:"Type"` Url string `json:"Url"` diff --git a/partnerapi/kiotviet/model_res.go b/partnerapi/kiotviet/model_res.go index a13b2ed..7414ea2 100644 --- a/partnerapi/kiotviet/model_res.go +++ b/partnerapi/kiotviet/model_res.go @@ -67,3 +67,19 @@ type RError struct { ErrorCode string `json:"errorCode"` Message string `json:"message"` } + +type Webhook struct { + Id int `json:"id"` + Type string `json:"type"` + Url string `json:"url"` + IsActive bool `json:"isActive"` + RetailerId int `json:"retailerId"` + ModifiedDate time.Time `json:"modifiedDate"` +} + +type ListWebhookRes struct { + Total int `json:"total"` + PageSize int `json:"pageSize"` + Data []Webhook `json:"data"` + Timestamp time.Time `json:"timestamp"` +}