simplestore

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: ISC Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteTemplate

func WriteTemplate(rootDestPath string) error

WriteTemplate writes the store template in the given path.

Types

type Cart

type Cart struct {
	Items   []*CartItem `json:"items"`
	Updated time.Time   `json:"updated"`
}

func (*Cart) HasCharges added in v0.1.9

func (cart *Cart) HasCharges() bool

HasCharges returns true if at least one item has a positive charge amount.

func (*Cart) Total

func (cart *Cart) Total() float64

Total returns the total cart amount in USD.

func (*Cart) TotalCents

func (cart *Cart) TotalCents() int64

Total returns the total amount, with 2 decimal places accuracy.

type CartItem

type CartItem struct {
	Product  *Product `json:"product"`
	Quantity uint32   `json:"quantity"`
}

type Config

type Config struct {
	Root          string
	Log           slog.Logger
	LiveReload    bool
	OrderPlaced   func(order *Order, msg string)
	StatusChanged func(order *Order, msg string)
	PayType       PayType
	Account       string
	ShipCharge    float64
	Client        *client.Client
	LNPayClient   *client.DcrlnPaymentClient

	ExchangeRateProvider func() float64
}

Config holds the configuration for a simple store.

type Order

type Order struct {
	ID           OrderID           `json:"id"`
	User         clientintf.UserID `json:"user"`
	Cart         Cart              `json:"cart"`
	Status       OrderStatus       `json:"status"`
	PlacedTS     time.Time         `json:"placed_ts"`
	ResolvedTS   *time.Time        `json:"resolved_ts"`
	ShipCharge   float64           `json:"ship_charge"`
	ExchangeRate float64           `json:"exchange_rate"`
	PayType      PayType           `json:"pay_type"`
	Invoice      string            `json:"invoice"`
	ShipAddr     *ShippingAddress  `json:"shipping"`
	Comments     []OrderComment    `json:"comments"`
	ExpiresTS    time.Time         `json:"expires_ts"`
}

func (*Order) Total

func (order *Order) Total() float64

Total returns the total amount as a float USD.

func (*Order) TotalCents

func (order *Order) TotalCents() int64

Total returns the total amount, with 2 decimal places accuracy.

func (*Order) TotalDCR

func (order *Order) TotalDCR() dcrutil.Amount

TotalDCR returns the total order amount in DCR, given the configured exchange rate.

type OrderComment

type OrderComment struct {
	Timestamp time.Time `json:"ts"`
	FromAdmin bool      `json:"fromAdmin"`
	Comment   string    `json:"comment"`
}

type OrderID

type OrderID uint32

func (*OrderID) FromString

func (id *OrderID) FromString(s string) error

func (OrderID) String

func (id OrderID) String() string

type OrderStatus

type OrderStatus string
const (
	StatusPlaced    OrderStatus = "placed"
	StatusPaid      OrderStatus = "paid"
	StatusShipped   OrderStatus = "shipped"
	StatusCompleted OrderStatus = "completed"
	StatusCanceled  OrderStatus = "canceled"
)

type PayType

type PayType string
const (
	PayTypeOnChain PayType = "onchain"
	PayTypeLN      PayType = "ln"
)

type Product

type Product struct {
	Title        string   `json:"title"`
	SKU          string   `json:"sku"`
	Description  string   `json:"description"`
	Tags         []string `json:"tags"`
	Price        float64  `json:"price"`
	Disabled     bool     `json:"disabled,omitempty"`
	Shipping     bool     `json:"shipping"`
	SendFilename string   `json:"send_filename"`
}

type ShippingAddress

type ShippingAddress struct {
	Name        string `json:"name"`
	Address1    string `json:"address1"`
	Address2    string `json:"address2"`
	City        string `json:"city"`
	State       string `json:"state"`
	PostalCode  string `json:"postalCode"`
	Phone       string `json:"phone"`
	CountryCode string `json:"countrycode"`
}

type Store

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

Store is a simple store instance. A simple store can render a front page (index) and individual product pages.

func New

func New(cfg Config) (*Store, error)

New creates a new simple store.

func (*Store) Fulfill

func (*Store) Run

func (s *Store) Run(ctx context.Context) error

Run the simple store functions.

Jump to

Keyboard shortcuts

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