flamingo.me/flamingo-commerce/v3@v3.11.0/checkout/domain/placeorder/states/success.go (about) 1 package states 2 3 import ( 4 "context" 5 6 "flamingo.me/flamingo-commerce/v3/checkout/domain/placeorder/process" 7 "flamingo.me/flamingo/v3/framework/flamingo" 8 "go.opencensus.io/trace" 9 ) 10 11 type ( 12 // Success state 13 Success struct { 14 eventRouter flamingo.EventRouter 15 } 16 17 // SuccessEvent is dispatched when the final success state runs 18 SuccessEvent struct { 19 ProcessContext process.Context 20 } 21 ) 22 23 var _ process.State = Success{} 24 25 // Inject dependencies 26 func (s *Success) Inject( 27 eventRouter flamingo.EventRouter, 28 ) *Success { 29 s.eventRouter = eventRouter 30 31 return s 32 } 33 34 // Name get state name 35 func (s Success) Name() string { 36 return "Success" 37 } 38 39 // Run the state operations 40 func (s Success) Run(ctx context.Context, p *process.Process) process.RunResult { 41 _, span := trace.StartSpan(ctx, "placeorder/state/Success/Run") 42 defer span.End() 43 44 s.eventRouter.Dispatch(ctx, &SuccessEvent{ 45 ProcessContext: p.Context(), 46 }) 47 48 return process.RunResult{} 49 } 50 51 // Rollback the state operations 52 func (s Success) Rollback(_ context.Context, _ process.RollbackData) error { 53 return nil 54 } 55 56 // IsFinal if state is a final state 57 func (s Success) IsFinal() bool { 58 return true 59 }