diff --git a/order/order_get_set.go b/order/order_get_set.go index fb86780..670fa97 100644 --- a/order/order_get_set.go +++ b/order/order_get_set.go @@ -11,6 +11,8 @@ import ( "github.com/foomo/shop/version" ) +var ErrorInconsistentStateTransition = errors.New("state transition now allowed") + //------------------------------------------------------------------ // ~ SIMPLE GETTERS ON ORDER //------------------------------------------------------------------ @@ -207,6 +209,16 @@ func (order *Order) SetFraudInvestigationState(state FraudInvestigationState) er if order.Processing == nil { return errors.New("Processing is nil") } + currentState := order.Processing.FraudInvestigationState + if currentState == state { + return nil // state is already set + } + + // avoid overriding of "final" states approved and rejected + if currentState == FraudInvestigationStateApproved || currentState == FraudInvestigationStateRejected { + return ErrorInconsistentStateTransition + } + order.Processing.FraudInvestigationState = state return order.Upsert() }