Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82b88cbaf5 | ||
|
|
994cabc20e | ||
|
|
bde3d07c28 | ||
|
|
0bf0abd435 | ||
|
|
82106ee4e0 | ||
|
|
c1091f12b0 | ||
|
|
f80f35f5d5 | ||
|
|
13bef02dcb | ||
|
|
e6ffe724af | ||
|
|
8fee81d8a4 |
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.1
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package snipcart
|
package snipcart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@@ -30,10 +31,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 {
|
||||||
@@ -52,9 +57,19 @@ type SnipcartOrder struct {
|
|||||||
Phone string `json:"shippingAddressPhone"`
|
Phone string `json:"shippingAddressPhone"`
|
||||||
TrackingNumber string `json:"trackingNumber"`
|
TrackingNumber string `json:"trackingNumber"`
|
||||||
TrackingUrl string `json:"trackingUrl"`
|
TrackingUrl string `json:"trackingUrl"`
|
||||||
|
ShippingCost float64 `json:"shippingFees"`
|
||||||
Items []SnipcartItem `json:"items"`
|
Items []SnipcartItem `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SnipcartOrderUpdate struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
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
|
||||||
@@ -72,7 +87,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +107,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,3 +138,27 @@ func (o *SnipcartOrder) TokenPNGBase64() (string, error) {
|
|||||||
|
|
||||||
return base64.StdEncoding.EncodeToString(img), nil
|
return base64.StdEncoding.EncodeToString(img), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SnipcartProvider) UpdateOrder(orderUpdate *SnipcartOrderUpdate) (*SnipcartOrder, error) {
|
||||||
|
updateJson, err := json.Marshal(orderUpdate)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response, err := helper.Put(orderUri+"/"+orderUpdate.Token, "Basic", s.AuthBase64, bytes.NewBuffer(updateJson))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if response.StatusCode < 200 && response.StatusCode >= 300 {
|
||||||
|
return nil, fmt.Errorf("unexpected response received: %s", 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