woocommerce

package module
v0.0.0-...-de239a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 4 Imported by: 0

README

woocommerce-go

Go library for the woocommerce API.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Company   string `json:"company"`
	Address1  string `json:"address_1"`
	Address2  string `json:"address_2"`
	City      string `json:"city"`
	State     string `json:"state"`
	Postcode  string `json:"postcode"`
	Country   string `json:"country"`

	Email string `json:"email,omitempty"`
	Phone string `json:"phone,omitempty"`
}

Address is the address used in the order. It is used as billing and shipping address. Some fields are only present in billing address.

type BaseParameters

type BaseParameters url.Values

BaseParameters is a wrapper around url.Values type.

func (BaseParameters) Values

func (b BaseParameters) Values() url.Values

type Cart

type Cart struct {
	// CartToken is the cart token returned by woocommerce on cart request.
	CartToken string `json:"cart_token"`

	Coupons         []Coupon           `json:"coupons"`
	Items           []CartItem         `json:"items"`
	ShippingAddress CartAddress        `json:"shipping_address"`
	BillingAddress  CartAddress        `json:"billing_address"`
	Totals          CartTotals         `json:"totals"`
	ShippingRates   []CartShippingRate `json:"shipping_rates"`
}

Cart holds the cart data.

type CartAddress

type CartAddress struct {
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
	Phone     string `json:"phone,omitempty"`
	Company   string `json:"company"`
	Address1  string `json:"address_1"`
	Address2  string `json:"address_2"`
	City      string `json:"city"`
	State     string `json:"state"`
	Postcode  string `json:"postcode"`
	Country   string `json:"country"`
}

type CartImage

type CartImage struct {
	ID        int    `json:"id"`
	SRC       string `json:"src"`
	Thumbnail string `json:"thumbnail"`
}

type CartItem

type CartItem struct {
	Key              string              `json:"key"`
	ID               int                 `json:"id"`
	Quantity         int                 `json:"quantity"`
	Name             string              `json:"name"`
	Summary          string              `json:"summary"`
	ShortDescription string              `json:"short_description"`
	Description      string              `json:"description"`
	SKU              string              `json:"sku"`
	Images           []CartImage         `json:"images"`
	Totals           CartItemTotals      `json:"totals"`
	Variations       []CartItemVariation `json:"variation"`
}

type CartItemTotals

type CartItemTotals struct {
	CurrencyCode      string `json:"currency_code"`
	CurrencyMinorUnit int    `json:"currency_minor_unit"`
	LineTotal         Int    `json:"line_total"`
	LineTotalTax      Int    `json:"line_total_tax"`
	LineSubtotal      Int    `json:"line_subtotal"`
	LineSubtotalTax   Int    `json:"line_subtotal_tax"`
}

type CartItemVariation

type CartItemVariation struct {
	Attribute string `json:"attribute"`
	Value     string `json:"value"`
}

type CartShippingRate

type CartShippingRate struct {
	PackageID     int                     `json:"package_id"`
	Name          string                  `json:"name"`
	ShippingRates []CartShippingRateInner `json:"shipping_rates"`
}

type CartShippingRateInner

type CartShippingRateInner struct {
	RateID       string `json:"rate_id"`
	Name         string `json:"name"`
	Description  string `json:"description"`
	Price        Int    `json:"price"`
	MethodID     string `json:"method_id"`
	Selected     bool   `json:"selected"`
	CurrencyCode string `json:"currency_code"`
}

type CartTotals

type CartTotals struct {
	CurrencyCode      string `json:"currency_code"`
	CurrencyMinorUnit int    `json:"currency_minor_unit"`
	TotalItems        Int    `json:"total_items"`
	TotalItemsTax     Int    `json:"total_items_tax"`
	TotalFees         Int    `json:"total_fees"`
	TotalFeesTax      Int    `json:"total_fees_tax"`
	TotalDiscount     Int    `json:"total_discount"`
	TotalDiscountTax  Int    `json:"total_discount_tax"`
	TotalShipping     Int    `json:"total_shipping"`
	TotalShippingTax  Int    `json:"total_shipping_tax"`
	TotalPrice        Int    `json:"total_price"`
	TotalTax          Int    `json:"total_tax"`
}

type Coupon

type Coupon struct {
	Code   string       `json:"code"`
	Type   CouponType   `json:"discount_type"`
	Totals CouponTotals `json:"totals"`
}

type CouponTotals

type CouponTotals struct {
	CurrencyCode              string `json:"currency_code"`
	CurrencySymbol            string `json:"currency_symbol"`
	CurrencyMinorUnit         int    `json:"currency_minor_unit"`
	CurrencyDecimalSeparator  string `json:"currency_decimal_separator"`
	CurrencyThousandSeparator string `json:"currency_thousand_separator"`
	CurrencyPrefix            string `json:"currency_prefix"`
	CurrencySuffix            string `json:"currency_suffix"`
	TotalDiscount             Int    `json:"total_discount"`
	TotalDiscountTax          Int    `json:"total_discount_tax"`
}

type CouponType

type CouponType string
const (
	CouponTypePercent      CouponType = "percent"
	CouponTypeFixedCart    CouponType = "fixed_cart"
	CouponTypeFixedProduct CouponType = "fixed_product"
)

type Customer

type Customer struct {
	ID               int        `json:"id,omitempty"`
	DateCreated      string     `json:"date_created,omitempty"`
	DateModified     string     `json:"date_modified,omitempty"`
	Email            string     `json:"email,omitempty"`
	FirstName        string     `json:"first_name,omitempty"`
	LastName         string     `json:"last_name,omitempty"`
	Role             string     `json:"role,omitempty"`
	Username         string     `json:"username,omitempty"`
	Billing          Address    `json:"billing,omitempty"`
	Shipping         Address    `json:"shipping,omitempty"`
	IsPayingCustomer bool       `json:"is_paying_customer,omitempty"`
	AvatarUrl        string     `json:"avatar_url,omitempty"`
	MetaData         []MetaData `json:"meta_data,omitempty"`
}

type Error

type Error struct {
	StatusCode int    `json:"status_code"`
	Code       string `json:"code"`
	Message    string `json:"message"`
	Data       struct {
		Status  int                     `json:"status"`
		Params  map[string]string       `json:"params"`
		Details map[string]ErrorDetails `json:"details"`
	}
}

func (*Error) Error

func (e *Error) Error() string

type ErrorDetails

type ErrorDetails struct {
	Code             string         `json:"code"`
	Message          string         `json:"message"`
	AdditionalErrors []ErrorDetails `json:"additional_errors"`
}

type Float

type Float float64

Float is a support type that marshals itself to string in JSON.

func (Float) MarshalJSON

func (f Float) MarshalJSON() ([]byte, error)

func (*Float) UnmarshalJSON

func (f *Float) UnmarshalJSON(bytes []byte) error

type Int

type Int int64

func (Int) MarshalJSON

func (i Int) MarshalJSON() ([]byte, error)

func (*Int) UnmarshalJSON

func (i *Int) UnmarshalJSON(bytes []byte) error

type MetaData

type MetaData struct {
	ID    int         `json:"id"`
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
}

MetaData holds the meta data.

type NullFloat

type NullFloat struct {
	Float Float
	Valid bool
}

NullFloat is a support type that marshals itself to string in JSON.

func (NullFloat) MarshalJSON

func (f NullFloat) MarshalJSON() ([]byte, error)

func (*NullFloat) UnmarshalJSON

func (f *NullFloat) UnmarshalJSON(bytes []byte) error

type NullTime

type NullTime struct {
	Time  Time
	Valid bool
}

func (NullTime) MarshalJSON

func (t NullTime) MarshalJSON() ([]byte, error)

func (*NullTime) UnmarshalJSON

func (t *NullTime) UnmarshalJSON(bytes []byte) error

type Order

type Order struct {
	ID         int         `json:"id"`
	ParentID   int         `json:"parent_id"`
	Number     string      `json:"number"`
	OrderKey   string      `json:"order_key"`
	CreatedVia string      `json:"created_via"`
	Version    string      `json:"version"`
	Status     OrderStatus `json:"status"`
	// Currency in 3-letter ISO format.
	Currency     string `json:"currency"`
	DateCreated  Time   `json:"date_created"`
	DateModified Time   `json:"date_modified"`
	// DiscountTotal is the total discount amount for the order
	DiscountTotal string `json:"discount_total"`
	// DiscountTax is the discount tax amount for the order
	DiscountTax string `json:"discount_tax"`
	// ShippingTotal is the shipping amount for the order
	ShippingTotal string `json:"shipping_total"`
	// ShippingTax is the shipping tax amount for the order
	ShippingTax string `json:"shipping_tax"`
	// CartTax is the sum of line item taxes only
	CartTax string `json:"cart_tax"`
	// Total is the grand total
	Total string `json:"total"`
	// TotalTax is the sum of all taxes
	TotalTax string `json:"total_tax"`
	// PricesIncludeTax is true the prices included tax during checkout
	PricesIncludeTax  bool    `json:"prices_include_tax"`
	CustomerID        int     `json:"customer_id"`
	CustomerIPAddress string  `json:"customer_ip_address"`
	CustomerUserAgent string  `json:"customer_user_agent"`
	CustomerNote      string  `json:"customer_note"`
	Billing           Address `json:"billing"`
	Shipping          Address `json:"shipping"`
	// PaymentMethod is the ID of the Payment method
	PaymentMethod      string   `json:"payment_method"`
	PaymentMethodTitle string   `json:"payment_method_title"`
	TransactionID      string   `json:"transaction_id"`
	DatePaid           NullTime `json:"date_paid"`
	DateCompleted      NullTime `json:"date_completed"`
	// CartHash is the MD5 hash of the cart items.
	CartHash      string          `json:"cart_hash"`
	MetaData      []MetaData      `json:"meta_data"`
	LineItems     []OrderItem     `json:"line_items"`
	TaxLines      []OrderTax      `json:"tax_lines"`
	ShippingLines []OrderShipping `json:"shipping_lines"`
	CouponLines   []OrderCoupon   `json:"coupon_lines"`
	Refunds       []OrderRefund   `json:"refunds"`
}

Order is the order object that the API returns.

type OrderCoupon

type OrderCoupon struct {
	ID          int        `json:"ID,omitempty"`
	Code        string     `json:"code"`
	Discount    Float      `json:"discount,omitempty"`
	DiscountTax Float      `json:"discount_tax,omitempty"`
	MetaData    []MetaData `json:"meta_data,omitempty"`
}

type OrderCreate

type OrderCreate struct {
	CustomerID         int                   `json:"customer_id,omitempty"`
	PaymentMethod      string                `json:"payment_method"`
	PaymentMethodTitle string                `json:"payment_method_title"`
	Currency           string                `json:"currency"`
	SetPaid            bool                  `json:"set_paid"`
	Billing            OrderCreateBilling    `json:"billing"`
	Shipping           OrderCreateShipping   `json:"shipping"`
	Items              []OrderCreateItem     `json:"line_items"`
	MetaData           []OrderCreateMetadata `json:"meta_data"`
	ShippingLines      []OrderShippingLine   `json:"shipping_lines"`
	CouponLines        []OrderCoupon         `json:"coupon_lines,omitempty"`
}

type OrderCreateBilling

type OrderCreateBilling struct {
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Company   string `json:"company"`
	Address1  string `json:"address_1"`
	Address2  string `json:"address_2"`
	City      string `json:"city"`
	State     string `json:"state"`
	Postcode  string `json:"postcode"`
	Country   string `json:"country"`
	Email     string `json:"email"`
	Phone     string `json:"phone"`
}

type OrderCreateItem

type OrderCreateItem struct {
	ProductID int                   `json:"product_id"`
	Quantity  int                   `json:"quantity"`
	Total     Float                 `json:"total,omitempty"`
	MetaData  []OrderCreateMetadata `json:"meta_data,omitempty"`
}

type OrderCreateMetadata

type OrderCreateMetadata struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type OrderCreateShipping

type OrderCreateShipping struct {
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Address1  string `json:"address_1"`
	Address2  string `json:"address_2"`
	City      string `json:"city"`
	State     string `json:"state"`
	Postcode  string `json:"postcode"`
	Country   string `json:"country"`
}

type OrderItem

type OrderItem struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	ProductID   int    `json:"product_id"`
	VariationID int    `json:"variation_id"`
	Quantity    int    `json:"quantity"`
	TaxClass    string `json:"tax_class"`

	// Subtotal is line subtotal before discounts
	Subtotal Float `json:"subtotal"`
	// SubtotalTax is line subtotal tax before discounts
	SubtotalTax Float `json:"subtotal_tax"`
	// Total is line total after discounts
	Total Float `json:"total"`
	//  TotalTax is line total tax after discounts
	TotalTax Float      `json:"total_tax"`
	Taxes    []OrderTax `json:"taxes"`
	MetaData []MetaData `json:"meta_data"`
	SKU      string     `json:"sku"`
	Price    Float      `json:"price"`
}

type OrderRefund

type OrderRefund struct {
	ID     int
	Reason string
	// Total is the refund total.
	Total Float
}

type OrderShipping

type OrderShipping struct {
	ID          int    `json:"id"`
	MethodTitle string `json:"method_title"`
	MethodID    string `json:"method_id"`
	// Total is the line total after discounts.
	Total Float `json:"total"`
	// TotalTax is the line total tax after discounts.
	TotalTax Float      `json:"total_tax"`
	Taxes    []OrderTax `json:"taxes"`
	MetaData []MetaData `json:"meta_data"`
}

type OrderShippingLine

type OrderShippingLine struct {
	MethodID string `json:"method_id"`
	// Total is the total price of the shipping line.
	// It is formatted on two decimal with '.' as decimal separator.
	Total string `json:"total"`
}

type OrderStatus

type OrderStatus string
const (
	OrderStatusPending    OrderStatus = "pending"
	OrderStatusProcessing OrderStatus = "processing"
	OrderStatusOnHold     OrderStatus = "on-hold"
	OrderStatusCompleted  OrderStatus = "completed"
	OrderStatusCancelled  OrderStatus = "cancelled"
	OrderStatusRefunded   OrderStatus = "refunded"
	OrderStatusFailed     OrderStatus = "failed"
	OrderStatusTrash      OrderStatus = "trash"
)

type OrderTax

type OrderTax struct {
	ID       int    `json:"id"`
	RateCode string `json:"rate_code"`
	RateID   String `json:"rate_id"`
	Label    string `json:"label"`
	Compound bool   `json:"compound"`

	// TaxTotal presents tax total not including shipping taxes.
	TaxTotal         Float      `json:"tax_total"`
	ShippingTaxTotal Float      `json:"shipping_tax_total"`
	MetaData         []MetaData `json:"meta_data"`
}

type OrderUpdate

type OrderUpdate struct {
	SetPaid bool `json:"set_paid"`
}

type PageParams

type PageParams struct {
	Page, PerPage int
}

PageParams represents parameters that are used to specify pagination values of list queries.

func (PageParams) Values

func (p PageParams) Values() url.Values

type Parameters

type Parameters interface {
	Values() url.Values
}

Parameters specifies a type that can return GET parameters of the request.

func ParametersWithValue

func ParametersWithValue(p Parameters, key, value string) Parameters

ParametersWithValue sets the value of the given parameters and returns new parameters.

type Product

type Product struct {
	ProductCommon

	Name             string      `json:"name,omitempty"`
	Slug             string      `json:"slug,omitempty"`
	Type             ProductType `json:"type,omitempty"`
	Featured         bool        `json:"featured,omitempty"`
	ShortDescription string      `json:"short_description,omitempty"`
	ParentID         int         `json:"parent_id,omitempty"`
	Variations       []int       `json:"variations,omitempty"`
}

type ProductCommon

type ProductCommon struct {
	ID           int           `json:"id,omitempty"`
	DateCreated  string        `json:"date_created,omitempty"`
	DateModified string        `json:"date_modified,omitempty"`
	Status       ProductStatus `json:"status,omitempty"`
	Description  string        `json:"description,omitempty"`
	SKU          string        `json:"sku,omitempty"`
	Price        NullFloat     `json:"price,omitempty"`
	RegularPrice NullFloat     `json:"regular_price,omitempty"`
	SalePrice    NullFloat     `json:"sale_price,omitempty"`
	MetaData     []MetaData    `json:"meta_data,omitempty"`
}

ProductCommon contains the common fields of product and product variation.

type ProductStatus

type ProductStatus string
const (
	ProductStatusDraft   ProductStatus = "draft"
	ProductStatusPending ProductStatus = "pending"
	ProductStatusPrivate ProductStatus = "private"
	ProductStatusPublish ProductStatus = "publish"
)

type ProductType

type ProductType string
const (
	ProductTypeSimple   ProductType = "simple"
	ProductTypeGrouped  ProductType = "grouped"
	ProductTypeExternal ProductType = "external"
	ProductTypeVariable ProductType = "variable"
)

type ProductVariation

type ProductVariation struct {
	ProductCommon
}

type String

type String string

String is a string that is sometimes a number (thanks woocommerce).

func (*String) UnmarshalJSON

func (s *String) UnmarshalJSON(bytes []byte) error

type Tax

type Tax struct {
	ID      int    `json:"id"`
	Country string `json:"country"`
	Rate    Float  `json:"rate"`
}

Tax represents a tax object.

type Time

type Time struct {
	time.Time
}

Time is a support type that marshals itself into JSON without timezone.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(bytes []byte) error

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL