Documentation ¶
Index ¶
- Constants
- Variables
- func AutoMigrate(db *gorm.DB) error
- func Connect(config *conf.GlobalConfiguration) (*gorm.DB, error)
- func CreateInstance(db *gorm.DB, instance *Instance) error
- func DeleteInstance(db *gorm.DB, instance *Instance) error
- func IsNotFoundError(err error) bool
- func LogEvent(db *gorm.DB, ip, userID, orderID string, eventType EventType, changes []string)
- func NextInvoiceNumber(tx *gorm.DB, instanceID string) (int64, error)
- func RunHooks(db *gorm.DB, log *logrus.Entry)
- func UpdateInstance(db *gorm.DB, instance *Instance) error
- type AddonItem
- type AddonMetaItem
- type Address
- type AddressRequest
- type Coupon
- func (c *Coupon) FixedDiscount(currency string) uint64
- func (c *Coupon) PercentageDiscount() uint64
- func (c *Coupon) Valid() bool
- func (c *Coupon) ValidForPrice(currency string, price uint64) bool
- func (c *Coupon) ValidForProduct(productSku string) bool
- func (c *Coupon) ValidForType(productType string) bool
- type Download
- type Event
- type EventType
- type FixedAmount
- type Hook
- type Instance
- type InvoiceNumber
- type LineItem
- func (i *LineItem) AfterFind() error
- func (i *LineItem) BeforeDelete(tx *gorm.DB) error
- func (i *LineItem) BeforeSave() error
- func (i *LineItem) FixedVAT() uint64
- func (i *LineItem) GetQuantity() uint64
- func (i *LineItem) PriceInLowestUnit() uint64
- func (i *LineItem) Process(userClaims map[string]interface{}, order *Order, meta *LineItemMetadata) error
- func (i *LineItem) ProductSku() string
- func (i *LineItem) ProductType() string
- func (LineItem) TableName() string
- func (i *LineItem) TaxableItems() []calculator.Item
- type LineItemMetadata
- type ModelNotFoundError
- type Order
- type OrderNote
- type PriceItem
- type PriceMetaItem
- type PriceMetadata
- type Transaction
- type User
Constants ¶
const ( NumberType = iota StringType BoolType )
NumberType | StringType | BoolType are the different types supported in custom data for orders
const ChargeTransactionType = "charge"
ChargeTransactionType is the charge transaction type.
const FailedState = "failed"
FailedState is the failed state of an Order
const PaidState = "paid"
PaidState is the paid state of an Order
const PendingState = "pending"
PendingState is the pending state of an Order
const RefundTransactionType = "refund"
RefundTransactionType is the refund transaction type.
const ShippedState = "shipped"
ShippedState is the shipped state of an Order
Variables ¶
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
AutoMigrate runs the gorm automigration for all models
func Connect ¶
func Connect(config *conf.GlobalConfiguration) (*gorm.DB, error)
Connect will connect to that storage engine
func IsNotFoundError ¶ added in v1.1.2
IsNotFoundError returns whether an error represents a "not found" error.
func NextInvoiceNumber ¶ added in v1.1.2
NextInvoiceNumber updates and returns the next invoice number for the instance
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"` }
AddonItem are additional items for a LineItem.
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"` }
AddonMetaItem model
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"` }
Address is a stored address, reusable with an ID.
type AddressRequest ¶ added in v0.2.0
type AddressRequest struct { Name string `json:"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"` // deprecated FirstName string `json:"first_name,omitempty"` LastName string `json:"last_name,omitempty"` }
AddressRequest is the raw address data
func (*AddressRequest) AfterFind ¶ added in v1.1.2
func (a *AddressRequest) AfterFind() (err error)
AfterFind database callback.
func (*AddressRequest) BeforeSave ¶ added in v1.1.2
func (a *AddressRequest) BeforeSave() (err error)
BeforeSave database callback.
func (AddressRequest) Validate ¶ added in v0.2.0
func (a AddressRequest) Validate() error
Validate validates the AddressRequest model
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"` Products []string `json:"products,omitempty"` Claims map[string]interface{} `json:"claims,omitempty"` }
Coupon represents a discount redeemable with a code.
func (*Coupon) FixedDiscount ¶ added in v1.1.0
FixedDiscount returns the amount of fixed discount for a Coupon.
func (*Coupon) PercentageDiscount ¶ added in v1.1.0
PercentageDiscount returns the percentage discount of a Coupon.
func (*Coupon) ValidForPrice ¶ added in v1.1.0
ValidForPrice returns whether a coupon applies to a specific amount.
func (*Coupon) ValidForProduct ¶ added in v1.2.0
ValidForProduct returns whether a coupon applies to a specific product.
func (*Coupon) ValidForType ¶ added in v1.1.0
ValidForType returns whether a coupon applies to a specific product type.
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:idx_downloads_deleted_at"` }
Download represents a purchased asset download.
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"` }
Event represents a change to an order.
type EventType ¶ added in v1.1.0
type EventType string
EventType is the type of change that occurred.
type FixedAmount ¶ added in v1.1.0
FixedAmount represents an amount and currency pair
type Hook ¶ added in v1.1.0
type Hook struct { ID uint64 UserID string Type string Done bool Failed bool URL string Payload string `sql:"type:text"` Secret string ResponseStatus string ResponseHeaders string `sql:"type:text"` ResponseBody string `sql:"type:text"` ErrorMessage *string `sql:"type:text"` Tries int CreatedAt time.Time RunAfter *time.Time LockedAt *time.Time LockedBy *string CompletedAt *time.Time }
Hook represents a webhook.
type Instance ¶ added in v1.1.2
type Instance struct { ID string `json:"id"` // Netlify UUID UUID string `json:"uuid,omitempty"` RawBaseConfig string `json:"-" sql:"type:text"` BaseConfig *conf.Configuration `json:"config"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `json:"deleted_at"` }
func GetInstance ¶ added in v1.1.2
GetInstance finds an instance by ID
func GetInstanceByUUID ¶ added in v1.1.2
func (*Instance) BeforeSave ¶ added in v1.1.2
BeforeSave database callback.
type InvoiceNumber ¶ added in v1.1.2
func (InvoiceNumber) TableName ¶ added in v1.1.2
func (InvoiceNumber) TableName() string
TableName returns the database table name for the LineItem model.
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" sql:"type:text"` 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:"-" sql:"type:text"` CreatedAt time.Time `json:"-"` DeletedAt *time.Time `json:"-"` }
LineItem is a single item in an Order.
func (*LineItem) BeforeSave ¶ added in v1.1.2
BeforeSave database callback.
func (*LineItem) FixedVAT ¶ added in v1.1.0
FixedVAT implements part of the calculator.Item interface.
func (*LineItem) GetQuantity ¶ added in v1.1.0
GetQuantity implements part of the calculator.Item interface.
func (*LineItem) PriceInLowestUnit ¶ added in v1.1.0
PriceInLowestUnit implements part of the calculator.Item interface.
func (*LineItem) Process ¶
func (i *LineItem) Process(userClaims map[string]interface{}, order *Order, meta *LineItemMetadata) error
Process calculates the price of a LineItem.
func (*LineItem) ProductSku ¶ added in v1.2.0
ProductSku returns the Sku of the line item to match the calculator.Item interface
func (*LineItem) ProductType ¶ added in v1.1.0
ProductType implements part of the calculator.Item interface.
func (LineItem) TableName ¶ added in v0.2.0
TableName returns the database table name for the LineItem model.
func (*LineItem) TaxableItems ¶ added in v1.1.0
func (i *LineItem) TaxableItems() []calculator.Item
TaxableItems implements part of the calculator.Item interface.
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"` }
LineItemMetadata model
type ModelNotFoundError ¶ added in v1.1.2
type ModelNotFoundError struct {
// contains filtered or unexported fields
}
ModelNotFoundError represents when an instance is not found.
func (ModelNotFoundError) Error ¶ added in v1.1.2
func (e ModelNotFoundError) Error() string
type Order ¶
type Order struct { InstanceID string `json:"-"` ID string `json:"id"` InvoiceNumber int64 `json:"invoice_number,omitempty"` 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:"-" sql:"type:text"` CouponCode string `json:"coupon_code,omitempty"` Coupon *Coupon `json:"coupon,omitempty" sql:"-"` RawCoupon string `json:"-" sql:"type:text"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `json:"-" sql:"index:idx_orders_deleted_at"` }
Order model
func (*Order) BeforeSave ¶ added in v1.1.2
BeforeSave database callback.
func (*Order) CalculateTotal ¶
func (o *Order) CalculateTotal(settings *calculator.Settings, claims map[string]interface{}, log logrus.FieldLogger)
CalculateTotal calculates the total price of an Order.
type OrderNote ¶
type OrderNote struct { ID int64 `json:"-"` UserID string `json:"user_id"` Text string `json:"text" sql:"type:text"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `json:"-"` }
OrderNote model which represent notes on a model.
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"` }
PriceItem represent the subcomponent price items of a LineItem.
func (*PriceItem) FixedVAT ¶ added in v1.1.0
FixedVAT implements part of the calculator.Item interface.
func (*PriceItem) GetQuantity ¶ added in v1.1.0
GetQuantity implements part of the calculator.Item interface.
func (*PriceItem) PriceInLowestUnit ¶ added in v1.1.0
PriceInLowestUnit implements part of the calculator.Item interface.
func (*PriceItem) ProductSku ¶ added in v1.2.0
ProductSku returns the Sku of the line item to match the calculator.Item interface
func (*PriceItem) ProductType ¶ added in v1.1.0
ProductType implements part of the calculator.Item interface.
func (PriceItem) TableName ¶ added in v1.1.0
TableName returns the database table name for the PriceItem model.
func (*PriceItem) TaxableItems ¶ added in v1.1.0
func (i *PriceItem) TaxableItems() []calculator.Item
TaxableItems implements part of the calculator.Item interface.
type PriceMetaItem ¶ added in v1.0.0
type PriceMetaItem struct { Amount string `json:"amount"` Type string `json:"type"` VAT uint64 `json:"vat"` }
PriceMetaItem model
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 }
PriceMetadata model
type Transaction ¶
type Transaction struct { InstanceID string `json:"-"` ID string `json:"id"` Order *Order `json:"-"` OrderID string `json:"order_id"` InvoiceNumber int64 `json:"invoice_number"` ProcessorID string `json:"processor_id"` User *User `json:"-"` UserID string `json:"user_id,omitempty"` Amount uint64 `json:"amount"` Currency string `json:"currency"` FailureCode string `json:"failure_code,omitempty"` FailureDescription string `json:"failure_description,omitempty" sql:"type:text"` 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 GetTransaction ¶ added in v1.1.2
func GetTransaction(db *gorm.DB, id string) (*Transaction, error)
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
TableName returns the database table name for the Transaction model.