Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e2a2afd42 | ||
|
|
d7c5fd3b74 | ||
|
|
b586a3184c | ||
|
|
805491571c | ||
|
|
10a9427598 | ||
|
|
3816c67b95 | ||
|
|
c18376739b | ||
|
|
6d85149be8 | ||
|
|
cf4ad9642d | ||
|
|
e1adf8cf4f | ||
|
|
73195a090f | ||
|
|
db81f246bf | ||
|
|
9c7218f937 | ||
|
|
543935289f |
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 {
|
||||
@@ -37,6 +39,9 @@ type Client struct {
|
||||
}
|
||||
|
||||
type CustomField struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Options string `json:"options,omitempty"`
|
||||
Required bool `json:"required"`
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -26,35 +26,63 @@ type Item struct {
|
||||
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 {
|
||||
Token string `json:"token"`
|
||||
Created time.Time `json:"creationDate"`
|
||||
Modified time.Time `json:"modificationDate"`
|
||||
Invoice string `json:"invoiceNumber"`
|
||||
Subtotal float64 `json:"subtotal,omitempty"`
|
||||
Currency string `json:"currency,omitempty"`
|
||||
Total float64 `json:"grandTotal,omitempty"`
|
||||
Status string `json:"status"`
|
||||
TotalWeight float64 `json:"totalWeight"`
|
||||
ShippingAddress Address `json:"shippingAddress,omitempty"`
|
||||
Name string `json:"shippingAddressName,omitempty"`
|
||||
Company string `json:"shippingAddressCompanyName,omitempty"`
|
||||
Address1 string `json:"shippingAddressAddress1,omitempty"`
|
||||
Address2 string `json:"shippingAddressAddress2,omitempty"`
|
||||
City string `json:"shippingAddressCity,omitempty"`
|
||||
Province string `json:"shippingAddressProvince,omitempty"`
|
||||
Country string `json:"shippingAddressCountry,omitempty"`
|
||||
PostalCode string `json:"shippingAddressPostalCode,omitempty"`
|
||||
Phone string `json:"shippingAddressPhone,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
TrackingNumber string `json:"trackingNumber"`
|
||||
TrackingUrl string `json:"trackingUrl"`
|
||||
ShippingCost float64 `json:"shippingFees"`
|
||||
ShippingProvider string `json:"shippingProvider,omitempty"`
|
||||
ShippingMethod string `json:"shippingMethod,omitempty"`
|
||||
ShippingRateId string `json:"shippingRateUserDefinedId,omitempty"`
|
||||
Items []Item `json:"items"`
|
||||
Metadata any `json:"metadata"`
|
||||
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"`
|
||||
Name string `json:"shippingAddressName,omitempty"`
|
||||
Company string `json:"shippingAddressCompanyName,omitempty"`
|
||||
Address1 string `json:"shippingAddressAddress1,omitempty"`
|
||||
Address2 string `json:"shippingAddressAddress2,omitempty"`
|
||||
City string `json:"shippingAddressCity,omitempty"`
|
||||
Province string `json:"shippingAddressProvince,omitempty"`
|
||||
Country string `json:"shippingAddressCountry,omitempty"`
|
||||
PostalCode string `json:"shippingAddressPostalCode,omitempty"`
|
||||
Phone string `json:"shippingAddressPhone,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
TrackingNumber string `json:"trackingNumber"`
|
||||
TrackingUrl string `json:"trackingUrl"`
|
||||
ShippingCost float64 `json:"shippingFees"`
|
||||
ShippingProvider string `json:"shippingProvider,omitempty"`
|
||||
ShippingMethod string `json:"shippingMethod,omitempty"`
|
||||
ShippingRateId string `json:"shippingRateUserDefinedId,omitempty"`
|
||||
Items []Item `json:"items"`
|
||||
Taxes []OrderTax `json:"taxes,omitempty"`
|
||||
Metadata any `json:"metadata"`
|
||||
}
|
||||
|
||||
type OrderUpdate struct {
|
||||
@@ -68,6 +96,8 @@ type OrderUpdate struct {
|
||||
|
||||
type Orders struct {
|
||||
TotalItems int
|
||||
Offest int
|
||||
Limit int
|
||||
Items []Order
|
||||
}
|
||||
|
||||
@@ -159,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 {
|
||||
|
||||
@@ -4,17 +4,25 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ShippingError struct {
|
||||
Key string `json:"key"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type ShippingErrors struct {
|
||||
Errors []ShippingError `json:"errors"`
|
||||
}
|
||||
|
||||
type TaxShippingInfo struct {
|
||||
Fees float64 `json:"fees"`
|
||||
Method string `json:"method"`
|
||||
}
|
||||
|
||||
type TaxContent struct {
|
||||
Created time.Time `json:"creationDate"`
|
||||
Modified time.Time `json:"modificationDate"`
|
||||
Created int `json:"creationDate"`
|
||||
Modified int `json:"modificationDate"`
|
||||
Token string `json:"token"`
|
||||
Email string `json:"email"`
|
||||
ShipToBillingAddress bool `json:"shipToBillingAddress"`
|
||||
@@ -38,6 +46,10 @@ type TaxContent struct {
|
||||
Metadata any `json:"metadata"`
|
||||
}
|
||||
|
||||
type TaxWebhook struct {
|
||||
Content TaxContent `json:"content"`
|
||||
}
|
||||
|
||||
type Tax struct {
|
||||
Name string `json:"name"`
|
||||
Amount float64 `json:"amount"`
|
||||
|
||||
Reference in New Issue
Block a user