fixed UpdateOrder method
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
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.4
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package snipcart
|
package snipcart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@@ -62,7 +61,6 @@ type SnipcartOrder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SnipcartOrderUpdate struct {
|
type SnipcartOrderUpdate struct {
|
||||||
Token string `json:"token"`
|
|
||||||
Status OrderStatus `json:"status"`
|
Status OrderStatus `json:"status"`
|
||||||
PaymentStatus string `json:"paymentStatus,omitempty"`
|
PaymentStatus string `json:"paymentStatus,omitempty"`
|
||||||
TrackingNumber string `json:"trackingNumber,omitempty"`
|
TrackingNumber string `json:"trackingNumber,omitempty"`
|
||||||
@@ -139,18 +137,15 @@ 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) {
|
func (s *SnipcartProvider) UpdateOrder(token string, orderUpdate *SnipcartOrderUpdate) (*SnipcartOrder, error) {
|
||||||
updateJson, err := json.Marshal(orderUpdate)
|
response, err := helper.Put(orderUri+"/"+token, "Basic", s.AuthBase64, orderUpdate)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
response, err := helper.Put(orderUri+"/"+orderUpdate.Token, "Basic", s.AuthBase64, bytes.NewBuffer(updateJson))
|
|
||||||
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