Compare commits

...

11 Commits

Author SHA1 Message Date
Bastian de Byl
131af89f4f moved enums to enums.go, added SendNotification, Notification structs & enums 2023-04-12 16:56:01 -04:00
Bastian de Byl
b93afeec2f added Created and Modified times to SnipcartOrder 2023-04-09 18:31:53 -04:00
Bastian de Byl
bc56b4d16a 8677r5eju added initial .drone.yml 2023-04-06 23:34:18 -04:00
Bastian de Byl
b08b64f5b2 added SnipcartTax and SnipcartWebhookTaxResponse 2023-04-06 17:59:48 -04:00
Bastian de Byl
ad93704f41 renamed Order.ShippingRate to Order.ShippingRateId 2023-04-03 21:20:22 -04:00
Bastian de Byl
b97ee3132b consolidated webhook order to just order 2023-03-29 13:24:09 -04:00
Bastian de Byl
cfdde462f4 added more order struct details 2023-03-29 13:14:30 -04:00
Bastian de Byl
e039b583e2 fixed Curreny to Currency typo 2023-03-13 00:26:11 -04:00
Bastian de Byl
26571a41fa changed ShippingAddress State to Province 2023-03-13 00:16:22 -04:00
Bastian de Byl
559a100e90 added more missing OrderEventContent fields 2023-03-13 00:14:47 -04:00
Bastian de Byl
6ff851823e added missing OrderEventContent fields 2023-03-13 00:12:11 -04:00
3 changed files with 80 additions and 28 deletions

View File

@@ -1,6 +1,7 @@
package snipcart package snipcart
type OrderStatus string type OrderStatus string
type NotificationType string
const ( const (
Processed OrderStatus = "Processed" Processed OrderStatus = "Processed"
@@ -10,4 +11,10 @@ const (
Pending = "Pending" Pending = "Pending"
Cancelled = "Cancelled" Cancelled = "Cancelled"
Dispatched = "Dispatched" Dispatched = "Dispatched"
Comment NotificationType = "Comment"
OrderStatusChanged = "OrderStatusChanged"
OrderShipped = "OrderShipped"
TrackingNumber = "TrackingNumber"
Invoice = "Invice"
) )

View File

@@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"time"
helper "github.com/debyltech/go-helpers/json" helper "github.com/debyltech/go-helpers/json"
"github.com/skip2/go-qrcode" "github.com/skip2/go-qrcode"
@@ -47,28 +48,34 @@ type SnipcartItem struct {
} }
type SnipcartOrder struct { type SnipcartOrder struct {
Token string `json:"token"` Token string `json:"token"`
Invoice string `json:"invoiceNumber"` Created time.Time `json:"creationDate"`
Subtotal float64 `json:"subtotal,omitempty"` Modified time.Time `json:"modificationDate"`
Currency string `json:"currency,omitempty"` Invoice string `json:"invoiceNumber"`
Total float64 `json:"grandTotal,omitempty"` Subtotal float64 `json:"subtotal,omitempty"`
Status string `json:"status"` Currency string `json:"currency,omitempty"`
TotalWeight float64 `json:"totalWeight"` Total float64 `json:"grandTotal,omitempty"`
Name string `json:"shippingAddressName"` Status string `json:"status"`
Company string `json:"shippingAddressCompanyName"` TotalWeight float64 `json:"totalWeight"`
Address1 string `json:"shippingAddressAddress1"` ShippingAddress SnipcartShippingAddress `json:"shippingAddress,omitempty"`
Address2 string `json:"shippingAddressAddress2"` Name string `json:"shippingAddressName,omitempty"`
City string `json:"shippingAddressCity"` Company string `json:"shippingAddressCompanyName,omitempty"`
Province string `json:"shippingAddressProvince"` Address1 string `json:"shippingAddressAddress1,omitempty"`
Country string `json:"shippingAddressCountry"` Address2 string `json:"shippingAddressAddress2,omitempty"`
PostalCode string `json:"shippingAddressPostalCode"` City string `json:"shippingAddressCity,omitempty"`
Phone string `json:"shippingAddressPhone,omitempty"` Province string `json:"shippingAddressProvince,omitempty"`
Email string `json:"email,omitempty"` Country string `json:"shippingAddressCountry,omitempty"`
TrackingNumber string `json:"trackingNumber"` PostalCode string `json:"shippingAddressPostalCode,omitempty"`
TrackingUrl string `json:"trackingUrl"` Phone string `json:"shippingAddressPhone,omitempty"`
ShippingCost float64 `json:"shippingFees"` Email string `json:"email,omitempty"`
Items []SnipcartItem `json:"items"` TrackingNumber string `json:"trackingNumber"`
Metadata any `json:"metadata"` TrackingUrl string `json:"trackingUrl"`
ShippingCost float64 `json:"shippingFees"`
ShippingProvider string `json:"shippingProvider,omitempty"`
ShippingMethod string `json:"shippingMethod,omitempty"`
ShippingRateId string `json:"shippingRateUserDefinedId,omitempty"`
Items []SnipcartItem `json:"items"`
Metadata any `json:"metadata"`
} }
type SnipcartOrderUpdate struct { type SnipcartOrderUpdate struct {
@@ -84,6 +91,30 @@ type SnipcartOrders struct {
Items []SnipcartOrder Items []SnipcartOrder
} }
type SnipcartTax struct {
Name string `json:"name"`
Amount float64 `json:"amount"`
NumberForInvoice string `json:"numberForInvoice"`
Rate float64 `json:"rate"`
}
type SnipcartNotification struct {
Type NotificationType `json:"type"`
DeliveryMethod string `json:"deliveryMethod"`
Message string `json:"message,omitempty"`
}
type SnipcartNotificationResponse struct {
Id string `json:"id"`
Created time.Time `json:"creationDate"`
Type NotificationType `json:"type"`
DeliveryMethod string `json:"deliveryMethod"`
Body string `json:"body"`
Message string `json:"message"`
Subject string `json:"subject"`
SentOn time.Time `json:"sentOn"`
}
func NewClient(snipcartApiKey string) Client { func NewClient(snipcartApiKey string) Client {
return Client{ return Client{
SnipcartKey: snipcartApiKey, SnipcartKey: snipcartApiKey,
@@ -156,7 +187,6 @@ func (s *Client) UpdateOrder(token string, orderUpdate *SnipcartOrderUpdate) (*S
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()
@@ -168,3 +198,20 @@ func (s *Client) UpdateOrder(token string, orderUpdate *SnipcartOrderUpdate) (*S
return &responseOrder, nil return &responseOrder, nil
} }
func (s *Client) SendNotification(token string, notification *SnipcartNotification) (*SnipcartNotificationResponse, error) {
response, err := helper.Post(orderUri+"/"+token+"/notifications", "Basic", s.AuthBase64, notification)
if err != nil {
return nil, err
}
defer response.Body.Close()
var responseNotification SnipcartNotificationResponse
err = json.NewDecoder(response.Body).Decode(&responseNotification)
if err != nil {
return nil, err
}
return &responseNotification, nil
}

View File

@@ -11,13 +11,11 @@ type SnipcartShippingAddress struct {
City string `json:"city"` City string `json:"city"`
Country string `json:"country"` Country string `json:"country"`
PostalCode string `json:"postalCode"` PostalCode string `json:"postalCode"`
State string `json:"province"` Province string `json:"province"`
Phone string `json:"phone"` Phone string `json:"phone"`
VatNumber string `json:"vatNumber,omitempty"` VatNumber string `json:"vatNumber,omitempty"`
} }
type SnipcartOrderEventContent struct { type SnipcartWebhookTaxResponse struct {
Token string `json:"token"` Taxes []SnipcartTax `json:"taxes"`
Items []SnipcartItem `json:"items"`
ShippingAddress SnipcartShippingAddress `json:"shippingAddress"`
} }