Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d91d1d122 | ||
|
|
13f482e50a | ||
|
|
bfb6497d25 | ||
|
|
82b88cbaf5 | ||
|
|
994cabc20e | ||
|
|
bde3d07c28 | ||
|
|
0bf0abd435 |
@@ -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()
|
||||||
|
|||||||
33
example_get_order.go
Normal file
33
example_get_order.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/debyltech/go-snipcart/snipcart"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
snipcartApiKey := flag.String("key", "", "Snipcart API Key")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if *snipcartApiKey == "" {
|
||||||
|
log.Fatal("missing -key flag")
|
||||||
|
}
|
||||||
|
|
||||||
|
snipcartProvider := snipcart.NewSnipcartProvider(*snipcartApiKey)
|
||||||
|
|
||||||
|
response, err := snipcartProvider.GetOrder("b35990df-c0ca-4014-94de-1caa7bd7bb51")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
byteResponse, err := json.Marshal(response)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(byteResponse))
|
||||||
|
}
|
||||||
32
example_update_order.go
Normal file
32
example_update_order.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/debyltech/go-snipcart/snipcart"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
snipcartApiKey := flag.String("key", "", "Snipcart API Key")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if *snipcartApiKey == "" {
|
||||||
|
log.Fatal("missing -key flag")
|
||||||
|
}
|
||||||
|
|
||||||
|
snipcartProvider := snipcart.NewSnipcartProvider(*snipcartApiKey)
|
||||||
|
|
||||||
|
updateOrder := snipcart.SnipcartOrderUpdate{
|
||||||
|
Status: snipcart.Delivered,
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := snipcartProvider.UpdateOrder("b35990df-c0ca-4014-94de-1caa7bd7bb51", &updateOrder)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range response.Items {
|
||||||
|
log.Printf("%v: %v\n", k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
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 v1.0.1
|
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
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -26,13 +26,18 @@ type SnipcartProvider struct {
|
|||||||
Limit int
|
Limit int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SnipcartCustomField struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
type SnipcartItem struct {
|
type SnipcartItem struct {
|
||||||
UUID string `json:"uniqueId"`
|
UUID string `json:"uniqueId"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Quantity int `json:"quantity"`
|
Quantity int `json:"quantity"`
|
||||||
TotalWeight float64 `json:"totalWeight,omitempty"`
|
TotalWeight float64 `json:"totalWeight,omitempty"`
|
||||||
CustomFieldsJSON string `json:"customFieldsJson"`
|
CustomFields []SnipcartCustomField `json:"customFields"`
|
||||||
Length float64 `json:"length,omitempty"`
|
Length float64 `json:"length,omitempty"`
|
||||||
Width float64 `json:"width,omitempty"`
|
Width float64 `json:"width,omitempty"`
|
||||||
Height float64 `json:"height,omitempty"`
|
Height float64 `json:"height,omitempty"`
|
||||||
@@ -60,6 +65,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
|
||||||
@@ -129,14 +142,15 @@ func (o *SnipcartOrder) TokenPNGBase64() (string, error) {
|
|||||||
return base64.StdEncoding.EncodeToString(img), nil
|
return base64.StdEncoding.EncodeToString(img), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SnipcartProvider) UpdateOrder(order *SnipcartOrder) (*SnipcartOrder, error) {
|
func (s *SnipcartProvider) UpdateOrder(token string, orderUpdate *SnipcartOrderUpdate) (*SnipcartOrder, error) {
|
||||||
response, err := helper.Put(orderUri+"/"+order.Token, "Basic", s.AuthBase64, *order)
|
response, err := helper.Put(orderUri+"/"+token, "Basic", s.AuthBase64, orderUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if response.StatusCode < 200 && response.StatusCode >= 300 {
|
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)
|
||||||
}
|
}
|
||||||
|
fmt.Println(response.Status)
|
||||||
|
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user