Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2fdeafc3c | ||
|
|
5e2a2afd42 | ||
|
|
d7c5fd3b74 | ||
|
|
b586a3184c |
2
go.mod
2
go.mod
@@ -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
|
||||
)
|
||||
|
||||
@@ -12,6 +12,8 @@ var (
|
||||
orderUri = apiUri + ordersPath
|
||||
productsUri = apiUri + productsPath
|
||||
validationUri = apiUri + validationPath
|
||||
|
||||
orderNotificationPath = "notifications"
|
||||
)
|
||||
|
||||
type Address struct {
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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"`
|
||||
@@ -43,8 +60,10 @@ type Order struct {
|
||||
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"`
|
||||
ShippingAddressSameAsBilling bool `json:"shippingAddressSameAsBilling,omitempty"`
|
||||
ShippingAddress Address `json:"shippingAddress,omitempty"`
|
||||
Name string `json:"shippingAddressName,omitempty"`
|
||||
Company string `json:"shippingAddressCompanyName,omitempty"`
|
||||
@@ -171,6 +190,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 {
|
||||
|
||||
Reference in New Issue
Block a user