cart

package
v0.0.0-...-6bf1803 Latest Latest
Warning

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

Jump to

Keyboard shortcuts

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