github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/communicator/SessionBuilder.go (about) 1 package communicator 2 3 import "net/url" 4 5 // SessionBuilder is the builder for Session objects 6 type SessionBuilder struct { 7 APIEndpoint *url.URL 8 Connection Connection 9 MetaDataProvider *MetaDataProvider 10 Authenticator Authenticator 11 } 12 13 // WithAPIEndpoint sets the Ingenico ePayments platform API endpoint to be used by the Session 14 func (s *SessionBuilder) WithAPIEndpoint(endpoint *url.URL) *SessionBuilder { 15 s.APIEndpoint = endpoint 16 17 return s 18 } 19 20 // WithConnection sets the Connection to be used by the Session 21 func (s *SessionBuilder) WithConnection(connection Connection) *SessionBuilder { 22 s.Connection = connection 23 24 return s 25 } 26 27 // WithMetaDataProvider sets the MetaDataProvider to be used by the Session 28 func (s *SessionBuilder) WithMetaDataProvider(provider *MetaDataProvider) *SessionBuilder { 29 s.MetaDataProvider = provider 30 31 return s 32 } 33 34 // WithAuthenticator sets the Authenticator to be used by the Session 35 func (s *SessionBuilder) WithAuthenticator(auth Authenticator) *SessionBuilder { 36 s.Authenticator = auth 37 38 return s 39 } 40 41 // Build creates a Session object based on the builder parameters 42 func (s *SessionBuilder) Build() (*Session, error) { 43 return NewSession(s.APIEndpoint, s.Connection, s.Authenticator, s.MetaDataProvider) 44 } 45 46 // NewSessionBuilder creates a SessionBuilder object 47 func NewSessionBuilder() (*SessionBuilder, error) { 48 return &SessionBuilder{}, nil 49 }