gowooco

package module
v0.0.0-...-223aadb Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2021 License: MIT Imports: 15 Imported by: 0

README

go-commerce

wooCommerce Go REST API Library

WooCommerce API Doc

Install

 go get github.com/chenyangguang/go-woocommerce

Documentation

Index

Constants

View Source
const (
	LevelError = iota + 1
	LevelWarn
	LevelInfo
	LevelDebug
)
View Source
const (
	OrdersBaseResource = "orders"
)
View Source
const (
	UserAgent = "gowooco/1.0.0"
)

Variables

This section is empty.

Functions

func CheckResponseError

func CheckResponseError(r *http.Response) error

func ShopBaseURL

func ShopBaseURL(shopName string) string

ShopBaseURL return a shop's base https base url

Types

type Address

type Address struct {
	FirstName string `json:"first_name,omitempty"`
	LastName  string `json:"last_name,omitempty"`
	Company   string `json:"company,omitempty"`
	Address1  string `json:"address1,omitempty"`
	Address2  string `json:"address2,omitempty"`
	City      string `json:"city,omitempty"`
	State     string `json:"province,omitempty"`
	PostCode  string `json:"postcode,omitempty"`
	Country   string `json:"country,omitempty"`
	Email     string `json:"email,omitempty"`
	Phone     string `json:"phone,omitempty"`
}

type App

type App struct {
	CustomerKey    string
	CustomerSecret string
	AppName        string
	UserId         string
	Scope          string
	ReturnUrl      string
	CallbackUrl    string
	Client         *Client
}

func (App) NewClient

func (a App) NewClient(shopName string, opts ...Option) *Client

NewClient returns a new WooCommerce API client with an already authenticated shopname and token. The shopName parameter is the shop's wooCommerce website domain, e.g. "shop.gitvim.com" a.NewClient(shopName, token, opts) is equivalent to NewClient(a, shopName, token, opts)

type Client

type Client struct {
	Client *http.Client

	RateLimits RateLimitInfo
	Product    ProductService
	Order      OrderService
	OrderNote  OrderNoteService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(app App, shopName string, opts ...Option) *Client

NewClient Returns a new WooCommerce API client with an already authenticated shopname and token. The shopName parameter is the shop's wooCommerce website domain, e.g. "shop.gitvim.com"

func (*Client) CreateAndDo

func (c *Client) CreateAndDo(method, relPath string, data, options, resource interface{}) error

CreateAndDo performs a web request to WooCommerce with the given method (GET, POST, PUT, DELETE) and relative path (e.g. "/wp-admin/v3").

func (*Client) Delete

func (c *Client) Delete(path string) error

Delete performs a DELETE request for the given path

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) error

Do sends an API request and populates the given interface with the parsed response. It does not make much sense to call Do without a prepared interface instance.

func (*Client) Get

func (c *Client) Get(path string, resource, options interface{}) error

Get performs a GET request for the given path and saves the result in the given resource.

func (*Client) NewRequest

func (c *Client) NewRequest(method, relPath string, body, options interface{}) (*http.Request, error)

Creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) Post

func (c *Client) Post(path string, data, resource interface{}) error

Post performs a POST request for the given path and saves the result in the given resource.

func (*Client) Put

func (c *Client) Put(path string, data, resource interface{}) error

Put performs a PUT request for the given path and saves the result in the given resource.

type CouponLine

type CouponLine struct {
	ID          int64      `json:"id,omitempty"`
	Code        string     `json:"code,omitempty"`
	Discount    string     `json:"discount,omitempty"`
	DiscountTax string     `json:"discount_tax,omitempty"`
	MetaData    []MetaData `json:"meta_data,omitempty"`
}

type FeeLine

type FeeLine struct {
	ID        int64      `json:"id,omitempty"`
	Name      string     `json:"name,omitempty"`
	TaxClass  string     `json:"tax_class,omitempty"`
	TaxStatus string     `json:"tax_status,omitempty"`
	Total     string     `json:"total,omitempty"`
	TotalTax  string     `json:"total_tax,omitempty"`
	Taxes     []TaxLine  `json:"taxes,omitempty"`
	MetaData  []MetaData `json:"meta_data,omitempty"`
}

type LeveledLogger

type LeveledLogger struct {
	// Level is the minimum logging level that will be emitted by this logger.
	//
	// For example, a Level set to LevelWarn will emit warnings and errors, but
	// not informational or debug messages.
	//
	// Always set this with a constant like LevelWarn because the individual
	// values are not guaranteed to be stable.
	Level int
	// contains filtered or unexported fields
}

It prints warnings and errors to `os.Stderr` and other messages to `os.Stdout`.

func (*LeveledLogger) Debugf

func (l *LeveledLogger) Debugf(format string, v ...interface{})

Debugf logs a debug message using Printf conventions.

func (*LeveledLogger) Errorf

func (l *LeveledLogger) Errorf(format string, v ...interface{})

Errorf logs a warning message using Printf conventions.

func (*LeveledLogger) Infof

func (l *LeveledLogger) Infof(format string, v ...interface{})

Infof logs an informational message using Printf conventions.

func (*LeveledLogger) Warnf

func (l *LeveledLogger) Warnf(format string, v ...interface{})

Warnf logs a warning message using Printf conventions.

type LeveledLoggerInterface

type LeveledLoggerInterface interface {
	Debugf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Warnf(format string, v ...interface{})
}

type LineItem

type LineItem struct {
	ID          int64      `json:"id,omitempty"`
	Name        string     `json:"name,omitempty"`
	ProductID   int64      `json:"product_id,omitempty"`
	VariantID   int64      `json:"variant_id,omitempty"`
	Quantity    int        `json:"quantity,omitempty"`
	TaxClass    string     `json:"tax_class,omitempty"`
	SubTotal    string     `json:"subtotal,omitempty"`
	SubtotalTax string     `json:"subtotal_tax,omitempty"`
	Total       string     `json:"total,omitempty"`
	TotalTax    string     `json:"total_tax,omitempty"`
	Taxes       []TaxLine  `json:"taxes,omitempty"`
	MetaData    []MetaData `json:"meta_data,omitempty"`
	SKU         string     `json:"sku,omitempty"`
	Price       int64      `json:"price,omitempty"`
}

type ListOptions

type ListOptions struct {
	Context string  `url:"context,omitemty"`
	Page    int     `url:"page,omitemty"`
	PerPage int     `url:"per_page,omitemty"`
	Search  string  `url:"search,omitemty"`
	After   string  `url:"after,omitemty"`
	Before  string  `url:"before,omitemty"`
	Exclude []int64 `url:"exclude,omitemty"`
	Include []int64 `url:"include,omitemty"`
	Offset  int     `url:"offset,omitemty"`
	Order   string  `url:"order,omitemty"`
	Orderby string  `url:"orderby,omitemty"`
}

ListOptions represent ist options that can be used for most collections of entities.

type MetaData

type MetaData struct {
	ID    int64  `json:"id,omitempty"`
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

type Option

type Option func(c *Client)

func WithLog

func WithLog(logger LeveledLoggerInterface) Option

WithLog log config option

func WithRetry

func WithRetry(retries int) Option

WithRetry Timeout config option

func WithVersion

func WithVersion(apiVersion string) Option

WithVersion version config option

type Order

type Order struct {
	ID                 int64           `json:"id,omitempty"`
	ParentId           int64           `json:"parent_id,omitempty"`
	Number             string          `json:"number,omitempty"`
	OrderKey           string          `json:"order_key,omitempty"`
	CreatedVia         string          `json:"created_via,omitempty"`
	Version            string          `json:"version,omitempty"`
	Status             string          `json:"status,omitempty"`
	Currency           string          `json:"currency,omitempty"`
	DateCreated        string          `json:"date_created,omitempty"`
	DateCreatedGmt     string          `json:"date_created_gmt,omitempty"`
	DateModified       string          `json:"date_modified,omitempty"`
	DateModifiedGmt    string          `json:"date_modified_gmt,omitempty"`
	DiscountsTotal     string          `json:"discount_total,omitempty"`
	DiscountsTax       string          `json:"discount_tax,omitempty"`
	ShippingTotal      string          `json:"shipping_total,omitempty"`
	ShippingTax        string          `json:"shipping_tax,omitempty"`
	CartTax            string          `json:"cart_tax,omitempty"`
	Total              string          `json:"total,omitempty"`
	TotalTax           string          `json:"total_tax,omitempty"`
	PricesIncludeTax   bool            `json:"prices_include_tax,omitempty"`
	CustomerId         int64           `json:"customer_id,omitempty"`
	CustomerIpAddress  string          `json:"customer_ip_address,omitempty"`
	CustomerUserAgent  string          `json:"customer_user_agent,omitempty"`
	CustomerNote       string          `json:"customer_note,omitempty"`
	Billing            *Address        `json:"billing,omitempty"`
	Shipping           *Address        `json:"shipping,omitempty"`
	PaymentMethod      string          `json:"payment_method,omitempty"`
	PaymentMethodTitle string          `json:"payment_method_title,omitempty"`
	TransactionId      string          `json:"transaction_id,omitempty"`
	DatePaid           string          `json:"date_paid,omitempty"`
	DatePaidGmt        string          `json:"date_paid_gmt,omitempty"`
	DateCompleted      string          `json:"date_completed,omitempty"`
	DateCompletedGmt   string          `json:"date_completed_gmt,omitempty"`
	CartHash           string          `json:"cart_hash,omitempty"`
	MetaData           []MetaData      `json:"meta_data,omitempty"`
	LineItems          []LineItem      `json:"line_items,omitempty"`
	TaxLines           []TaxLine       `json:"tax_lines,omitempty"`
	ShippingLines      []ShippingLines `json:"shipping_lines,omitempty"`
	FeeLines           []FeeLine       `json:"fee_lines,omitempty"`
	CouponLines        []CouponLine    `json:"coupon_lines,omitempty"`
	Refunds            []Refund        `json:"refunds,omitempty"`
	SetPaid            bool            `json:"set_paid,omitempty"`
}

Order represents a WooCommerce Order https://woocommerce.github.io/woocommerce-rest-api-docs/#order-properties

type OrderListOption

type OrderListOption struct {
	ListOptions
	Parent        []int64  `url:"parent,omitemty"`
	ParentExclude []int64  `url:"parent_exclude,omitemty"`
	Status        []string `url:"status,omitempty"`
	Customer      int64    `url:"customer,omitempty"`
	Product       int64    `url:"product,omitempty"`
	Dp            int      `url:"id,omitempty"`
}

OrderListOption list all thee order list option request params refrence url: https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-orders parameters: context string Scope under which the request is made; determines fields present in response. Options: view and edit. Default is view. page integer Current page of the collection. Default is 1. per_page integer Maximum number of items to be returned in result set. Default is 10. search string Limit results to those matching a string. after string Limit response to resources published after a given ISO8601 compliant date. before string Limit response to resources published before a given ISO8601 compliant date. exclude array Ensure result set excludes specific IDs. include array Limit result set to specific ids. offset integer Offset the result set by a specific number of items. order string Order sort attribute ascending or descending. Options: asc and desc. Default is desc. orderby string Sort collection by object attribute. Options: date, id, include, title and slug. Default is date. parent array Limit result set to those of particular parent IDs. parent_exclude array Limit result set to all items except those of a particular parent ID. status array Limit result set to orders assigned a specific status. Options: any, pending, processing, on-hold, completed, cancelled, refunded, failed and trash. Default is any. customer integer Limit result set to orders assigned a specific customer. product integer Limit result set to orders assigned a specific product. dp integer Number of decimal points to use in each resource. Default is 2.

type OrderNote

type OrderNote struct {
	ID             int64  `json:"id,omitempty"`
	Author         string `json:"author,omitempty"`
	DateCreated    string `json:"date_created,omitempty"`
	DateCreatedGmt string `json:"date_created_gmt,omitempty"`

	Note         string `json:"note,omitempty"`
	CustomerNote string `json:"customer_note,omitempty"`
	AddedByUser  bool   `json:"added_by_user,omitempty"`
}

OrderNote represent a WooCommerce Order note https://woocommerce.github.io/woocommerce-rest-api-docs/#order-notes

type OrderNoteService

type OrderNoteService interface {
	Create()
	Get()
	List()
	Delete()
}

OrderNoteService operate Woo-Commerce Order note, eg: create, view, and delete individual order notes. https://woocommerce.github.io/woocommerce-rest-api-docs/#order-notes

type OrderNoteServiceOp

type OrderNoteServiceOp struct {
	// contains filtered or unexported fields
}

func (*OrderNoteServiceOp) Create

func (n *OrderNoteServiceOp) Create()

func (*OrderNoteServiceOp) Delete

func (n *OrderNoteServiceOp) Delete()

func (*OrderNoteServiceOp) Get

func (n *OrderNoteServiceOp) Get()

func (*OrderNoteServiceOp) List

func (n *OrderNoteServiceOp) List()

type OrderRefund

type OrderRefund struct {
	ID int64 `json:"id,omitempty"`

	DateCreated    string `json:"date_created,omitempty"`
	DateCreatedGmt string `json:"date_created_gmt,omitempty"`

	Amount string `json:"amount,omitempty"`
}

OrderRefund represent a WooCommerce Order Refund https://woocommerce.github.io/woocommerce-rest-api-docs/#order-refund-properties

type OrderRefundService

type OrderRefundService interface {
	Create()
	Get()
	Delete()
	List()
}

OrderRefundService allows you to create, view, and delete individual WooCommerce Order refunds. https://woocommerce.github.io/woocommerce-rest-api-docs/#refunds

type OrderResource

type OrderResource struct {
	Order *Order `json:"order"`
}

OrderResource represents the result from the /wp-json/wc/v3/orders/:id endpoint

type OrderService

type OrderService interface {
	Create()
	Get(orderId int64, options interface{}) (*Order, error)
	List(options interface{}) ([]Order, error)
	Update()
	Delete()
	BatchUpdate()
}

OrderService is an interface for interfacing with the orders endpoints of woocommerce API https://woocommerce.github.io/woocommerce-rest-api-docs/#orders

type OrderServiceOp

type OrderServiceOp struct {
	// contains filtered or unexported fields
}

OrderServiceOp handles communication with the order related methods of WooCommerce'API

func (*OrderServiceOp) BatchUpdate

func (o *OrderServiceOp) BatchUpdate()

func (*OrderServiceOp) Create

func (o *OrderServiceOp) Create()

func (*OrderServiceOp) Delete

func (o *OrderServiceOp) Delete()

func (*OrderServiceOp) Get

func (o *OrderServiceOp) Get(orderID int64, options interface{}) (*Order, error)

Get individual order

func (*OrderServiceOp) List

func (o *OrderServiceOp) List(options interface{}) ([]Order, error)

func (*OrderServiceOp) ListWithPagination

func (o *OrderServiceOp) ListWithPagination(options interface{}) ([]Order, *Pagination, error)

ListWithPagination lists products and return pagination to retrieve next/previous results.

func (*OrderServiceOp) Update

func (o *OrderServiceOp) Update()

type OrdersResource

type OrdersResource struct {
	Orders []Order `json:"orders"`
}

OrderResource represents the result from the /wp-json/wc/v3/orders endpoint

type Pagination

type Pagination struct {
	NextPageOptions     *ListOptions
	PreviousPageOptions *ListOptions
	FirstPageOptions    *ListOptions
	LastPageOptions     *ListOptions
}

Pagination of results

type Product

type Product struct {
}

Product represent WooCommerce Product https://woocommerce.github.io/woocommerce-rest-api-docs/#product-properties

type ProductService

type ProductService interface {
	Create()
	Get()
	Delete()
	List()
	Update()
	BatchUpdate()
}

ProductService allows you to create, view, update, and delete individual, or a batch, of products https://woocommerce.github.io/woocommerce-rest-api-docs/#products

type ProductServiceOp

type ProductServiceOp struct {
	// contains filtered or unexported fields
}

func (*ProductServiceOp) BatchUpdate

func (p *ProductServiceOp) BatchUpdate()

func (*ProductServiceOp) Create

func (p *ProductServiceOp) Create()

func (*ProductServiceOp) Delete

func (p *ProductServiceOp) Delete()

func (*ProductServiceOp) Get

func (p *ProductServiceOp) Get()

func (*ProductServiceOp) List

func (p *ProductServiceOp) List()

func (*ProductServiceOp) Update

func (p *ProductServiceOp) Update()

type RateLimitError

type RateLimitError struct {
	ResponseError
	RetryAfter int
}

An error specific to a rate-limiting response. Embeds the ResponseError to allow consumers to handle it the same was a normal ResponseError.

type RateLimitInfo

type RateLimitInfo struct {
	RequestCount      int
	BucketSize        int
	RetryAfterSeconds float64
}

type Refund

type Refund struct {
	ID     int64  `json:"id,omitempty"`
	Reason string `json:"reason,omitempty"`
	Total  string `json:"total,omitempty"`
}

type ResponseDecodingError

type ResponseDecodingError struct {
	Body    []byte
	Message string
	Status  int
}

ResponseDecodingError occurs when the response body from WooCommerce could not be parsed.

func (ResponseDecodingError) Error

func (e ResponseDecodingError) Error() string

type ResponseError

type ResponseError struct {
	Status  int
	Message string
	Data    []string
}

ResponseError is A general response error that follows a similar layout to WooCommerce's response errors, i.e. either a single message or a list of messages. https://woocommerce.github.io/woocommerce-rest-api-docs/#request-response-format

func (ResponseError) Error

func (e ResponseError) Error() string

type ShippingLines

type ShippingLines struct {
	ID          int64      `json:"id,omitempty"`
	MethodTitle string     `json:"method_title,omitempty"`
	MethodID    string     `json:"method_id,omitempty"`
	Total       string     `json:"total,omitempty"`
	TotalTax    string     `json:"total_tax,omitempty"`
	Taxes       []TaxLine  `json:"tax_lines,omitempty"`
	MetaData    []MetaData `json:"meta_data,omitempty"`
}

type TaxLine

type TaxLine struct {
	ID               int64      `json:"id,omitempty"`
	RateCode         string     `json:"rate_code,omitempty"`
	RateId           string     `json:"rate_id,omitempty"`
	Label            string     `json:"label,omitempty"`
	Compound         bool       `json:"compound,omitempty"`
	TaxTotal         string     `json:"tax_total"`
	ShippingTaxTotal string     `json:"shipping_tax_total,omitempty"`
	MetaData         []MetaData `json:"meta_data,omitempty"`
}

Jump to

Keyboard shortcuts

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