placeorder

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: 19 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// ValidatePaymentErrorNoActionURL used for errors when the needed URL is missing from the ActionData struct
	ValidatePaymentErrorNoActionURL = "no url set for action"
	// ValidatePaymentErrorNoWalletDetails used for errors when the needed URL is missing from the ActionData struct
	ValidatePaymentErrorNoWalletDetails = "no wallet details set for action"
	// ValidatePaymentErrorNoActionDisplayData used for errors when the needed DisplayData/HTML is missing from the ActionData struct
	ValidatePaymentErrorNoActionDisplayData = "no display data / html set for action"
)

Variables

View Source
var (
	// ErrLockTaken to indicate the lock is taken (by another running process)
	ErrLockTaken = errors.New("lock already taken")
	// ErrNoPlaceOrderProcess if a requested process not running
	ErrNoPlaceOrderProcess = errors.New("ErrNoPlaceOrderProcess")
	// ErrAnotherPlaceOrderProcessRunning if a process runs
	ErrAnotherPlaceOrderProcessRunning = errors.New("ErrAnotherPlaceOrderProcessRunning")
)

Functions

func PaymentValidator

func PaymentValidator(ctx context.Context, p *process.Process, paymentService *application.PaymentService) process.RunResult

PaymentValidator to decide over the next state

Types

type CancelPlaceOrderCommand

type CancelPlaceOrderCommand struct {
}

CancelPlaceOrderCommand cancels current running process

type Coordinator

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

Coordinator ensures that certain parts of the place order process are only done once at a time

func (*Coordinator) Cancel

func (c *Coordinator) Cancel(ctx context.Context) error

Cancel the process if it exists (blocking) be aware that all rollback callbacks are executed

func (*Coordinator) ClearLastProcess

func (c *Coordinator) ClearLastProcess(ctx context.Context) error

ClearLastProcess removes last stored process

func (*Coordinator) HasUnfinishedProcess

func (c *Coordinator) HasUnfinishedProcess(ctx context.Context) (bool, error)

HasUnfinishedProcess checks for processes not in final state

func (*Coordinator) Inject

func (c *Coordinator) Inject(
	locker TryLocker,
	logger flamingo.Logger,
	processFactory *process.Factory,
	contextStore process.ContextStore,
	sessionStore *web.SessionStore,
	cartService *application.CartService,
	cfg *struct {
		SessionName string `inject:"config:flamingo.session.name,optional"`
		Area        string `inject:"config:area"`
	},
)

Inject dependencies

func (*Coordinator) LastProcess

func (c *Coordinator) LastProcess(ctx context.Context) (*process.Process, error)

LastProcess current place order process

func (*Coordinator) New

func (c *Coordinator) New(ctx context.Context, cart cartDomain.Cart, returnURL *url.URL) (*process.Context, error)

New acquires lock if possible and creates new process with first run call blocking returns error if already locked or error during run

func (*Coordinator) Run

func (c *Coordinator) Run(ctx context.Context)

Run starts the next processing if not already running Run is NOP if the process is locked Run returns immediately

func (*Coordinator) RunBlocking

func (c *Coordinator) RunBlocking(ctx context.Context) (*process.Context, error)

RunBlocking waits for the lock and starts the next processing RunBlocking waits until the process is finished and returns its result

type Handler

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

Handler for handling PlaceOrder related commands

func (*Handler) CancelPlaceOrder

func (h *Handler) CancelPlaceOrder(ctx context.Context, _ CancelPlaceOrderCommand) error

CancelPlaceOrder handles order cancellation, is blocking

func (*Handler) ClearPlaceOrder

func (h *Handler) ClearPlaceOrder(ctx context.Context) error

ClearPlaceOrder clears the last placed order from the context store, only possible if order in final state

func (*Handler) CurrentContext

func (h *Handler) CurrentContext(ctx context.Context) (*process.Context, error)

CurrentContext returns the last saved state

func (*Handler) HasUnfinishedProcess

func (h *Handler) HasUnfinishedProcess(ctx context.Context) (bool, error)

HasUnfinishedProcess checks for processes not in final state

func (*Handler) Inject

func (h *Handler) Inject(
	c *Coordinator,
) *Handler

Inject dependencies

func (*Handler) RefreshPlaceOrder

func (h *Handler) RefreshPlaceOrder(ctx context.Context, _ RefreshPlaceOrderCommand) (*process.Context, error)

RefreshPlaceOrder handles RefreshPlaceOrder command

func (*Handler) RefreshPlaceOrderBlocking

func (h *Handler) RefreshPlaceOrderBlocking(ctx context.Context, _ RefreshPlaceOrderCommand) (*process.Context, error)

RefreshPlaceOrderBlocking handles RefreshPlaceOrder blocking

func (*Handler) StartPlaceOrder

func (h *Handler) StartPlaceOrder(ctx context.Context, command StartPlaceOrderCommand) (*process.Context, error)

StartPlaceOrder handles start place order command

type RefreshPlaceOrderCommand

type RefreshPlaceOrderCommand struct {
}

RefreshPlaceOrderCommand proceeds in place order process

type StartPlaceOrderCommand

type StartPlaceOrderCommand struct {
	Cart      cartDomain.Cart
	ReturnURL *url.URL
}

StartPlaceOrderCommand triggers new place order

type TryLocker

type TryLocker interface {
	// TryLock tries to get the lock for the provided key, if lock is already taken or couldn't be acquired function
	// returns an error. If the lock could be acquired a unlock function is returned which should be called to release the lock.
	// The provided duration is used in case that the node which required the lock dies so that the lock can released anyways.
	// If the node stays alive the lock time is not restricted in any way.
	TryLock(ctx context.Context, key string, maxLockDuration time.Duration) (Unlock, error)
}

TryLocker port for a locking implementation

type Unlock

type Unlock func() error

Unlock function to release the previously acquired lock, should be called within defer

Jump to

Keyboard shortcuts

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