models

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2017 License: MIT Imports: 22 Imported by: 5

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 MaxConcurrentHooks = 5
View Source
const MaxRetries = 5
View Source
const PaidState = "paid"
View Source
const PendingState = "pending"
View Source
const RefundTransactionType = "refund"
View Source
const RetryPeriod = 30 * time.Second
View Source
const ShippedState = "shipped"
View Source
const SignatureExpiration = 5 * time.Minute

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

func LogEvent added in v1.1.0

func LogEvent(db *gorm.DB, ip, userID, orderID string, eventType EventType, changes []string)

LogEvent logs a new event

func RunHooks added in v1.1.0

func RunHooks(db *gorm.DB, log *logrus.Entry, secret string)

Types

type AddonItem added in v1.1.0

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

	Sku         string `json:"sku"`
	Title       string `json:"title"`
	Description string `json:"description"`

	Price uint64 `json:"price"`
}

func (AddonItem) TableName added in v1.1.0

func (AddonItem) TableName() string

type AddonMetaItem added in v1.1.0

type AddonMetaItem struct {
	Sku         string          `json:"sku"`
	Title       string          `json:"title"`
	Description string          `json:"description"`
	Prices      []PriceMetadata `json:"prices"`
}

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 Coupon added in v1.1.0

type Coupon struct {
	Code string `json:"code"`

	StartDate *time.Time `json:"start_date,omitempty"`
	EndDate   *time.Time `json:"end_date,omitempty"`

	Percentage  uint64         `json:"percentage,omitempty"`
	FixedAmount []*FixedAmount `json:"fixed,omitempty"`

	ProductTypes []string               `json:"product_types,omitempty"`
	Claims       map[string]interface{} `json:"claims,omitempty"`
}

func (*Coupon) FixedDiscount added in v1.1.0

func (c *Coupon) FixedDiscount(currency string) uint64

func (*Coupon) PercentageDiscount added in v1.1.0

func (c *Coupon) PercentageDiscount() uint64

func (*Coupon) Valid added in v1.1.0

func (c *Coupon) Valid() bool

func (*Coupon) ValidForPrice added in v1.1.0

func (c *Coupon) ValidForPrice(currency string, price uint64) bool

func (*Coupon) ValidForType added in v1.1.0

func (c *Coupon) ValidForType(productType string) bool

type Download added in v1.1.0

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

	OrderID    string `json:"order_id"`
	LineItemID int64  `json:"line_item_id"`

	Title  string `json:"title"`
	Sku    string `json:"sku"`
	Format string `json:"format"`
	URL    string `json:"url"`

	DownloadCount uint64 `json:"downloads"`

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

func (*Download) SignURL added in v1.1.0

func (d *Download) SignURL(store assetstores.Store) error

func (Download) TableName added in v1.1.0

func (Download) TableName() string

type Event added in v1.1.0

type Event struct {
	ID uint64 `json:"id"`

	IP string `json:"ip"`

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

	Order   *Order `json:"order,omitempty"`
	OrderID string `json:"order_id,omitempty"`

	Type    string `json:"type"`
	Changes string `json:"data"`

	CreatedAt time.Time `json:"created_at"`
}

func (Event) TableName added in v1.1.0

func (Event) TableName() string

type EventType added in v1.1.0

type EventType string
const (
	EventCreated EventType = "created"
	EventUpdated EventType = "updated"
	EventDeleted EventType = "deleted"
)

type FixedAmount added in v1.1.0

type FixedAmount struct {
	Amount   string `json:"amount"`
	Currency string `json:"currency"`
}

type Hook added in v1.1.0

type Hook struct {
	ID uint64

	UserID string

	Type string

	Done   bool
	Failed bool

	URL     string
	Payload string

	ResponseStatus  string
	ResponseHeaders string
	ResponseBody    string
	ErrorMessage    *string

	Tries int

	CreatedAt   time.Time
	RunAfter    *time.Time
	LockedAt    *time.Time
	LockedBy    *string
	CompletedAt *time.Time
}

func NewHook added in v1.1.0

func NewHook(hookType, url, userID string, payload interface{}) *Hook

func (Hook) TableName added in v1.1.0

func (Hook) TableName() string

func (*Hook) Trigger added in v1.1.0

func (h *Hook) Trigger(client *http.Client, log *logrus.Entry, secret string) (*http.Response, error)

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

	Path string `json:"path"`

	Price uint64 `json:"price"`
	VAT   uint64 `json:"vat"`

	PriceItems []*PriceItem `json:"price_items"`
	AddonItems []*AddonItem `json:"addons"`
	AddonPrice uint64       `json:"addon_price"`

	Quantity uint64 `json:"quantity"`

	MetaData    map[string]interface{} `sql:"-" json:"meta"`
	RawMetaData string                 `json:"-"`

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

func (*LineItem) AfterFind added in v1.1.0

func (l *LineItem) AfterFind() (err error)

func (*LineItem) BeforeUpdate added in v1.1.0

func (l *LineItem) BeforeUpdate() (err error)

func (*LineItem) FixedVAT added in v1.1.0

func (i *LineItem) FixedVAT() uint64

func (*LineItem) GetQuantity added in v1.1.0

func (i *LineItem) GetQuantity() uint64

func (*LineItem) PriceInLowestUnit added in v1.1.0

func (i *LineItem) PriceInLowestUnit() uint64

Make sure LineItem is a valid Item for the calculator

func (*LineItem) Process

func (i *LineItem) Process(userClaims map[string]interface{}, order *Order, meta *LineItemMetadata) error

func (*LineItem) ProductType added in v1.1.0

func (i *LineItem) ProductType() string

func (LineItem) TableName added in v0.2.0

func (LineItem) TableName() string

func (*LineItem) TaxableItems added in v1.1.0

func (i *LineItem) TaxableItems() []calculator.Item

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

	Downloads []Download      `json:"downloads"`
	Addons    []AddonMetaItem `json:"addons"`

	Webhook string `json:"webhook"`
}

type Order

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

	IP string `json:"ip"`

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

	Email string `json:"email"`

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

	Downloads []Download `json:"downloads"`

	Currency string `json:"currency"`
	Taxes    uint64 `json:"taxes"`
	Shipping uint64 `json:"shipping"`
	SubTotal uint64 `json:"subtotal"`
	Discount uint64 `json:"discount"`

	Total uint64 `json:"total"`

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

	PaymentProcessor string `json:"payment_processor"`

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

	MetaData    map[string]interface{} `sql:"-" json:"meta"`
	RawMetaData string                 `json:"-"`

	CouponCode string `json:"coupon_code,omitempty"`

	Coupon    *Coupon `json:"coupon,omitempty" sql:"-"`
	RawCoupon string  `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) AfterFind added in v1.1.0

func (o *Order) AfterFind() error

func (*Order) BeforeUpdate added in v1.1.0

func (o *Order) BeforeUpdate() error

func (*Order) CalculateTotal

func (o *Order) CalculateTotal(settings *calculator.Settings, claims map[string]interface{})

func (Order) TableName added in v0.2.0

func (Order) TableName() string

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

func (*PriceItem) FixedVAT added in v1.1.0

func (i *PriceItem) FixedVAT() uint64

func (*PriceItem) GetQuantity added in v1.1.0

func (i *PriceItem) GetQuantity() uint64

func (*PriceItem) PriceInLowestUnit added in v1.1.0

func (i *PriceItem) PriceInLowestUnit() uint64

Make sure a PriceItem fullfils the calculator Item interface

func (*PriceItem) ProductType added in v1.1.0

func (i *PriceItem) ProductType() string

func (PriceItem) TableName added in v1.1.0

func (PriceItem) TableName() string

func (*PriceItem) TaxableItems added in v1.1.0

func (i *PriceItem) TaxableItems() []calculator.Item

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"`
	Claims   map[string]string `json:"claims"`
	// contains filtered or unexported fields
}

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  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"-"`

	OrderCount int64 `json:"order_count,ommitempty" gorm:"-"`
}

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