Compare commits

...

7 Commits

Author SHA1 Message Date
Bastian de Byl
5e2a2afd42 added OrderNotification, OrderNotifications, client.GetOrderNotifications 2023-09-25 13:05:05 -04:00
Bastian de Byl
d7c5fd3b74 updated helpers for Get request fix 2023-09-13 13:48:50 -04:00
Bastian de Byl
b586a3184c added TotalTaxes to Order 2023-08-11 11:29:15 -04:00
Bastian de Byl
805491571c added missing Completed field for completion date of order 2023-07-29 17:34:01 -04:00
Bastian de Byl
10a9427598 corrected CustomField.Options field to string from []string 2023-07-27 13:48:13 -04:00
Bastian de Byl
3816c67b95 added more data types to CustomField struct 2023-07-27 13:44:06 -04:00
Bastian de Byl
c18376739b added TotalTaxable to Order 2023-07-03 13:31:26 -04:00
4 changed files with 58 additions and 13 deletions

2
go.mod
View File

@@ -3,7 +3,7 @@ module github.com/debyltech/go-snipcart
go 1.19
require (
github.com/debyltech/go-helpers v1.1.0
github.com/debyltech/go-helpers v1.1.1
github.com/debyltech/go-shippr v0.1.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
)

View File

@@ -12,6 +12,8 @@ var (
orderUri = apiUri + ordersPath
productsUri = apiUri + productsPath
validationUri = apiUri + validationPath
orderNotificationPath = "notifications"
)
type Address struct {
@@ -39,4 +41,7 @@ type Client struct {
type CustomField struct {
Name string `json:"name"`
Value string `json:"value"`
Type string `json:"type,omitempty"`
Options string `json:"options,omitempty"`
Required bool `json:"required"`
}

View File

@@ -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"
)

View File

@@ -33,14 +33,34 @@ 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"`
Modified time.Time `json:"modificationDate"`
Completed time.Time `json:"completionDate"`
Invoice string `json:"invoiceNumber"`
Subtotal float64 `json:"subtotal,omitempty"`
Currency string `json:"currency,omitempty"`
Total float64 `json:"grandTotal,omitempty"`
TotalTaxable float64 `json:"taxableTotal,omitempty"`
TotalTaxes float64 `json:"taxesTotal,omitempty"`
Status string `json:"status"`
TotalWeight float64 `json:"totalWeight"`
ShippingAddress Address `json:"shippingAddress,omitempty"`
@@ -169,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(&notifications)
if err != nil {
return nil, err
}
return &notifications, nil
}
func (s *Client) GetOrders(queries map[string]string) (*Orders, error) {
response, err := helper.Get(orderUri, "Basic", s.AuthBase64, queries)
if err != nil {