github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/configuration/CommunicatorConfiguration.go (about)

     1  package configuration
     2  
     3  import (
     4  	"net/url"
     5  	"time"
     6  
     7  	"github.com/Ingenico-ePayments/connect-sdk-go/defaultimpl"
     8  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/metadata"
     9  )
    10  
    11  // CommunicatorConfiguration represents the configuration to be used by a Communicator
    12  type CommunicatorConfiguration struct {
    13  	// APIEndpoint represents the API endpoint of for the communicator
    14  	// See https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/endpoints.html
    15  	APIEndpoint url.URL
    16  	// ConnectTimeout represents the connect timeout
    17  	ConnectTimeout time.Duration
    18  	// SocketTimeout represents the request timeout
    19  	SocketTimeout time.Duration
    20  	// IdleTimeout represents the idle connection timeout
    21  	IdleTimeout time.Duration
    22  	// KeepAliveTimeout represents the HTTP KeepAlive interval
    23  	KeepAliveTimeout time.Duration
    24  	// MaxConnections represents the maximum amount of concurrent pooled connections
    25  	MaxConnections int
    26  	// AuthorizationType represents authorizationType used to sign the requests
    27  	AuthorizationType defaultimpl.AuthorizationType
    28  	// APIKeyID represents an identifier for the secret API key
    29  	APIKeyID string
    30  	// SecretAPIKey represents a shared secret
    31  	SecretAPIKey string
    32  	// Proxy represents the URL for the connection proxy
    33  	Proxy *url.URL
    34  	// Integrator represents the integrator name
    35  	Integrator string
    36  	// ShoppingCartExtension represents the shopping cart extension used in the MetaData headers
    37  	ShoppingCartExtension *metadata.ShoppingCartExtension
    38  }
    39  
    40  // The default configuration used by the factory is the following:
    41  // APIEndpoint: world.api-ingenico.com
    42  // ConnectTimeout: 5 seconds
    43  // SocketTimeout: 30 seconds
    44  // IdleTimeout: 5 seconds
    45  // KeepAliveTimeout: 30 seconds
    46  // MaxConnections: 10
    47  // AuthorizationType: V1HMAC
    48  // Proxy: none
    49  var defaultConfiguration = CommunicatorConfiguration{
    50  	APIEndpoint: url.URL{
    51  		Scheme: "https",
    52  		Host:   "world.api-ingenico.com",
    53  	},
    54  	ConnectTimeout:    5 * time.Second,
    55  	SocketTimeout:     30 * time.Second,
    56  	IdleTimeout:       5 * time.Second,
    57  	KeepAliveTimeout:  30 * time.Second,
    58  	MaxConnections:    10,
    59  	AuthorizationType: defaultimpl.V1HMAC,
    60  }
    61  
    62  // DefaultConfiguration returns the default communicator configuration
    63  func DefaultConfiguration(apiKeyID, secretAPIKey, integrator string) CommunicatorConfiguration {
    64  	customizedConfiguration := defaultConfiguration
    65  
    66  	customizedConfiguration.Integrator = integrator
    67  	customizedConfiguration.SecretAPIKey = secretAPIKey
    68  	customizedConfiguration.APIKeyID = apiKeyID
    69  
    70  	return customizedConfiguration
    71  }