Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13f482e50a | ||
|
|
bfb6497d25 | ||
|
|
82b88cbaf5 | ||
|
|
994cabc20e | ||
|
|
bde3d07c28 | ||
|
|
0bf0abd435 | ||
|
|
82106ee4e0 |
@@ -7,10 +7,6 @@ import (
|
|||||||
"github.com/debyltech/go-snipcart/snipcart"
|
"github.com/debyltech/go-snipcart/snipcart"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
configFile = "config.json"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
snipcartApiKey := flag.String("key", "", "Snipcart API Key")
|
snipcartApiKey := flag.String("key", "", "Snipcart API Key")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -3,6 +3,6 @@ module github.com/debyltech/go-snipcart
|
|||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/debyltech/go-helpers v0.0.0-20230224002154-eb55816c71ec
|
github.com/debyltech/go-helpers v1.0.5
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -60,6 +60,14 @@ type SnipcartOrder struct {
|
|||||||
Items []SnipcartItem `json:"items"`
|
Items []SnipcartItem `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SnipcartOrderUpdate struct {
|
||||||
|
Status OrderStatus `json:"status"`
|
||||||
|
PaymentStatus string `json:"paymentStatus,omitempty"`
|
||||||
|
TrackingNumber string `json:"trackingNumber,omitempty"`
|
||||||
|
TrackingUrl string `json:"trackingUrl,omitempty"`
|
||||||
|
Metadata any `json:"metadata,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type SnipcartOrders struct {
|
type SnipcartOrders struct {
|
||||||
TotalItems int
|
TotalItems int
|
||||||
Items []SnipcartOrder
|
Items []SnipcartOrder
|
||||||
@@ -77,7 +85,7 @@ func (s *SnipcartProvider) GetOrder(token string) (*SnipcartOrder, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if response.Status != "200 OK" {
|
if response.StatusCode < 200 && response.StatusCode >= 300 {
|
||||||
return nil, fmt.Errorf("unexpected response received: %s", response.Status)
|
return nil, fmt.Errorf("unexpected response received: %s", response.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +105,7 @@ func (s *SnipcartProvider) GetOrders(queries map[string]string) (*SnipcartOrders
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if response.Status != "200 OK" {
|
if response.StatusCode < 200 && response.StatusCode >= 300 {
|
||||||
return nil, fmt.Errorf("unexpected response received: %s", response.Status)
|
return nil, fmt.Errorf("unexpected response received: %s", response.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,3 +136,24 @@ func (o *SnipcartOrder) TokenPNGBase64() (string, error) {
|
|||||||
|
|
||||||
return base64.StdEncoding.EncodeToString(img), nil
|
return base64.StdEncoding.EncodeToString(img), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SnipcartProvider) UpdateOrder(token string, orderUpdate *SnipcartOrderUpdate) (*SnipcartOrder, error) {
|
||||||
|
response, err := helper.Put(orderUri+"/"+token, "Basic", s.AuthBase64, orderUpdate)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if response.StatusCode < 200 && response.StatusCode >= 300 {
|
||||||
|
return nil, fmt.Errorf("unexpected response received: %s", response.Status)
|
||||||
|
}
|
||||||
|
fmt.Println(response.Status)
|
||||||
|
|
||||||
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
var responseOrder SnipcartOrder
|
||||||
|
err = json.NewDecoder(response.Body).Decode(&responseOrder)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &responseOrder, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user