cart

package
v3.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 17 Imported by: 39

Documentation

Index

Constants

View Source
const (
	TotalsTypeDiscount      = "totals_type_discount"
	TotalsTypeVoucher       = "totals_type_voucher"
	TotalsTypeTax           = "totals_type_tax"
	TotalsTypeLoyaltypoints = "totals_loyaltypoints"
	TotalsTypeShipping      = "totals_type_shipping"
)

Key constants

View Source
const (
	// DeliveryWorkflowPickup constant for pickup delivery workflow
	DeliveryWorkflowPickup = "pickup"
	// DeliveryWorkflowDelivery constant for delivery delivery workflow
	DeliveryWorkflowDelivery = "delivery"
	// DeliveryWorkflowUnspecified constant for an unspecified delivery workflow
	DeliveryWorkflowUnspecified = "unspecified"

	// DeliverylocationTypeUnspecified constant for an unspecified delivery location type
	DeliverylocationTypeUnspecified = "unspecified"
	// DeliverylocationTypeCollectionpoint constant for collection points
	DeliverylocationTypeCollectionpoint = "collection-point"
	// DeliverylocationTypeStore constant for store delivery
	DeliverylocationTypeStore = "store"
	// DeliverylocationTypeAddress constant for deliveries to an address
	DeliverylocationTypeAddress = "address"
	// DeliverylocationTypeFreightstation constant for deliveries to an freight station
	DeliverylocationTypeFreightstation = "freight-station"
)

Variables

View Source
var (
	// ErrCartNotFound is used if a cart was not found
	ErrCartNotFound = errors.New("Cart not found")
	// ErrItemNotFound is used if a item on cart was not found
	ErrItemNotFound = errors.New("Item not found")
	// ErrDeliveryCodeNotFound is used if a delivery was not found
	ErrDeliveryCodeNotFound = errors.New("Delivery not found")
)
View Source
var (

	// ErrSplitNoGiftCards indicates that there are no gift cards given to PaymentSplitWithGiftCards
	ErrSplitNoGiftCards = errors.New("no gift cards applied")

	// ErrSplitEmptyGiftCards indicates that there are gift cards given but with 0 applied balance
	ErrSplitEmptyGiftCards = errors.New("applied gift cards are empty")

	// ErrSplitGiftCardsExceedTotal indicates that gift card sum exceeds total of prices items
	ErrSplitGiftCardsExceedTotal = errors.New("gift card amount exceeds total priced items value")

	// ErrSplitGiftCardsNoChargeTypeMapping indicates that there is no mapping from the gift card charge type to an actual payment method
	ErrSplitGiftCardsNoChargeTypeMapping = fmt.Errorf("payment method for charge type %q not defined", price.ChargeTypeGiftCard)

	// ErrPaymentSelectionNotSet is used for nil PaymentSelection on cart
	ErrPaymentSelectionNotSet = errors.New("paymentSelection not set")
)
View Source
var (
	// ErrAdditionalInfosNotFound is returned if the additional infos are not set
	ErrAdditionalInfosNotFound = errors.New("additional infos not found")
)

Functions

This section is empty.

Types

type AddRequest

type AddRequest struct {
	MarketplaceCode        string
	Qty                    int
	VariantMarketplaceCode string
	AdditionalData         map[string]string
	BundleConfiguration    productDomain.BundleConfiguration
}

AddRequest defines add to cart request

type AdditionalData

type AdditionalData struct {
	// CustomAttributes list of key values
	CustomAttributes map[string]string
	// ReservedOrderID is an ID already known by the Cart of the future order ID
	ReservedOrderID string
}

AdditionalData defines the supplementary cart data

type AdditionalDeliverInfo

type AdditionalDeliverInfo interface {
	Marshal() (json.RawMessage, error)
	Unmarshal(json.RawMessage) error
}

AdditionalDeliverInfo is an interface that allows to store "any" additional objects on the cart see DeliveryInfoUpdateCommand

type Address

type Address struct {
	Vat                    string
	Firstname              string
	Lastname               string
	MiddleName             string
	Title                  string
	Salutation             string
	Street                 string
	StreetNr               string
	AdditionalAddressLines []string
	Company                string
	City                   string
	PostCode               string
	State                  string
	RegionCode             string
	Country                string
	CountryCode            string
	TelephoneCountryCode   string
	TelephoneAreaCode      string
	TelephoneNumber        string
	// Deprecated: parts of number should be distinguished, please use TelephoneCountryCode, TelephoneAreaCode and TelephoneNumber
	Telephone string
	Email     string
}

Address defines a cart address

func (Address) FullName

func (a Address) FullName() string

FullName return Firstname Lastname

func (*Address) IsEmpty

func (a *Address) IsEmpty() bool

IsEmpty checks all fields of the address if they are empty

type AppliedCouponCodes added in v3.0.1

type AppliedCouponCodes []CouponCode

AppliedCouponCodes slice of applied coupon codes

func (AppliedCouponCodes) ContainedIn added in v3.0.1

func (acc AppliedCouponCodes) ContainedIn(couponCodesToCompare AppliedCouponCodes) bool

ContainedIn returns if the coupon codes are contained in couponCodesToCompare

type AppliedDiscount

type AppliedDiscount struct {
	CampaignCode  string       // unique code of the underlying campaign or rule e.g. "summer-campaign-2018"
	CouponCode    string       // code of discount e.g. provided by user "summer2018"
	Label         string       // readable name of discount "Super Summer Sale 2018"
	Applied       domain.Price // how much of the discount has been subtracted from cart price, IMPORTANT: always negative
	Type          string       // to distinguish between discounts
	IsItemRelated bool         // flag indicating if the discount is applied due to item in cart
	SortOrder     int          // indicates in which order discount have been applied, low value has been applied before high value
}

AppliedDiscount value object - generic reference for a discount

type AppliedDiscounts

type AppliedDiscounts []AppliedDiscount

AppliedDiscounts represents multiple discounts that are subtracted from total price of cart

func (AppliedDiscounts) ByCampaignCode

func (discounts AppliedDiscounts) ByCampaignCode(campaignCode string) AppliedDiscounts

ByCampaignCode filter AppliedDiscounts based on provided campaign code

func (AppliedDiscounts) ByType

func (discounts AppliedDiscounts) ByType(filterType string) AppliedDiscounts

ByType filter AppliedDiscounts based on type

func (AppliedDiscounts) Items

func (discounts AppliedDiscounts) Items() []AppliedDiscount

Items getter for graphql integration

func (AppliedDiscounts) Sum

func (discounts AppliedDiscounts) Sum() (domain.Price, error)

Sum returns the sum of the applied values of the AppliedDiscounts

type AppliedGiftCard

type AppliedGiftCard struct {
	Code             string
	Applied          domain.Price           // how much of the gift card has been subtracted from cart price
	Remaining        domain.Price           // how much of the gift card is still available
	CustomAttributes map[string]interface{} // additional custom attributes
}

AppliedGiftCard value object represents a gift card (partial payment) on the cart

func (AppliedGiftCard) HasRemaining

func (card AppliedGiftCard) HasRemaining() bool

HasRemaining checks whether gift card has a remaining balance

func (AppliedGiftCard) Total added in v3.0.1

func (card AppliedGiftCard) Total() (domain.Price, error)

Total returns the total value of the gift card by adding what is applied and remaining In case the values cannot be added the function returns the remaining amount of the giftcard and an error

type AppliedGiftCards

type AppliedGiftCards []AppliedGiftCard

AppliedGiftCards convenience wrapper for array of applied gift cards

func (*AppliedGiftCards) ByRemaining

func (cards *AppliedGiftCards) ByRemaining() AppliedGiftCards

ByRemaining fetches gift cards that still have a remaining value from applied gift cards

func (*AppliedGiftCards) GiftCardByCode

func (cards *AppliedGiftCards) GiftCardByCode(code string) (*AppliedGiftCard, bool)

GiftCardByCode returns a single gift card if the given code matches its code. First return parameter is the gift card if found and the second return parameter is a boolean depicting if a gift card was found

type Cart

type Cart struct {
	// ID is the main identifier of the cart
	ID string
	// EntityID is a second identifier that may be used by some backends
	EntityID string

	// BillingAddress is the main billing address (relevant for all payments/invoices)
	BillingAddress *Address

	// Purchaser hold additional infos for the legal contact person in this order
	Purchaser *Person

	// Deliveries contains a list of desired Deliveries (or Shipments) involved in this cart
	Deliveries []Delivery

	// AdditionalData can be used for Custom attributes
	AdditionalData AdditionalData

	// PaymentSelection is used to store information on "how" the customer wants to pay
	PaymentSelection PaymentSelection

	// BelongsToAuthenticatedUser displays if the cart is guest cart (false) or from an authenticated user (true)
	BelongsToAuthenticatedUser bool

	// AuthenticatedUserID holds the potential customer ID
	AuthenticatedUserID string

	// AppliedCouponCodes hold the coupons or discount codes that are applied to the cart
	AppliedCouponCodes []CouponCode

	DefaultCurrency string

	// Additional non taxable totals
	Totalitems []Totalitem

	// AppliedGiftCards is a list of applied gift cards
	AppliedGiftCards []AppliedGiftCard
	// AppliedGiftCardsAmount is the part of GrandTotal which is paid by gift cards
	TotalGiftCardAmount domain.Price
	// GrandTotalWithGiftCards is the final amount with the applied gift cards subtracted.
	GrandTotalWithGiftCards domain.Price
	// GrandTotalNetWithGiftCards is the corresponding net value to GrandTotalWithGiftCards
	GrandTotalNetWithGiftCards domain.Price
	// GrandTotal is the final amount that need to be paid by the customer (gross)
	GrandTotal domain.Price
	// GrandTotalNet is the corresponding net value to GrandTotal
	GrandTotalNet domain.Price
	// ShippingNet is the sum of all shipping costs
	ShippingNet domain.Price
	// ShippingNetWithDiscounts is the sum of all shipping costs with all shipping discounts
	ShippingNetWithDiscounts domain.Price
	// ShippingGross is the sum of all shipping costs including tax
	ShippingGross domain.Price
	// ShippingGrossWithDiscounts is the sum of all shipping costs with all shipping discounts including tax
	ShippingGrossWithDiscounts domain.Price
	// SubTotalGross is the sum of all delivery subtotals (without shipping/ discounts)
	SubTotalGross domain.Price
	// SubTotalNet is the sum of all delivery net subtotals (without shipping/ discounts)
	SubTotalNet domain.Price
	// SubTotalGrossWithDiscounts is the sum of row gross prices reduced by the applied discounts
	SubTotalGrossWithDiscounts domain.Price
	// SubTotalNetWithDiscounts is the sum of row net prices reduced by the net value of the applied discounts
	SubTotalNetWithDiscounts domain.Price
	// TotalDiscountAmount is the sum of all discounts (incl. shipping)
	TotalDiscountAmount domain.Price
	// NonItemRelatedDiscountAmount is the sum of discounts that are not related to the item (including shipping discounts)
	NonItemRelatedDiscountAmount domain.Price
	// ItemRelatedDiscountAmount is the sum of discounts that are related to the item (including shipping discounts)
	ItemRelatedDiscountAmount domain.Price
}

Cart Value Object (immutable data - because the CartService is responsible to return a cart).

func (Cart) AllShippingTitles

func (c Cart) AllShippingTitles() []string

AllShippingTitles returns all ShippingItem titles

func (Cart) Clone added in v3.5.0

func (c Cart) Clone() (Cart, error)

Clone the current cart

func (Cart) GetAllPaymentRequiredItems

func (c Cart) GetAllPaymentRequiredItems() PricedItems

GetAllPaymentRequiredItems returns all the Items (Cartitem, ShippingItem, TotalItems) that need to be paid with the final gross price

func (Cart) GetByExternalReference

func (c Cart) GetByExternalReference(ref string) (*Item, error)

GetByExternalReference gets an item by its external reference

func (Cart) GetByItemID

func (c Cart) GetByItemID(itemID string) (*Item, error)

GetByItemID gets an item by its id

func (Cart) GetCartTeaser

func (c Cart) GetCartTeaser() *Teaser

GetCartTeaser returns the teaser

func (Cart) GetContactMail added in v3.4.0

func (c Cart) GetContactMail() string

GetContactMail returns the contact mail from the shipping address with fall back to the billing address

func (Cart) GetDeliveryByCode

func (c Cart) GetDeliveryByCode(deliveryCode string) (*Delivery, bool)

GetDeliveryByCode gets a delivery by code

func (Cart) GetDeliveryByCodeWithoutBool

func (c Cart) GetDeliveryByCodeWithoutBool(deliveryCode string) *Delivery

GetDeliveryByCodeWithoutBool TODO: This func needs to be removed as soon as there's a solution for handling of boolean returns when gql expects an err

func (Cart) GetDeliveryByItemID

func (c Cart) GetDeliveryByItemID(itemID string) (*Delivery, error)

GetDeliveryByItemID returns a delivery by a given itemID

func (Cart) GetDeliveryCodes

func (c Cart) GetDeliveryCodes() []string

GetDeliveryCodes returns a slice of all delivery codes in cart that have at least one cart item

func (Cart) GetMainShippingEMail

func (c Cart) GetMainShippingEMail() string

GetMainShippingEMail returns the main shipping address email, empty string if not available

func (Cart) GetPaymentReference

func (c Cart) GetPaymentReference() string

GetPaymentReference returns a string that can be used as reference to pass to payment gateway. You may want to use it. It returns either the reserved Order id or the cart id/entityID

func (Cart) GetTotalItemsByType

func (c Cart) GetTotalItemsByType(typeCode string) []Totalitem

GetTotalItemsByType returns a slice of all Totalitems by typeCode

func (Cart) GetTotalQty

func (c Cart) GetTotalQty(marketPlaceCode string, variantCode string) int

GetTotalQty for the product in the cart

func (Cart) GetVoucherSavings

func (c Cart) GetVoucherSavings() domain.Price

GetVoucherSavings returns the savings of all vouchers

func (Cart) GrandTotalCharges

func (c Cart) GrandTotalCharges() domain.Charges

GrandTotalCharges is the final sum that need to be paid - split by the charges that need to be paid

func (Cart) HasAppliedCouponCode

func (c Cart) HasAppliedCouponCode() bool

HasAppliedCouponCode checks if a coupon code is applied to the cart

func (*Cart) HasAppliedDiscounts

func (c *Cart) HasAppliedDiscounts() (bool, error)

HasAppliedDiscounts check whether there are any discounts currently applied to the cart

func (Cart) HasAppliedGiftCards

func (c Cart) HasAppliedGiftCards() bool

HasAppliedGiftCards checks if a gift card is applied to the cart

func (Cart) HasDeliveryForCode

func (c Cart) HasDeliveryForCode(deliveryCode string) bool

HasDeliveryForCode checks if a delivery with the given code exists in the cart

func (Cart) HasRemainingGiftCards

func (c Cart) HasRemainingGiftCards() bool

HasRemainingGiftCards check whether there are gift cards with remaining balance

func (Cart) HasShippingCosts

func (c Cart) HasShippingCosts() bool

HasShippingCosts returns true if cart HasShippingCosts

func (Cart) IsEmpty

func (c Cart) IsEmpty() bool

IsEmpty returns true if cart is empty

func (Cart) IsPaymentSelected

func (c Cart) IsPaymentSelected() bool

IsPaymentSelected returns true if a valid payment is selected

func (Cart) ItemCount

func (c Cart) ItemCount() int

ItemCount returns amount of cart items in the current cart

func (*Cart) MergeDiscounts

func (c *Cart) MergeDiscounts() (AppliedDiscounts, error)

MergeDiscounts sums up discounts of cart based on its deliveries All discounts with the same campaign code are aggregated and returned as one with a summed price

func (Cart) ProductCount

func (c Cart) ProductCount() int

ProductCount returns the amount of different products, but a product is counted twice if it is in different deliveries

func (Cart) ProductCountUnique added in v3.1.0

func (c Cart) ProductCountUnique() int

ProductCountUnique returns the amount of unique products across all deliveries

func (Cart) SumTaxes

func (c Cart) SumTaxes() Taxes

SumTaxes returns sum of deliveries SumRowTaxes

func (Cart) SumTotalTaxAmount

func (c Cart) SumTotalTaxAmount() domain.Price

SumTotalTaxAmount returns sum price of deliveries Taxes as total amount

type CompleteBehaviour added in v3.1.0

type CompleteBehaviour interface {
	Complete(context.Context, *Cart) (*Cart, DeferEvents, error)
	// Restore should reopen the cart while maintaining the previously used cart id
	Restore(context.Context, *Cart) (*Cart, DeferEvents, error)
}

CompleteBehaviour can be implemented by a cart service. Complete is normally called before the cart is placed This can for example be used to invalidate gift cards

type CouponCode

type CouponCode struct {
	Code string
	// CustomAttributes can hold additional data for coupon code - keys and values are project specific
	CustomAttributes map[string]interface{}
}

CouponCode value object

type CustomerCartService

type CustomerCartService interface {
	// GetModifyBehaviour gets the behaviour for the customer cart service
	GetModifyBehaviour(context.Context, auth.Identity) (ModifyBehaviour, error)
	// GetCart for authenticated user and optional cartid
	GetCart(ctx context.Context, identity auth.Identity, cartID string) (*Cart, error)
	// RestoreCart restores a previously used customer cart with all its content.
	// Depending on the used adapter this can lead to a new Cart.ID
	// Deprecated: Implement CompleteBehaviour instead
	RestoreCart(ctx context.Context, identity auth.Identity, cart Cart) (*Cart, error)
}

CustomerCartService interface - Secondary PORT

type DefaultDeliveryInfoBuilder

type DefaultDeliveryInfoBuilder struct {
	// contains filtered or unexported fields
}

DefaultDeliveryInfoBuilder defines the default delivery info builder used

func (*DefaultDeliveryInfoBuilder) BuildByDeliveryCode

func (b *DefaultDeliveryInfoBuilder) BuildByDeliveryCode(deliverycode string) (*DeliveryInfo, error)

BuildByDeliveryCode builds a (initial) DeliveryInfo by deliveryCode Convention that is used in this factory is to split infos in the build deliveryinfo by "_" like this:

  • workflow_locationtype_locationdetail_method_anythingelse
  • not all parts are required
  • to "skip" parts in between use "-"

func (*DefaultDeliveryInfoBuilder) Inject

func (b *DefaultDeliveryInfoBuilder) Inject(
	logger flamingo.Logger,
	config *struct {
		DefaultUseBillingAddress bool `inject:"config:commerce.cart.defaultUseBillingAddress,optional"`
	},
)

Inject dependencies

type DefaultPaymentSelection

type DefaultPaymentSelection struct {
	// GatewayProp - the selected Gateway
	GatewayProp        string
	ChargedItemsProp   PaymentSplitByItem
	IdempotencyKeyUUID string
}

DefaultPaymentSelection value object - that implements the PaymentSelection interface

func (DefaultPaymentSelection) CartSplit

func (d DefaultPaymentSelection) CartSplit() PaymentSplit

CartSplit returns the selected split per ChargeType and PaymentMethod

func (DefaultPaymentSelection) Gateway

func (d DefaultPaymentSelection) Gateway() string

Gateway returns the selected Gateway code

func (DefaultPaymentSelection) GenerateNewIdempotencyKey added in v3.0.1

func (d DefaultPaymentSelection) GenerateNewIdempotencyKey() (PaymentSelection, error)

GenerateNewIdempotencyKey updates the Idempotency-Key to a new value

func (DefaultPaymentSelection) IdempotencyKey added in v3.0.1

func (d DefaultPaymentSelection) IdempotencyKey() string

IdempotencyKey returns the Idempotency-Key for this payment selection

func (DefaultPaymentSelection) ItemSplit

ItemSplit returns the selected split per ChargeType and PaymentMethod

func (DefaultPaymentSelection) MarshalJSON added in v3.0.1

func (d DefaultPaymentSelection) MarshalJSON() ([]byte, error)

MarshalJSON adds the Idempotency-Key to the payment selection json

func (DefaultPaymentSelection) MethodByType

func (d DefaultPaymentSelection) MethodByType(chargeType string) string

MethodByType returns the payment method by charge type

func (DefaultPaymentSelection) TotalValue

func (d DefaultPaymentSelection) TotalValue() price.Price

TotalValue returns returns Valued price sum

type DeferEvents

type DeferEvents []flamingo.Event

DeferEvents represents events that should be dispatched after a cart modify call

type Delivery

type Delivery struct {
	// DeliveryInfo contains details for this delivery e.g. how and where the delivery should be delivered to
	DeliveryInfo DeliveryInfo
	// Cartitems is the list of items belonging to this delivery
	Cartitems []Item
	// ShippingItem	represent the shipping cost that may be involved in this delivery
	ShippingItem ShippingItem

	// SubTotalGross contains the sum of row gross prices, without shipping/discounts
	SubTotalGross priceDomain.Price
	// SubTotalNet contains the sum of row net prices, without shipping/discounts
	SubTotalNet priceDomain.Price
	// TotalDiscountAmount contains the sum of all discounts (incl. shipping)
	TotalDiscountAmount priceDomain.Price
	// TotalDiscountAmount contains the sum of all discounts (excl. shipping)
	SubTotalDiscountAmount priceDomain.Price
	// NonItemRelatedDiscountAmount contains the sum of discounts that are not related to the item, e.g. a general promo
	NonItemRelatedDiscountAmount priceDomain.Price
	// ItemRelatedDiscountAmount contains the sum of discounts that are related to the item, e.g. promo due to product attribute
	ItemRelatedDiscountAmount priceDomain.Price
	// SubTotalGrossWithDiscounts contains the sum of row gross prices reduced by the applied discounts
	SubTotalGrossWithDiscounts priceDomain.Price
	// SubTotalNetWithDiscounts contains the sum of row net prices reduced by the net value of the applied discounts
	SubTotalNetWithDiscounts priceDomain.Price
	// GrandTotal contains the final price to pay
	GrandTotal priceDomain.Price
}

Delivery - represents the DeliveryInfo and the assigned Items

func (*Delivery) HasAppliedDiscounts

func (d *Delivery) HasAppliedDiscounts() (bool, error)

HasAppliedDiscounts check whether there are any discounts currently applied to the delivery

func (Delivery) HasItems

func (d Delivery) HasItems() bool

HasItems returns true if there are items under the delivery

func (*Delivery) MergeDiscounts

func (d *Delivery) MergeDiscounts() (AppliedDiscounts, error)

MergeDiscounts sums up discounts of a delivery based on its single item discounts All discounts with the same campaign code are aggregated and returned as one with a summed price

func (Delivery) SumRowTaxes

func (d Delivery) SumRowTaxes() Taxes

SumRowTaxes returns all taxes applied to items of this delivery

func (Delivery) SumTotalTaxAmount

func (d Delivery) SumTotalTaxAmount() priceDomain.Price

SumTotalTaxAmount returns the sum of all applied item taxes

type DeliveryInfo

type DeliveryInfo struct {
	// Code is a project specific identifier for the Delivery - you need it for the AddToCart Request for example
	// the code can follow the convention in the Readme: Type_Method_LocationType_LocationCode
	Code string
	// Workflow of the Delivery e.g. delivery or pickup, see DeliveryWorkflowPickup, DeliveryWorkflowDelivery or DeliveryWorkflowUnspecified
	Workflow string
	// Method is the shipping method something that is project specific and that can mean different delivery qualities with different delivery costs
	Method string
	// Carrier optional name of the Carrier that should be responsible for executing the delivery
	Carrier string
	// DeliveryLocation is the target location for the delivery
	DeliveryLocation DeliveryLocation
	// DesiredTime is an optional desired time for the delivery
	DesiredTime time.Time
	// AdditionalData can be used to store project specific information on the delivery
	AdditionalData map[string]string
	// AdditionalDeliveryInfos is similar to AdditionalData but can be used to store "any" other object on a delivery encoded as json.RawMessage
	AdditionalDeliveryInfos map[string]json.RawMessage `swaggerignore:"true"`
}

DeliveryInfo - represents the Delivery

func (DeliveryInfo) AdditionalDataKeys

func (di DeliveryInfo) AdditionalDataKeys() []string

AdditionalDataKeys lists all available keys

func (DeliveryInfo) AdditionalDeliveryInfoKeys

func (di DeliveryInfo) AdditionalDeliveryInfoKeys() []string

AdditionalDeliveryInfoKeys lists all available keys

func (DeliveryInfo) GetAdditionalData

func (di DeliveryInfo) GetAdditionalData(key string) string

GetAdditionalData returns additional data

func (DeliveryInfo) GetAdditionalDeliveryInfo

func (di DeliveryInfo) GetAdditionalDeliveryInfo(key string) json.RawMessage

GetAdditionalDeliveryInfo returns additional delivery info

func (*DeliveryInfo) LoadAdditionalInfo

func (di *DeliveryInfo) LoadAdditionalInfo(key string, info AdditionalDeliverInfo) error

LoadAdditionalInfo returns the additional Data

type DeliveryInfoBuilder

type DeliveryInfoBuilder interface {
	BuildByDeliveryCode(deliveryCode string) (*DeliveryInfo, error)
}

DeliveryInfoBuilder can be used to set delivery infos depending on supplied delivery code

type DeliveryInfoUpdateCommand

type DeliveryInfoUpdateCommand struct {
	DeliveryInfo DeliveryInfo
	// contains filtered or unexported fields
}

DeliveryInfoUpdateCommand defines the update item command

func CreateDeliveryInfoUpdateCommand

func CreateDeliveryInfoUpdateCommand(info DeliveryInfo) DeliveryInfoUpdateCommand

CreateDeliveryInfoUpdateCommand - factory to get the update command based on the given deliveryInfos (which might come from cart)

func (*DeliveryInfoUpdateCommand) AddAdditional

func (d *DeliveryInfoUpdateCommand) AddAdditional(key string, val AdditionalDeliverInfo) (err error)

AddAdditional adds additional delivery info data

func (*DeliveryInfoUpdateCommand) Additional

func (d *DeliveryInfoUpdateCommand) Additional() map[string]json.RawMessage

Additional gets the additional data as war map from the delivery info update command

func (*DeliveryInfoUpdateCommand) SetAdditional

func (d *DeliveryInfoUpdateCommand) SetAdditional(val map[string]json.RawMessage)

SetAdditional adds additional delivery info data

type DeliveryLocation

type DeliveryLocation struct {
	// Type is the type of the delivery - use some of the constant defined in the package like DeliverylocationTypeAddress
	Type string
	// Address contains the address of the delivery location, maybe not relevant if the type is not address
	Address *Address
	// UseBillingAddress if the address should be taken from billing (only relevant for type address)
	UseBillingAddress bool
	// Code is an optional identifier of this location/destination
	Code string
}

DeliveryLocation hold information about where the items should be delivered

type ExistingCustomerData

type ExistingCustomerData struct {
	// ID of the customer
	ID string
}

ExistingCustomerData value object

type GiftCardAndVoucherBehaviour

type GiftCardAndVoucherBehaviour interface {
	ApplyAny(ctx context.Context, cart *Cart, anyCode string) (*Cart, DeferEvents, error)
}

GiftCardAndVoucherBehaviour - additional interface that can be implemented to support generic code entry (which can either be voucher or giftcard)

type GiftCardBehaviour

type GiftCardBehaviour interface {
	ApplyGiftCard(ctx context.Context, cart *Cart, giftCardCode string) (*Cart, DeferEvents, error)
	RemoveGiftCard(ctx context.Context, cart *Cart, giftCardCode string) (*Cart, DeferEvents, error)
}

GiftCardBehaviour - additional interface that can be implemented to support GiftCard features

type GuestCartService

type GuestCartService interface {
	// GetModifyBehaviour gets the behaviour for the guest cart service
	GetModifyBehaviour(context.Context) (ModifyBehaviour, error)
	// GetCart for guest by unique cart id
	GetCart(ctx context.Context, cartID string) (*Cart, error)
	// GetNewCart - should return a new guest cart (including the id of the cart)
	GetNewCart(ctx context.Context) (*Cart, error)
	// RestoreCart restores a previously used guest cart with all its content.
	// Depending on the used adapter this can lead to a new Cart.ID
	// Deprecated: Implement CompleteBehaviour instead
	RestoreCart(ctx context.Context, cart Cart) (*Cart, error)
}

GuestCartService interface - Secondary PORT

type InvalidateCartEvent

type InvalidateCartEvent struct {
	Session *web.Session
}

InvalidateCartEvent value object

type Item

type Item struct {
	// ID of the item - needs to be unique over the whole cart
	ID string
	// ExternalReference can be used by cart service implementations to separate the representation in an external
	// cart service from the unique item ID
	ExternalReference string
	// MarketplaceCode is the identifier for the product
	MarketplaceCode string
	// VariantMarketPlaceCode is used for Configurable products
	VariantMarketPlaceCode string
	ProductName            string

	BundleConfig productDomain.BundleConfiguration

	// Source Id of where the items should be initial picked - This is set by the SourcingLogic
	SourceID string

	Qty int

	AdditionalData map[string]string

	// SinglePriceGross is the gross price (incl. taxes) for a single product
	SinglePriceGross priceDomain.Price

	// SinglePriceNet is the net price (excl. taxes) for a single product
	SinglePriceNet priceDomain.Price

	// RowPriceGross is the price incl. taxes for the whole Qty of products
	RowPriceGross priceDomain.Price

	// RowPriceGrossWithDiscount is the price incl. taxes with deducted discounts for the whole Qty of products
	// This is in most cases the final price for the customer to pay
	RowPriceGrossWithDiscount priceDomain.Price

	// RowPriceGrossWithItemRelatedDiscount is the price incl. taxes with deducted item related discounts for the whole Qty of products
	RowPriceGrossWithItemRelatedDiscount priceDomain.Price

	// RowPriceNet is the price excl. taxes for the whole Qty of products
	RowPriceNet priceDomain.Price

	// RowPriceNetWithDiscount is the discounted net price for the whole Qty of products
	RowPriceNetWithDiscount priceDomain.Price

	// RowPriceNetWithItemRelatedDiscount is the price excl. taxes with deducted item related discounts for the whole Qty of products
	RowPriceNetWithItemRelatedDiscount priceDomain.Price

	// RowTaxes is a list of all taxes applied for the given Qty of products
	RowTaxes Taxes

	// AppliedDiscounts contains the details about the discounts applied to this item - they can be "itemrelated" or not
	// itemrelated would be e.g. special price, buy 3 pay 2
	// non-itemrelated would be e.g. 10% on everything
	AppliedDiscounts AppliedDiscounts

	// TotalDiscountAmount is the sum of all applied discounts (aka the savings for the customer)
	TotalDiscountAmount priceDomain.Price

	// ItemRelatedDiscountAmount is the sum of all itemrelated Discounts
	ItemRelatedDiscountAmount priceDomain.Price

	// NonItemRelatedDiscountAmount is the sum of non-itemrelated Discounts where IsItemRelated = false
	NonItemRelatedDiscountAmount priceDomain.Price
}

Item for Cart

func (Item) AdditionalDataKeys

func (i Item) AdditionalDataKeys() []string

AdditionalDataKeys lists all available keys

func (Item) AdditionalDataValues

func (i Item) AdditionalDataValues() []string

AdditionalDataValues lists all values

func (Item) GetAdditionalData

func (i Item) GetAdditionalData(key string) string

GetAdditionalData returns a specified attribute

func (Item) HasAdditionalDataKey

func (i Item) HasAdditionalDataKey(key string) bool

HasAdditionalDataKey checks if an attribute is available

func (*Item) HasAppliedDiscounts

func (i *Item) HasAppliedDiscounts() (bool, error)

HasAppliedDiscounts check whether there are any discounts currently applied to the item

func (*Item) MergeDiscounts

func (i *Item) MergeDiscounts() (AppliedDiscounts, error)

MergeDiscounts parses discounts of a single item All discounts with the same campaign code are aggregated and returned as one with a summed price

func (Item) TotalTaxAmount

func (i Item) TotalTaxAmount() priceDomain.Price

TotalTaxAmount is the sum of all applied taxes for the whole Qty of products

type ItemSplitter

type ItemSplitter struct {
	// contains filtered or unexported fields
}

ItemSplitter used to split an item

func (*ItemSplitter) SplitInSingleQtyItems

func (s *ItemSplitter) SplitInSingleQtyItems(givenItem Item) ([]Item, error)

SplitInSingleQtyItems the given item into multiple items with Qty 1 and make sure the sum of the items prices matches by using SplitInPayables

type ItemUpdateCommand

type ItemUpdateCommand struct {
	// SourceID of where the items should be initially picked from - This is set by the SourcingLogic
	SourceID *string
	// Qty contains the item quantity
	Qty *int
	// AdditionalData contains item related data
	AdditionalData map[string]string
	// Mandatory field: ItemID is only for identifying the item.
	ItemID string
	// BundleConfiguration contains an updated config of a bundle
	BundleConfiguration productDomain.BundleConfiguration
}

ItemUpdateCommand defines the update item command

type ModifyBehaviour

type ModifyBehaviour interface {
	DeleteItem(ctx context.Context, cart *Cart, itemID string, deliveryCode string) (*Cart, DeferEvents, error)
	UpdateItem(ctx context.Context, cart *Cart, itemUpdateCommand ItemUpdateCommand) (*Cart, DeferEvents, error)
	UpdateItems(ctx context.Context, cart *Cart, itemUpdateCommands []ItemUpdateCommand) (*Cart, DeferEvents, error)
	AddToCart(ctx context.Context, cart *Cart, deliveryCode string, addRequest AddRequest) (*Cart, DeferEvents, error)
	CleanCart(ctx context.Context, cart *Cart) (*Cart, DeferEvents, error)
	CleanDelivery(ctx context.Context, cart *Cart, deliveryCode string) (*Cart, DeferEvents, error)
	UpdatePurchaser(ctx context.Context, cart *Cart, purchaser *Person, additionalData *AdditionalData) (*Cart, DeferEvents, error)
	UpdateAdditionalData(ctx context.Context, cart *Cart, additionalData *AdditionalData) (*Cart, DeferEvents, error)
	UpdatePaymentSelection(ctx context.Context, cart *Cart, paymentSelection PaymentSelection) (*Cart, DeferEvents, error)
	UpdateDeliveryInfo(ctx context.Context, cart *Cart, deliveryCode string, deliveryInfo DeliveryInfoUpdateCommand) (*Cart, DeferEvents, error)
	UpdateBillingAddress(ctx context.Context, cart *Cart, billingAddress Address) (*Cart, DeferEvents, error)
	UpdateDeliveryInfoAdditionalData(ctx context.Context, cart *Cart, deliveryCode string, additionalData *AdditionalData) (*Cart, DeferEvents, error)
	ApplyVoucher(ctx context.Context, cart *Cart, couponCode string) (*Cart, DeferEvents, error)
	RemoveVoucher(ctx context.Context, cart *Cart, couponCode string) (*Cart, DeferEvents, error)
}

ModifyBehaviour is a interface that can be implemented by other packages to provide cart actions This port can not be registered directly but is provided by the registered "GuestCartService"

type PaymentSelection

type PaymentSelection interface {
	Gateway() string
	// ChargeSplits - the selected split per ChargeType and PaymentMethod
	CartSplit() PaymentSplit
	// ChargeSplits - the selected split per ChargeType and PaymentMethod
	ItemSplit() PaymentSplitByItem
	TotalValue() price.Price
	MethodByType(string) string
	IdempotencyKey() string
	GenerateNewIdempotencyKey() (PaymentSelection, error)
}

PaymentSelection value object - that represents the payment selection on the cart

func NewDefaultPaymentSelection

func NewDefaultPaymentSelection(gateway string, chargeTypeToPaymentMethod map[string]string, cart Cart) (PaymentSelection, error)

NewDefaultPaymentSelection returns a PaymentSelection that can be used to update the cart is able to include gift card charges if applied to cart

func NewPaymentSelection

func NewPaymentSelection(gateway string, chargedItems PaymentSplitByItem) PaymentSelection

NewPaymentSelection - with the passed PaymentSplitByItem

func RemoveZeroCharges

func RemoveZeroCharges(selection PaymentSelection, chargeTypeToPaymentMethod map[string]string) PaymentSelection

RemoveZeroCharges removes charges which have an value of zero from selection as they are necessary for our internal calculations but not for external clients, we assume zero charges are ignored moreover charges are transformed to pay ables

type PaymentSplit

type PaymentSplit map[SplitQualifier]price.Charge

PaymentSplit represents the Charges qualified by Charge Type, Charge Reference and Payment Method

func (PaymentSplit) ChargesByType

func (s PaymentSplit) ChargesByType() price.Charges

ChargesByType returns Charges (a list of Charges summed by Type)

func (PaymentSplit) MarshalJSON

func (s PaymentSplit) MarshalJSON() ([]byte, error)

MarshalJSON serialize to json

func (PaymentSplit) TotalValue

func (s PaymentSplit) TotalValue() price.Price

TotalValue returns the sum of the valued Price in the included Charges in this Split

func (*PaymentSplit) UnmarshalJSON

func (s *PaymentSplit) UnmarshalJSON(data []byte) error

UnmarshalJSON deserialize from json

type PaymentSplitByItem

type PaymentSplitByItem struct {
	CartItems     map[string]PaymentSplit
	ShippingItems map[string]PaymentSplit
	TotalItems    map[string]PaymentSplit
}

PaymentSplitByItem - similar to value object that contains items of the different possible types, that have a price

func (PaymentSplitByItem) Sum

Sum returns the resulting Split after sum all the included item split

type PaymentSplitByItemBuilder

type PaymentSplitByItemBuilder struct {
	// contains filtered or unexported fields
}

PaymentSplitByItemBuilder - Builder to get valid PaymentSplitByItem instances

func (*PaymentSplitByItemBuilder) AddCartItem

func (pb *PaymentSplitByItemBuilder) AddCartItem(id string, method string, charge price.Charge) *PaymentSplitByItemBuilder

AddCartItem adds a cart items charge to the PaymentSplitByItem

func (*PaymentSplitByItemBuilder) AddShippingItem

func (pb *PaymentSplitByItemBuilder) AddShippingItem(deliveryCode string, method string, charge price.Charge) *PaymentSplitByItemBuilder

AddShippingItem adds shipping charge

func (*PaymentSplitByItemBuilder) AddTotalItem

func (pb *PaymentSplitByItemBuilder) AddTotalItem(totalType string, method string, charge price.Charge) *PaymentSplitByItemBuilder

AddTotalItem adds total item charge

func (*PaymentSplitByItemBuilder) Build

Build returns the instance of PaymentSplitByItem

type PaymentSplitService

type PaymentSplitService struct{}

PaymentSplitService enables the creation of a PaymentSplitByItem following different payment methods

func (PaymentSplitService) SplitWithGiftCards

func (service PaymentSplitService) SplitWithGiftCards(chargeTypeToPaymentMethod map[string]string, items PricedItems, cards AppliedGiftCards) (*PaymentSplitByItem, error)

SplitWithGiftCards calculates a payment selection based on given method, priced items and applied gift cards

type Person

type Person struct {
	Address         *Address
	PersonalDetails PersonalDetails
	// ExistingCustomerData if the current purchaser is an existing customer - this contains infos about existing customer
	ExistingCustomerData *ExistingCustomerData
}

Person value object

type PersonalDetails

type PersonalDetails struct {
	DateOfBirth     string
	PassportCountry string
	PassportNumber  string
	Nationality     string
}

PersonalDetails value object

type PricedItems

type PricedItems struct {
	// contains filtered or unexported fields
}

PricedItems - value object that contains items of the different possible types, that have a price

func (PricedItems) CartItems

func (p PricedItems) CartItems() map[string]domain.Price

CartItems returns the Price per cartItems - map key is cart item ID

func (PricedItems) ShippingItems

func (p PricedItems) ShippingItems() map[string]domain.Price

ShippingItems returns the Price per ShippingItems - map key is delivery code

func (PricedItems) Sum

func (p PricedItems) Sum() domain.Price

Sum returns Sum of all items in this struct

func (PricedItems) TotalItems

func (p PricedItems) TotalItems() map[string]domain.Price

TotalItems returns the Price per Totalitem - map key is total type

type ShippingItem

type ShippingItem struct {
	Title                   string
	PriceNet                priceDomain.Price
	PriceNetWithDiscounts   priceDomain.Price
	PriceGross              priceDomain.Price
	PriceGrossWithDiscounts priceDomain.Price
	TaxAmount               priceDomain.Price
	AppliedDiscounts        AppliedDiscounts
}

ShippingItem represents shipping costs that need to be paid by the customer

func (*ShippingItem) HasAppliedDiscounts

func (s *ShippingItem) HasAppliedDiscounts() (bool, error)

HasAppliedDiscounts checks whether there are any discounts currently applied to the shipping item

func (*ShippingItem) MergeDiscounts

func (s *ShippingItem) MergeDiscounts() (AppliedDiscounts, error)

MergeDiscounts parses discounts of a shipping item All discounts with the same campaign code are aggregated and returned as one with a summed price

func (ShippingItem) Tax

func (s ShippingItem) Tax() Tax

Tax is the Tax of the shipping

func (*ShippingItem) TotalWithDiscountInclTax

func (s *ShippingItem) TotalWithDiscountInclTax() domain.Price

TotalWithDiscountInclTax returns the final shipping price to pay Deprecated use public field PriceGrossWithDiscounts

type SplitQualifier

type SplitQualifier struct {
	ChargeType      string
	ChargeReference string
	Method          string
}

SplitQualifier qualifies by Charge Type, Charge Reference and Payment Method

type Tax

type Tax struct {
	Amount domain.Price
	Type   string
	Rate   *big.Float `swaggertype:"string"`
}

Tax is the Tax represented by an Amount and optional the Rate.

type Taxes

type Taxes []Tax

Taxes is a list of Tax

func (Taxes) AddTax

func (t Taxes) AddTax(tax Tax) Taxes

AddTax returns new Tax with this Tax added

func (Taxes) AddTaxWithMerge

func (t Taxes) AddTaxWithMerge(taxToAddOrMerge Tax) Taxes

AddTaxWithMerge returns new Taxes with this Tax added

func (Taxes) AddTaxesWithMerge

func (t Taxes) AddTaxesWithMerge(taxes Taxes) Taxes

AddTaxesWithMerge returns new Taxes with the given Taxes all added or merged in

func (Taxes) TotalAmount

func (t Taxes) TotalAmount() domain.Price

TotalAmount returns the sum of all taxes as price

type Teaser

type Teaser struct {
	ProductCount  int
	ItemCount     int
	DeliveryCodes []string
}

Teaser represents some teaser infos for cart

type Totalitem

type Totalitem struct {
	Code  string
	Title string
	Price domain.Price
	Type  string
}

Totalitem for totals

type WithDiscount

type WithDiscount interface {
	HasAppliedDiscounts() (bool, error)
	MergeDiscounts() (AppliedDiscounts, error)
}

WithDiscount interface for a cart that is able to handle discounts

type WithGiftCard

type WithGiftCard interface {
	HasRemainingGiftCards() bool
	HasAppliedGiftCards() bool
}

WithGiftCard interface for a cart that is able to handle gift cards

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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