Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2fdeafc3c | ||
|
|
5e2a2afd42 | ||
|
|
d7c5fd3b74 |
2
go.mod
2
go.mod
@@ -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
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -33,39 +33,57 @@ 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"`
|
||||||
Modified time.Time `json:"modificationDate"`
|
Modified time.Time `json:"modificationDate"`
|
||||||
Completed time.Time `json:"completionDate"`
|
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"`
|
TotalTaxable float64 `json:"taxableTotal,omitempty"`
|
||||||
TotalTaxes float64 `json:"taxesTotal,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"`
|
ShippingAddressSameAsBilling bool `json:"shippingAddressSameAsBilling,omitempty"`
|
||||||
Name string `json:"shippingAddressName,omitempty"`
|
ShippingAddress Address `json:"shippingAddress,omitempty"`
|
||||||
Company string `json:"shippingAddressCompanyName,omitempty"`
|
Name string `json:"shippingAddressName,omitempty"`
|
||||||
Address1 string `json:"shippingAddressAddress1,omitempty"`
|
Company string `json:"shippingAddressCompanyName,omitempty"`
|
||||||
Address2 string `json:"shippingAddressAddress2,omitempty"`
|
Address1 string `json:"shippingAddressAddress1,omitempty"`
|
||||||
City string `json:"shippingAddressCity,omitempty"`
|
Address2 string `json:"shippingAddressAddress2,omitempty"`
|
||||||
Province string `json:"shippingAddressProvince,omitempty"`
|
City string `json:"shippingAddressCity,omitempty"`
|
||||||
Country string `json:"shippingAddressCountry,omitempty"`
|
Province string `json:"shippingAddressProvince,omitempty"`
|
||||||
PostalCode string `json:"shippingAddressPostalCode,omitempty"`
|
Country string `json:"shippingAddressCountry,omitempty"`
|
||||||
Phone string `json:"shippingAddressPhone,omitempty"`
|
PostalCode string `json:"shippingAddressPostalCode,omitempty"`
|
||||||
Email string `json:"email,omitempty"`
|
Phone string `json:"shippingAddressPhone,omitempty"`
|
||||||
TrackingNumber string `json:"trackingNumber"`
|
Email string `json:"email,omitempty"`
|
||||||
TrackingUrl string `json:"trackingUrl"`
|
TrackingNumber string `json:"trackingNumber"`
|
||||||
ShippingCost float64 `json:"shippingFees"`
|
TrackingUrl string `json:"trackingUrl"`
|
||||||
ShippingProvider string `json:"shippingProvider,omitempty"`
|
ShippingCost float64 `json:"shippingFees"`
|
||||||
ShippingMethod string `json:"shippingMethod,omitempty"`
|
ShippingProvider string `json:"shippingProvider,omitempty"`
|
||||||
ShippingRateId string `json:"shippingRateUserDefinedId,omitempty"`
|
ShippingMethod string `json:"shippingMethod,omitempty"`
|
||||||
Items []Item `json:"items"`
|
ShippingRateId string `json:"shippingRateUserDefinedId,omitempty"`
|
||||||
Taxes []OrderTax `json:"taxes,omitempty"`
|
Items []Item `json:"items"`
|
||||||
Metadata any `json:"metadata"`
|
Taxes []OrderTax `json:"taxes,omitempty"`
|
||||||
|
Metadata any `json:"metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderUpdate struct {
|
type OrderUpdate struct {
|
||||||
@@ -172,6 +190,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(¬ifications)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ¬ifications, 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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user