Compare commits

..

1 Commits

Author SHA1 Message Date
Bastian de Byl
5e2a2afd42 added OrderNotification, OrderNotifications, client.GetOrderNotifications 2023-09-25 13:05:05 -04:00
3 changed files with 49 additions and 10 deletions

View File

@@ -12,6 +12,8 @@ var (
orderUri = apiUri + ordersPath orderUri = apiUri + ordersPath
productsUri = apiUri + productsPath productsUri = apiUri + productsPath
validationUri = apiUri + validationPath validationUri = apiUri + validationPath
orderNotificationPath = "notifications"
) )
type Address struct { type Address struct {

View File

@@ -5,16 +5,16 @@ type NotificationType string
const ( const (
Processed OrderStatus = "Processed" Processed OrderStatus = "Processed"
Disputed = "Disputed" Disputed OrderStatus = "Disputed"
Shipped = "Shipped" Shipped OrderStatus = "Shipped"
Delivered = "Delivered" Delivered OrderStatus = "Delivered"
Pending = "Pending" Pending OrderStatus = "Pending"
Cancelled = "Cancelled" Cancelled OrderStatus = "Cancelled"
Dispatched = "Dispatched" Dispatched OrderStatus = "Dispatched"
Comment NotificationType = "Comment" Comment NotificationType = "Comment"
OrderStatusChanged = "OrderStatusChanged" OrderStatusChanged NotificationType = "OrderStatusChanged"
OrderShipped = "OrderShipped" OrderShipped NotificationType = "OrderShipped"
TrackingNumber = "TrackingNumber" TrackingNumber NotificationType = "TrackingNumber"
Invoice = "Invice" Invoice NotificationType = "Invice"
) )

View File

@@ -33,6 +33,23 @@ type OrderTax struct {
NumberForInvoice string `json:"numberForInvoice"` NumberForInvoice string `json:"numberForInvoice"`
} }
type OrderNotification struct {
Id string `json:"id"`
Created time.Time `json:"creationDate"`
Type NotificationType `json:"type"`
DeliveryMethod string `json:"deliveryMethod"`
Message string `json:"message,omitempty"`
SendDate time.Time `json:"sentOn,omitempty"`
Subject string `json:"subject,omitempty"`
}
type OrderNotifications struct {
TotalNotifications int `json:"totalItems"`
Offset int `json:"offset"`
Limit int `json:"limit"`
Notifications []OrderNotification `json:"items"`
}
type Order struct { type Order struct {
Token string `json:"token"` Token string `json:"token"`
Created time.Time `json:"creationDate"` Created time.Time `json:"creationDate"`
@@ -172,6 +189,26 @@ func (s *Client) GetOrder(token string) (*Order, error) {
return &order, nil return &order, nil
} }
func (s *Client) GetOrderNotifications(token string) (*OrderNotifications, error) {
response, err := helper.Get(orderUri+"/"+token+"/"+orderNotificationPath, "Basic", s.AuthBase64, nil)
if err != nil {
return nil, err
}
if response.StatusCode < 200 && response.StatusCode >= 300 {
return nil, fmt.Errorf("unexpected response received: %s", response.Status)
}
defer response.Body.Close()
var notifications OrderNotifications
err = json.NewDecoder(response.Body).Decode(&notifications)
if err != nil {
return nil, err
}
return &notifications, nil
}
func (s *Client) GetOrders(queries map[string]string) (*Orders, error) { func (s *Client) GetOrders(queries map[string]string) (*Orders, error) {
response, err := helper.Get(orderUri, "Basic", s.AuthBase64, queries) response, err := helper.Get(orderUri, "Basic", s.AuthBase64, queries)
if err != nil { if err != nil {