Version: v0.0.0-...-6bf1803 Latest Latest

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

Go to latest
Published: Nov 17, 2020 License: Apache-2.0 Imports: 4 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type Cart

type Cart struct {
	// contains filtered or unexported fields

Cart represents the actions that you can perform on a cart

func New

func New(inventory InventoryAPI, payments PaymentsAPI, cartContents shoppingCart.CartStore) *Cart

New starts a new cart

func (*Cart) AddProductToCart

func (c *Cart) AddProductToCart(userID string, prod Product) (*Contents, error)

AddProductToCart adds a bew product to the cart (or updates the existing item quantity if some already present)

func (*Cart) Checkout

func (c *Cart) Checkout(userID string) (*Contents, error)

Checkout attempts to perform checkout of the current cart contents

type Contents

type Contents struct {
	Products []*Product `json:"products"`

Contents represents the contents of the cart

type InventoryAPI

type InventoryAPI interface {
	// Check if product is in sufficient stock
	HasInStock(productID uint, quantity uint) (bool, error)
	// GetPrice returns the price of an item
	GetPrice(productID uint) (uint, error)
	// Renove from stock removes items from stock, but restores the previous values of False is sent over the commitChan
	RemoveFromStock(items map[uint]uint, commitChan <-chan bool, errorChan chan<- error) error

InventoryAPI represents the methods that need to be implemented by the inventory API

type PaymentsAPI

type PaymentsAPI interface {
	// MakePayment tries to call the payment API
	MakePayment(client string, money uint) error

PaymentsAPI represents the methods that need to be implemented by the payments API

type Product

type Product struct {
	ID       uint `json:"id"`
	Quantity uint `json:"quantity"`

Product represents a product added to the cart

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL