diff --git a/snipcart/common.go b/snipcart/common.go index b8db1c4..595f57e 100644 --- a/snipcart/common.go +++ b/snipcart/common.go @@ -12,6 +12,8 @@ var ( orderUri = apiUri + ordersPath productsUri = apiUri + productsPath validationUri = apiUri + validationPath + + orderNotificationPath = "notifications" ) type Address struct { diff --git a/snipcart/enums.go b/snipcart/enums.go index 355bd9d..d354e1b 100644 --- a/snipcart/enums.go +++ b/snipcart/enums.go @@ -5,16 +5,16 @@ type NotificationType string const ( Processed OrderStatus = "Processed" - Disputed = "Disputed" - Shipped = "Shipped" - Delivered = "Delivered" - Pending = "Pending" - Cancelled = "Cancelled" - Dispatched = "Dispatched" + Disputed OrderStatus = "Disputed" + Shipped OrderStatus = "Shipped" + Delivered OrderStatus = "Delivered" + Pending OrderStatus = "Pending" + Cancelled OrderStatus = "Cancelled" + Dispatched OrderStatus = "Dispatched" Comment NotificationType = "Comment" - OrderStatusChanged = "OrderStatusChanged" - OrderShipped = "OrderShipped" - TrackingNumber = "TrackingNumber" - Invoice = "Invice" + OrderStatusChanged NotificationType = "OrderStatusChanged" + OrderShipped NotificationType = "OrderShipped" + TrackingNumber NotificationType = "TrackingNumber" + Invoice NotificationType = "Invice" ) diff --git a/snipcart/snipcart.go b/snipcart/snipcart.go index 95bf470..6ca86c3 100644 --- a/snipcart/snipcart.go +++ b/snipcart/snipcart.go @@ -33,6 +33,23 @@ type OrderTax struct { 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 { Token string `json:"token"` Created time.Time `json:"creationDate"` @@ -172,6 +189,26 @@ func (s *Client) GetOrder(token string) (*Order, error) { 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(¬ifications) + if err != nil { + return nil, err + } + + return ¬ifications, nil +} + func (s *Client) GetOrders(queries map[string]string) (*Orders, error) { response, err := helper.Get(orderUri, "Basic", s.AuthBase64, queries) if err != nil {