Compare commits

...

11 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
Bastian de Byl
6d85149be8 corrected Taxes to Order (new OrderTax struct) 2023-07-03 13:21:06 -04:00
Bastian de Byl
cf4ad9642d added Taxes to Order (omitempty) 2023-07-03 13:18:42 -04:00
Bastian de Byl
e1adf8cf4f added Offset and Limit to Orders struct 2023-07-03 12:14:40 -04:00
Bastian de Byl
73195a090f added ShippingError and ShippingErrors struct 2023-06-06 19:54:21 -04:00
5 changed files with 105 additions and 41 deletions

2
go.mod
View File

@@ -3,7 +3,7 @@ module github.com/debyltech/go-snipcart
go 1.19 go 1.19
require ( 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/debyltech/go-shippr v0.1.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
) )

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 {
@@ -39,4 +41,7 @@ type Client struct {
type CustomField struct { type CustomField struct {
Name string `json:"name"` Name string `json:"name"`
Value string `json:"value"` 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 ( 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

@@ -26,14 +26,41 @@ type Item struct {
Shippable bool `json:"shippable,omitempty"` Shippable bool `json:"shippable,omitempty"`
} }
type OrderTax struct {
Name string `json:"taxName"`
Rate float64 `json:"taxRate"`
Amount float64 `json:"amount"`
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"`
Modified time.Time `json:"modificationDate"` Modified time.Time `json:"modificationDate"`
Completed time.Time `json:"completionDate"`
Invoice string `json:"invoiceNumber"` Invoice string `json:"invoiceNumber"`
Subtotal float64 `json:"subtotal,omitempty"` Subtotal float64 `json:"subtotal,omitempty"`
Currency string `json:"currency,omitempty"` Currency string `json:"currency,omitempty"`
Total float64 `json:"grandTotal,omitempty"` Total float64 `json:"grandTotal,omitempty"`
TotalTaxable float64 `json:"taxableTotal,omitempty"`
TotalTaxes float64 `json:"taxesTotal,omitempty"`
Status string `json:"status"` Status string `json:"status"`
TotalWeight float64 `json:"totalWeight"` TotalWeight float64 `json:"totalWeight"`
ShippingAddress Address `json:"shippingAddress,omitempty"` ShippingAddress Address `json:"shippingAddress,omitempty"`
@@ -54,6 +81,7 @@ type Order struct {
ShippingMethod string `json:"shippingMethod,omitempty"` ShippingMethod string `json:"shippingMethod,omitempty"`
ShippingRateId string `json:"shippingRateUserDefinedId,omitempty"` ShippingRateId string `json:"shippingRateUserDefinedId,omitempty"`
Items []Item `json:"items"` Items []Item `json:"items"`
Taxes []OrderTax `json:"taxes,omitempty"`
Metadata any `json:"metadata"` Metadata any `json:"metadata"`
} }
@@ -68,6 +96,8 @@ type OrderUpdate struct {
type Orders struct { type Orders struct {
TotalItems int TotalItems int
Offest int
Limit int
Items []Order Items []Order
} }
@@ -159,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 {

View File

@@ -6,6 +6,15 @@ import (
"net/http" "net/http"
) )
type ShippingError struct {
Key string `json:"key"`
Message string `json:"message"`
}
type ShippingErrors struct {
Errors []ShippingError `json:"errors"`
}
type TaxShippingInfo struct { type TaxShippingInfo struct {
Fees float64 `json:"fees"` Fees float64 `json:"fees"`
Method string `json:"method"` Method string `json:"method"`