models

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2016 License: MIT Imports: 10 Imported by: 5

Documentation

Index

Constants

View Source
const (
	NUMBER = iota
	STRING
	BOOL
)

NUMBER|STRING|BOOL are the different types supported in custom data for orders

View Source
const PaidState = "paid"
View Source
const PendingState = "pending"

Variables

This section is empty.

Functions

func Connect

func Connect(config *conf.Configuration) (*gorm.DB, error)

Connect will connect to that storage engine

Types

type Address

type Address struct {
	ID string `json:"id"`

	User   *User  `json:"-"`
	UserID string `json:"-"`

	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`

	Company  string `json:"company"`
	Address1 string `json:"address1"`
	Address2 string `json:"address2"`
	City     string `json:"city"`
	Country  string `json:"country"`
	State    string `json:"state"`
	Zip      string `json:"zip"`

	CreatedAt time.Time  `json:"created_at"`
	DeletedAt *time.Time `json:"deleted_at"`
}

func (*Address) Valid

func (a *Address) Valid() bool

type Configuration

type Configuration struct {
	Driver  string `json:"driver"`
	ConnURL string `json:"conn_url"`
}

Configuration defines the info necessary to connect to a storage engine

type Data

type Data struct {
	OrderID string `gorm:"primary_key"`
	Key     string `gorm:"primary_key"`

	Type int

	NumericValue float64
	StringValue  string
	BoolValue    bool
}

Data is the custom data on an Order

func (*Data) Value

func (d *Data) Value() interface{}

Value returns the value of the data field

type InvalidDataType

type InvalidDataType struct {
	Key string
}

InvalidDataType is an error returned when trying to set an invalid datatype for a user data key

func (*InvalidDataType) Error

func (i *InvalidDataType) Error() string

type LineItem

type LineItem struct {
	ID      int64  `json:"id"`
	OrderID string `json:"-"`

	Title       string `json:"title"`
	SKU         string `json:"sku"`
	Type        string `json:"type"`
	Description string `json:"description"`
	VAT         uint64 `json:"vat"`

	Path string `json:"path"`

	Price    uint64 `json:"price"`
	Quantity uint64 `json:"quantity"`

	CreatedAt time.Time  `json:"-"`
	DeletedAt *time.Time `json:"-"`
}

func (*LineItem) Process

func (i *LineItem) Process(order *Order, meta *LineItemMetadata) error

type LineItemMetadata

type LineItemMetadata struct {
	Sku         string          `json:"sku"`
	Title       string          `json:"title"`
	Description string          `json:"description"`
	VAT         uint64          `json:"vat"`
	Prices      []PriceMetadata `json:"prices"`
	Type        string          `json:"type"`
}

type Order

type Order struct {
	ID string `json:"id"`

	User      *User  `json:"user,omitempty"`
	UserID    string `json:"user_id,omitempty"`
	SessionID string `json:"-"`

	Email string `json:"email"`

	LineItems []*LineItem `json:"line_items"`

	Currency string `json:"currency"`
	Taxes    uint64 `json:"taxes"`
	Shipping uint64 `json:"shipping"`
	SubTotal uint64 `json:"subtotal"`
	Total    uint64 `json:"total"`

	PaymentState     string `json:"payment_state"`
	FulfillmentState string `json:"fulfillment_state"`
	State            string `json:"state"`

	Transactions []*Transaction `json:"transactions"`
	Notes        []*OrderNote   `json:"notes"`

	ShippingAddress   Address `json:"shipping_address",gorm:"ForeignKey:ShippingAddressID"`
	ShippingAddressID string

	BillingAddress   Address `json:"billing_address",gorm:"ForeignKey:BillingAddressID"`
	BillingAddressID string

	VATNumber string `json:"vatnumber"`

	Data []Data `json:"-"`

	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"-",sql:"index"`
}

func NewOrder

func NewOrder(sessionID, email, currency string) *Order

func (*Order) CalculateTotal

func (o *Order) CalculateTotal(settings *SiteSettings)

func (*Order) MarshalJSON

func (o *Order) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaller for Users

func (*Order) UpdateOrderData

func (o *Order) UpdateOrderData(tx *gorm.DB, updates *map[string]interface{}) error

UpdateOrderData updates all user data from a map of updates

type OrderNote

type OrderNote struct {
	ID int64 `json:"-"`

	UserID string `json:"user_id"`

	Text string `json:"text"`

	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"-"`
}

type PriceMetadata

type PriceMetadata struct {
	Amount   string `json:"amount"`
	Currency string `json:"currency"`
	VAT      string `json:"vat"`
}

type SiteSettings

type SiteSettings struct {
	Taxes []*Tax `json:"taxes"`
}

type Tax

type Tax struct {
	Percentage   uint64   `json:"percentage"`
	ProductTypes []string `json:"product_types"`
	Countries    []string `json:"countries"`
}

type Transaction

type Transaction struct {
	ID      string `json:"id"`
	Order   *Order `json:"-"`
	OrderID string `json:"order_id"`

	ProcessorID string `json:"processor_id"`

	User   *User  `json:"-"`
	UserID string `json:"user_id"`

	Amount         uint64 `json:"amount"`
	AmountReversed uint64 `json:"amount_reversed"`
	Currency       string `json:"currency"`

	FailureCode        string `json:"failure_code"`
	FailureDescription string `json:"failure_description"`

	Status string `json:"status"`
	Type   string `json:"type"`

	CreatedAt time.Time  `json:"created_at"`
	DeletedAt *time.Time `json:"-"`
}

Transaction is an transaction with a payment provider

func NewTransaction

func NewTransaction(order *Order) *Transaction

NewTransaction returns a new transaction for an order

type User

type User struct {
	ID    string `json:"id"`
	Email string `json:"email"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

Jump to

Keyboard shortcuts

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