Compare commits

...

1 Commits

Author SHA1 Message Date
Bastian de Byl
2d91d1d122 corrected SnipcartItem 2023-02-26 14:11:55 -05:00
3 changed files with 81 additions and 11 deletions

33
example_get_order.go Normal file
View 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
View 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)
}
}

View File

@@ -26,18 +26,23 @@ 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"`
Weight float64 `json:"weight,omitempty"` Weight float64 `json:"weight,omitempty"`
Shippable bool `json:"shippable,omitempty"` Shippable bool `json:"shippable,omitempty"`
} }
type SnipcartOrder struct { type SnipcartOrder struct {