Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84941b7acd | ||
|
|
28f77f63b9 | ||
|
|
2a97bca474 | ||
|
|
2d91d1d122 | ||
|
|
13f482e50a | ||
|
|
bfb6497d25 | ||
|
|
82b88cbaf5 | ||
|
|
994cabc20e |
@@ -7,10 +7,6 @@ import (
|
||||
"github.com/debyltech/go-snipcart/snipcart"
|
||||
)
|
||||
|
||||
const (
|
||||
configFile = "config.json"
|
||||
)
|
||||
|
||||
func main() {
|
||||
snipcartApiKey := flag.String("key", "", "Snipcart API Key")
|
||||
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
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
@@ -26,23 +26,31 @@ type SnipcartProvider struct {
|
||||
Limit int
|
||||
}
|
||||
|
||||
type SnipcartCustomField struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type SnipcartItem struct {
|
||||
UUID string `json:"uniqueId"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Quantity int `json:"quantity"`
|
||||
TotalWeight float64 `json:"totalWeight,omitempty"`
|
||||
CustomFieldsJSON string `json:"customFieldsJson"`
|
||||
Length float64 `json:"length,omitempty"`
|
||||
Width float64 `json:"width,omitempty"`
|
||||
Height float64 `json:"height,omitempty"`
|
||||
Weight float64 `json:"weight,omitempty"`
|
||||
Shippable bool `json:"shippable,omitempty"`
|
||||
UUID string `json:"uniqueId"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Quantity int `json:"quantity"`
|
||||
TotalWeight float64 `json:"totalWeight,omitempty"`
|
||||
TotalPrice float64 `json:"totalPrice,omitempty"`
|
||||
CustomFields []SnipcartCustomField `json:"customFields"`
|
||||
Length float64 `json:"length,omitempty"`
|
||||
Width float64 `json:"width,omitempty"`
|
||||
Height float64 `json:"height,omitempty"`
|
||||
Weight float64 `json:"weight,omitempty"`
|
||||
Shippable bool `json:"shippable,omitempty"`
|
||||
}
|
||||
|
||||
type SnipcartOrder struct {
|
||||
Token string `json:"token"`
|
||||
Invoice string `json:"invoiceNumber"`
|
||||
Subtotal float64 `json:"subtotal,omitempty"`
|
||||
Total float64 `json:"grandTotal,omitempty"`
|
||||
Status string `json:"status"`
|
||||
TotalWeight float64 `json:"totalWeight"`
|
||||
Email string `json:"email"`
|
||||
@@ -61,7 +69,6 @@ type SnipcartOrder struct {
|
||||
}
|
||||
|
||||
type SnipcartOrderUpdate struct {
|
||||
Token string `json:"token"`
|
||||
Status OrderStatus `json:"status"`
|
||||
PaymentStatus string `json:"paymentStatus,omitempty"`
|
||||
TrackingNumber string `json:"trackingNumber,omitempty"`
|
||||
@@ -138,14 +145,15 @@ func (o *SnipcartOrder) TokenPNGBase64() (string, error) {
|
||||
return base64.StdEncoding.EncodeToString(img), nil
|
||||
}
|
||||
|
||||
func (s *SnipcartProvider) UpdateOrder(orderUpdate *SnipcartOrderUpdate) (*SnipcartOrder, error) {
|
||||
response, err := helper.Put(orderUri+"/"+orderUpdate.Token, "Basic", s.AuthBase64, orderUpdate)
|
||||
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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user