Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1091f12b0 | ||
|
|
f80f35f5d5 | ||
|
|
13bef02dcb | ||
|
|
e6ffe724af | ||
|
|
8fee81d8a4 | ||
|
|
41c58a497b | ||
|
|
831ad7c029 | ||
|
|
be7452ddc1 | ||
|
|
3627712c9b |
5
go.mod
5
go.mod
@@ -2,4 +2,7 @@ module github.com/debyltech/go-snipcart
|
|||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require github.com/debyltech/go-helpers v0.0.0-20230224002154-eb55816c71ec
|
require (
|
||||||
|
github.com/debyltech/go-helpers v0.0.0-20230224002154-eb55816c71ec
|
||||||
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
|
)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
helper "github.com/debyltech/go-helpers"
|
helper "github.com/debyltech/go-helpers"
|
||||||
|
"github.com/skip2/go-qrcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -29,10 +30,14 @@ 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 float64 `json:"quantity"`
|
Quantity int `json:"quantity"`
|
||||||
Weight string `json:"weight"`
|
TotalWeight float64 `json:"totalWeight,omitempty"`
|
||||||
TotalWeight float64 `json:"totalWeight"`
|
|
||||||
CustomFieldsJSON string `json:"customFieldsJson"`
|
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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SnipcartOrder struct {
|
type SnipcartOrder struct {
|
||||||
@@ -49,6 +54,9 @@ type SnipcartOrder struct {
|
|||||||
Country string `json:"shippingAddressCountry"`
|
Country string `json:"shippingAddressCountry"`
|
||||||
PostalCode string `json:"shippingAddressPostalCode"`
|
PostalCode string `json:"shippingAddressPostalCode"`
|
||||||
Phone string `json:"shippingAddressPhone"`
|
Phone string `json:"shippingAddressPhone"`
|
||||||
|
TrackingNumber string `json:"trackingNumber"`
|
||||||
|
TrackingUrl string `json:"trackingUrl"`
|
||||||
|
ShippingCost float64 `json:"shippingFees"`
|
||||||
Items []SnipcartItem `json:"items"`
|
Items []SnipcartItem `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +72,26 @@ func NewSnipcartProvider(snipcartApiKey string) SnipcartProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SnipcartProvider) GetOrder(token string) (*SnipcartOrder, error) {
|
||||||
|
response, err := helper.Get(orderUri+"/"+token, "Basic", s.AuthBase64, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if response.Status != "200 OK" {
|
||||||
|
return nil, fmt.Errorf("unexpected response received: %s", response.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
var order SnipcartOrder
|
||||||
|
err = json.NewDecoder(response.Body).Decode(&order)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &order, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SnipcartProvider) GetOrders(queries map[string]string) (*SnipcartOrders, error) {
|
func (s *SnipcartProvider) GetOrders(queries map[string]string) (*SnipcartOrders, error) {
|
||||||
response, err := helper.Get(orderUri, "Basic", s.AuthBase64, queries)
|
response, err := helper.Get(orderUri, "Basic", s.AuthBase64, queries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -91,3 +119,12 @@ func (s *SnipcartProvider) GetOrdersByStatus(status OrderStatus) (*SnipcartOrder
|
|||||||
|
|
||||||
return s.GetOrders(map[string]string{"status": string(status)})
|
return s.GetOrders(map[string]string{"status": string(status)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *SnipcartOrder) TokenPNGBase64() (string, error) {
|
||||||
|
img, err := qrcode.Encode("order:"+o.Token, qrcode.Medium, 128)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return base64.StdEncoding.EncodeToString(img), nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user