Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Coupon ¶
type Coupon interface {
ValidForType(string) bool
ValidForPrice(string, uint64) bool
ValidForProduct(string) bool
PercentageDiscount() uint64
FixedDiscount(string) uint64
}
Coupon is the interface for a coupon needed to do price calculation.
type FixedMemberDiscount ¶
FixedMemberDiscount represents a fixed discount given to members.
type Item ¶
type Item interface {
ProductSku() string
PriceInLowestUnit() uint64
ProductType() string
FixedVAT() uint64
TaxableItems() []Item
GetQuantity() uint64
}
Item is the interface for a single line item needed to do price calculation.
type MemberDiscount ¶
type MemberDiscount struct {
Claims map[string]string `json:"claims"`
Percentage uint64 `json:"percentage"`
FixedAmount []*FixedMemberDiscount `json:"fixed"`
ProductTypes []string `json:"product_types"`
Products []string `json:"products"`
}
MemberDiscount represents a discount given to members, either fixed or a percentage.
func (*MemberDiscount) FixedDiscount ¶
func (d *MemberDiscount) FixedDiscount(currency string) uint64
FixedDiscount returns what the fixed discount amount is for a particular currency.
func (*MemberDiscount) ValidForProduct ¶ added in v1.2.0
func (d *MemberDiscount) ValidForProduct(productSku string) bool
ValidForProduct returns whether a member discount is valid for a product sku
func (*MemberDiscount) ValidForType ¶
func (d *MemberDiscount) ValidForType(productType string) bool
ValidForType returns whether a member discount is valid for a product type.
type PaymentMethods ¶ added in v1.3.0
type PaymentMethods struct {
Stripe struct {
Enabled bool `json:"enabled"`
PublicKey string `json:"public_key,omitempty"`
} `json:"stripe"`
PayPal struct {
Enabled bool `json:"enabled"`
ClientID string `json:"client_id,omitempty"`
Environment string `json:"environment,omitempty"`
} `json:"paypal"`
}
PaymentMethods settings
type Price ¶
Price represents the total price of all line items.
func CalculatePrice ¶
func CalculatePrice(settings *Settings, jwtClaims map[string]interface{}, params PriceParameters, log logrus.FieldLogger) Price
CalculatePrice will calculate the final total price. It takes into account currency, country, coupons, and discounts.
type PriceParameters ¶ added in v1.2.2
PriceParameters represents the order information to calculate prices.
type Settings ¶
type Settings struct {
PricesIncludeTaxes bool `json:"prices_include_taxes"`
Taxes []*Tax `json:"taxes,omitempty"`
MemberDiscounts []*MemberDiscount `json:"member_discounts,omitempty"`
PaymentMethods *PaymentMethods `json:"payment_methods,omitempty"`
}
Settings represent the site-wide settings for price calculation.