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

     1  package states
     2  
     3  import (
     4  	"context"
     5  	"encoding/gob"
     6  	"net/url"
     7  
     8  	"flamingo.me/flamingo-commerce/v3/checkout/domain/placeorder/process"
     9  	"flamingo.me/flamingo-commerce/v3/payment/application"
    10  	"go.opencensus.io/trace"
    11  )
    12  
    13  type (
    14  	// Redirect state
    15  	Redirect struct {
    16  		paymentService *application.PaymentService
    17  		validator      process.PaymentValidatorFunc
    18  	}
    19  )
    20  
    21  var _ process.State = Redirect{}
    22  
    23  func init() {
    24  	gob.Register(&url.URL{})
    25  }
    26  
    27  // NewRedirectStateData creates data required for this state
    28  func NewRedirectStateData(url *url.URL) process.StateData {
    29  	return process.StateData(url)
    30  }
    31  
    32  // Inject dependencies
    33  func (r *Redirect) Inject(
    34  	paymentService *application.PaymentService,
    35  	validator process.PaymentValidatorFunc,
    36  ) *Redirect {
    37  	r.paymentService = paymentService
    38  	r.validator = validator
    39  
    40  	return r
    41  }
    42  
    43  // Name get state name
    44  func (Redirect) Name() string {
    45  	return "Redirect"
    46  }
    47  
    48  // Run the state operations
    49  func (r Redirect) Run(ctx context.Context, p *process.Process) process.RunResult {
    50  	ctx, span := trace.StartSpan(ctx, "placeorder/state/Redirect/Run")
    51  	defer span.End()
    52  
    53  	return r.validator(ctx, p, r.paymentService)
    54  }
    55  
    56  // Rollback the state operations
    57  func (r Redirect) Rollback(ctx context.Context, _ process.RollbackData) error {
    58  	return nil
    59  }
    60  
    61  // IsFinal if state is a final state
    62  func (r Redirect) IsFinal() bool {
    63  	return false
    64  }