models

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2016 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NumberType = iota
	StringType
	BoolType
)

NumberType | StringType | BoolType are the different types supported in custom data for orders

View Source
const ChargeTransactionType = "charge"
View Source
const FailedState = "failed"
View Source
const PaidState = "paid"
View Source
const PendingState = "pending"
View Source
const RefundTransactionType = "refund"

Variables

View Source
var Namespace string

Namespace puts all tables names under a common namespace. This is useful if you want to use the same database for several services and don't want table names to collide.

Functions

func AutoMigrate added in v0.2.0

func AutoMigrate(db *gorm.DB) error

func Connect

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

Connect will connect to that storage engine

Types

type Address

type Address struct {
	AddressRequest

	ID string `json:"id"`

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

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

func (Address) TableName added in v0.2.0

func (Address) TableName() string

type AddressRequest added in v0.2.0

type AddressRequest struct {
	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"`
}

func (AddressRequest) Validate added in v0.2.0

func (a AddressRequest) Validate() error

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 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"`
	PriceItems []PriceItem
	Quantity   uint64 `json:"quantity"`

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

func (*LineItem) Process

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

func (LineItem) TableName added in v0.2.0

func (LineItem) TableName() string

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  `json:"shipping_address_id"`

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

	VATNumber string `json:"vatnumber"`

	Data []OrderData `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) TableName added in v0.2.0

func (Order) TableName() string

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 OrderData added in v0.2.0

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

	Type int

	NumericValue float64
	StringValue  string
	BoolValue    bool
}

OrderData is the custom data on an Order

func (OrderData) TableName added in v0.2.0

func (OrderData) TableName() string

func (*OrderData) Value added in v0.2.0

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

Value returns the value of the data field

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:"-"`
}

func (OrderNote) TableName added in v0.2.0

func (OrderNote) TableName() string

type PriceItem added in v1.0.0

type PriceItem struct {
	ID int64 `json:"id"`

	Amount uint64 `json:"amount"`
	Type   string `json:"type"`
	VAT    uint64 `json:"vat"`
}

type PriceMetaItem added in v1.0.0

type PriceMetaItem struct {
	Amount string `json:"amount"`
	Type   string `json:"type"`
	VAT    uint64 `json:"vat"`
}

type PriceMetadata

type PriceMetadata struct {
	Amount   string          `json:"amount"`
	Currency string          `json:"currency"`
	VAT      string          `json:"vat"`
	Items    []PriceMetaItem `json:"items"`
	// contains filtered or unexported fields
}

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"`
	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

func (Transaction) TableName added in v0.2.0

func (Transaction) TableName() string

type User

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

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

func (User) TableName added in v0.2.0

func (User) TableName() string

Jump to

Keyboard shortcuts

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