Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ff851823e | ||
|
|
db6e320b7f | ||
|
|
563e6baeda | ||
|
|
e1f7e99027 | ||
|
|
36ca8d6f83 | ||
|
|
d182b35d56 | ||
|
|
1d5b44c7e9 |
@@ -15,9 +15,9 @@ func main() {
|
||||
log.Fatal("missing -key flag")
|
||||
}
|
||||
|
||||
snipcartProvider := snipcart.NewSnipcartProvider(*snipcartApiKey)
|
||||
Client := snipcart.NewClient(*snipcartApiKey)
|
||||
|
||||
response, err := snipcartProvider.GetOrdersByStatus(snipcart.Processed)
|
||||
response, err := Client.GetOrdersByStatus(snipcart.Processed)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -17,9 +17,9 @@ func main() {
|
||||
log.Fatal("missing -key flag")
|
||||
}
|
||||
|
||||
snipcartProvider := snipcart.NewSnipcartProvider(*snipcartApiKey)
|
||||
Client := snipcart.NewClient(*snipcartApiKey)
|
||||
|
||||
response, err := snipcartProvider.GetOrder("b35990df-c0ca-4014-94de-1caa7bd7bb51")
|
||||
response, err := Client.GetOrder("b35990df-c0ca-4014-94de-1caa7bd7bb51")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -15,13 +15,13 @@ func main() {
|
||||
log.Fatal("missing -key flag")
|
||||
}
|
||||
|
||||
snipcartProvider := snipcart.NewSnipcartProvider(*snipcartApiKey)
|
||||
Client := snipcart.NewClient(*snipcartApiKey)
|
||||
|
||||
updateOrder := snipcart.SnipcartOrderUpdate{
|
||||
Status: snipcart.Delivered,
|
||||
}
|
||||
|
||||
response, err := snipcartProvider.UpdateOrder("b35990df-c0ca-4014-94de-1caa7bd7bb51", &updateOrder)
|
||||
response, err := Client.UpdateOrder("b35990df-c0ca-4014-94de-1caa7bd7bb51", &updateOrder)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
5
go.mod
5
go.mod
@@ -1,8 +1,9 @@
|
||||
module github.com/debyltech/go-snipcart
|
||||
|
||||
go 1.20
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/debyltech/go-helpers v1.0.5
|
||||
github.com/debyltech/go-helpers v1.1.0
|
||||
github.com/debyltech/go-shippr v0.1.0
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
helper "github.com/debyltech/go-helpers"
|
||||
helper "github.com/debyltech/go-helpers/json"
|
||||
"github.com/skip2/go-qrcode"
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ var (
|
||||
orderUri = apiUri + ordersPath
|
||||
)
|
||||
|
||||
type SnipcartProvider struct {
|
||||
type Client struct {
|
||||
SnipcartKey string
|
||||
AuthBase64 string
|
||||
Limit int
|
||||
@@ -50,22 +50,25 @@ type SnipcartOrder struct {
|
||||
Token string `json:"token"`
|
||||
Invoice string `json:"invoiceNumber"`
|
||||
Subtotal float64 `json:"subtotal,omitempty"`
|
||||
Currency string `json:"currency,omitempty"`
|
||||
Total float64 `json:"grandTotal,omitempty"`
|
||||
Status string `json:"status"`
|
||||
TotalWeight float64 `json:"totalWeight"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"shippingAddressName"`
|
||||
Company string `json:"shippingAddressCompanyName"`
|
||||
Address1 string `json:"shippingAddressAddress1"`
|
||||
Address2 string `json:"shippingAddressAddress2"`
|
||||
City string `json:"shippingAddressCity"`
|
||||
Province string `json:"shippingAddressProvince"`
|
||||
Country string `json:"shippingAddressCountry"`
|
||||
PostalCode string `json:"shippingAddressPostalCode"`
|
||||
Phone string `json:"shippingAddressPhone"`
|
||||
Phone string `json:"shippingAddressPhone,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
TrackingNumber string `json:"trackingNumber"`
|
||||
TrackingUrl string `json:"trackingUrl"`
|
||||
ShippingCost float64 `json:"shippingFees"`
|
||||
Items []SnipcartItem `json:"items"`
|
||||
Metadata any `json:"metadata"`
|
||||
}
|
||||
|
||||
type SnipcartOrderUpdate struct {
|
||||
@@ -81,14 +84,14 @@ type SnipcartOrders struct {
|
||||
Items []SnipcartOrder
|
||||
}
|
||||
|
||||
func NewSnipcartProvider(snipcartApiKey string) SnipcartProvider {
|
||||
return SnipcartProvider{
|
||||
func NewClient(snipcartApiKey string) Client {
|
||||
return Client{
|
||||
SnipcartKey: snipcartApiKey,
|
||||
AuthBase64: base64.StdEncoding.EncodeToString([]byte(snipcartApiKey + ":")),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SnipcartProvider) GetOrder(token string) (*SnipcartOrder, error) {
|
||||
func (s *Client) GetOrder(token string) (*SnipcartOrder, error) {
|
||||
response, err := helper.Get(orderUri+"/"+token, "Basic", s.AuthBase64, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -108,7 +111,7 @@ func (s *SnipcartProvider) GetOrder(token string) (*SnipcartOrder, error) {
|
||||
return &order, nil
|
||||
}
|
||||
|
||||
func (s *SnipcartProvider) GetOrders(queries map[string]string) (*SnipcartOrders, error) {
|
||||
func (s *Client) GetOrders(queries map[string]string) (*SnipcartOrders, error) {
|
||||
response, err := helper.Get(orderUri, "Basic", s.AuthBase64, queries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -128,7 +131,7 @@ func (s *SnipcartProvider) GetOrders(queries map[string]string) (*SnipcartOrders
|
||||
return &orders, nil
|
||||
}
|
||||
|
||||
func (s *SnipcartProvider) GetOrdersByStatus(status OrderStatus) (*SnipcartOrders, error) {
|
||||
func (s *Client) GetOrdersByStatus(status OrderStatus) (*SnipcartOrders, error) {
|
||||
if status == "" {
|
||||
return nil, errors.New("status is not set")
|
||||
}
|
||||
@@ -145,7 +148,7 @@ func (o *SnipcartOrder) TokenPNGBase64() (string, error) {
|
||||
return base64.StdEncoding.EncodeToString(img), nil
|
||||
}
|
||||
|
||||
func (s *SnipcartProvider) UpdateOrder(token string, orderUpdate *SnipcartOrderUpdate) (*SnipcartOrder, error) {
|
||||
func (s *Client) UpdateOrder(token string, orderUpdate *SnipcartOrderUpdate) (*SnipcartOrder, error) {
|
||||
response, err := helper.Put(orderUri+"/"+token, "Basic", s.AuthBase64, orderUpdate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
27
snipcart/webhook.go
Normal file
27
snipcart/webhook.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package snipcart
|
||||
|
||||
type SnipcartShippingAddress struct {
|
||||
FullName string `json:"fullName"`
|
||||
FirstName string `json:"firstName"`
|
||||
Name string `json:"name"`
|
||||
Company string `json:"company"`
|
||||
Address1 string `json:"address1"`
|
||||
Address2 string `json:"address2"`
|
||||
FullAddress string `json:"fullAddress"`
|
||||
City string `json:"city"`
|
||||
Country string `json:"country"`
|
||||
PostalCode string `json:"postalCode"`
|
||||
State string `json:"province"`
|
||||
Phone string `json:"phone"`
|
||||
VatNumber string `json:"vatNumber,omitempty"`
|
||||
}
|
||||
|
||||
type SnipcartOrderEventContent struct {
|
||||
Token string `json:"token"`
|
||||
Status string `json:"status"`
|
||||
PaymentStatus string `json:"paymentStatus"`
|
||||
Email string `json:"email"`
|
||||
Curreny string `json:"currency"`
|
||||
Items []SnipcartItem `json:"items"`
|
||||
ShippingAddress SnipcartShippingAddress `json:"shippingAddress"`
|
||||
}
|
||||
Reference in New Issue
Block a user