flamingo.me/flamingo-commerce/v3@v3.11.0/checkout/domain/placeorder/process/state.go (about)

     1  package process
     2  
     3  import (
     4  	"context"
     5  
     6  	"flamingo.me/flamingo-commerce/v3/payment/application"
     7  )
     8  
     9  type (
    10  	// State interface
    11  	State interface {
    12  		Run(context.Context, *Process) RunResult
    13  		Rollback(context.Context, RollbackData) error
    14  		IsFinal() bool
    15  		Name() string
    16  	}
    17  
    18  	// RunResult of a state
    19  	RunResult struct {
    20  		RollbackData RollbackData
    21  		Failed       FailedReason
    22  	}
    23  
    24  	// FatalRollbackError which causes the premature end of rollback process
    25  	FatalRollbackError struct {
    26  		error error
    27  		State string
    28  	}
    29  
    30  	// PaymentValidatorFunc to decide over next state depending on payment situation
    31  	PaymentValidatorFunc func(ctx context.Context, p *Process, paymentService *application.PaymentService) RunResult
    32  )
    33  
    34  // NewFatalRollbackError mark a rollback error as fatal, this breaks the current rollback
    35  func NewFatalRollbackError(err error, stateName string) FatalRollbackError {
    36  	return FatalRollbackError{
    37  		error: err,
    38  		State: stateName,
    39  	}
    40  }
    41  
    42  func (f *FatalRollbackError) Error() string {
    43  	return f.error.Error()
    44  }