Exemple #1
0
 void AssertBasicConfigurationSettings(CommunicatorConfiguration configuration)
 {
     Assert.AreEqual(new Uri("https://" + BaseUriHost), configuration.ApiEndpoint);
     Assert.AreEqual(AuthorizationType.V1HMAC, configuration.AuthorizationType);
     Assert.AreEqual(20000, configuration.ConnectTimeout?.TotalMilliseconds);
     Assert.AreEqual(10000, configuration.SocketTimeout?.TotalMilliseconds);
 }
Exemple #2
0
        public void TestConstructFromPropertiesWithoutProxy()
        {
            CommunicatorConfiguration configuration = CreateBasicConfiguration();

            AssertBasicConfigurationSettings(configuration);
            Assert.AreEqual(CommunicatorConfiguration.DefaultMaxConnections, configuration.MaxConnections);
            Assert.Null(configuration.ApiKeyId);
            Assert.Null(configuration.SecretApiKey);
        }
Exemple #3
0
        public void TestCreateConfiguration()
        {
            CommunicatorConfiguration configuration = Factory.CreateConfiguration(
                DICT, API_KEY_ID, SECRET_API_KEY);

            Assert.AreEqual(new Uri("https://payment.preprod.online-payments.com"), configuration.ApiEndpoint);
            Assert.AreEqual(AuthorizationType.V1HMAC, configuration.AuthorizationType);
            Assert.AreEqual(-1, configuration.ConnectTimeout?.TotalMilliseconds);
            Assert.AreEqual(-1, configuration.SocketTimeout?.TotalMilliseconds);
            Assert.AreEqual(100, configuration.MaxConnections);
            Assert.AreEqual(API_KEY_ID, configuration.ApiKeyId);
            Assert.AreEqual(SECRET_API_KEY, configuration.SecretApiKey);
        }
Exemple #4
0
        public void TestConstructFromPropertiesWithIPv6Host()
        {
            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties["onlinePayments.api.endpoint.host"]     = "::1";
            properties["onlinePayments.api.authorizationType"] = AuthType;
            properties["onlinePayments.api.connectTimeout"]    = "20000";
            properties["onlinePayments.api.socketTimeout"]     = "10000";

            CommunicatorConfiguration configuration = new CommunicatorConfiguration(properties);

            Assert.AreEqual(new Uri("https://[::1]"), configuration.ApiEndpoint);
        }
Exemple #5
0
        public void TestConstructFromPropertiesWithHostAndScheme()
        {
            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties["onlinePayments.api.endpoint.scheme"]   = "http";
            properties["onlinePayments.api.endpoint.host"]     = BaseUriHost;
            properties["onlinePayments.api.authorizationType"] = AuthType;
            properties["onlinePayments.api.connectTimeout"]    = "20000";
            properties["onlinePayments.api.socketTimeout"]     = "10000";

            CommunicatorConfiguration configuration = new CommunicatorConfiguration(properties);

            Assert.AreEqual(new Uri("http://" + BaseUriHost), configuration.ApiEndpoint);
        }
Exemple #6
0
        public void TestConstructFromPropertiesWithProxyWithoutAuthentication()
        {
            CommunicatorConfiguration configuration = CreateBasicConfiguration()
                                                      .WithProxyUri(new Uri("http://proxy.example.org:3128"));

            AssertBasicConfigurationSettings(configuration);
            Assert.AreEqual(CommunicatorConfiguration.DefaultMaxConnections, configuration.MaxConnections);
            Assert.Null(configuration.ApiKeyId);
            Assert.Null(configuration.SecretApiKey);

            Assert.NotNull(configuration.ProxyConfiguration);
            ProxyConfiguration proxyFig = configuration.ProxyConfiguration;

            AssertBasicProxySettings(proxyFig);
            Assert.That(proxyFig.Username, Is.Empty);
            Assert.That(proxyFig.Password, Is.Empty);
        }
Exemple #7
0
        /// <summary>
        /// Creates a <see cref="CommunicatorBuilder"/> based on the passed configuration.
        /// </summary>
        /// <returns>The communicator builder that can still be changed.</returns>
        public static CommunicatorBuilder CreateCommunicatorBuilder(CommunicatorConfiguration configuration)
        {
            MetaDataProvider metaDataProvider = new MetaDataProviderBuilder(configuration.Integrator)
                                                .WithShoppingCartExtension(configuration.ShoppingCartExtension)
                                                .Build();

            return(new CommunicatorBuilder()
                   .WithApiEndpoint(configuration.ApiEndpoint)
                   .WithConnection(new DefaultConnection(
                                       configuration.ProxyConfiguration,
                                       configuration.SocketTimeout,
                                       // connection timeout not supported
                                       configuration.MaxConnections))
                   .WithAuthenticator(new DefaultAuthenticator(
                                          configuration.AuthorizationType,
                                          configuration.ApiKeyId,
                                          configuration.SecretApiKey
                                          ))
                   .WithMarshaller(DefaultMarshaller.Instance)
                   .WithMetaDataProvider(metaDataProvider));
        }
Exemple #8
0
        /// <summary>
        /// Creates a <see cref="CommunicatorBuilder"/> based on the configuration
        /// values in <c>configurationDictionary</c>, <c>apiKeyId</c> and
        /// <c>secretApiKey</c>.
        /// </summary>
        /// <param name="configurationDictionary">Dictionary containing configuration.</param>
        /// <param name="apiKeyId">The API key identifier.</param>
        /// <param name="secretApiKey">The secret API key.</param>
        /// <returns>The communicator builder that can still be changed.</returns>
        public static CommunicatorBuilder CreateCommunicatorBuilder(IDictionary <string, string> configurationDictionary, string apiKeyId, string secretApiKey)
        {
            CommunicatorConfiguration configuration = CreateConfiguration(configurationDictionary, apiKeyId, secretApiKey);

            return(CreateCommunicatorBuilder(configuration));
        }
Exemple #9
0
        /// <summary>
        /// Creates a <see cref="CommunicatorBuilder"/> based on the provided values.
        /// </summary>
        /// <param name="apiKeyId">The API key identifier.</param>
        /// <param name="secretApiKey">The secret API key.</param>
        /// <param name="apiEndpoint">The URI of the payment platform.</param>
        /// <param name="integrator">The integrator of the SDK.</param>
        /// <returns>The communicator builder that can still be changed.</returns>
        public static CommunicatorBuilder CreateCommunicatorBuilder(string apiKeyId, string secretApiKey, Uri apiEndpoint, String integrator)
        {
            CommunicatorConfiguration configuration = CreateConfiguration(apiKeyId, secretApiKey, apiEndpoint, integrator);

            return(CreateCommunicatorBuilder(configuration));
        }
Exemple #10
0
 /// <summary>
 /// Creates a <see cref="Client"/> based on the passed configuration.
 /// </summary>
 public static IClient CreateClient(CommunicatorConfiguration configuration)
 {
     return(CreateClient(CreateCommunicator(configuration)));
 }
Exemple #11
0
 /// <summary>
 /// Creates a <see cref="ICommunicator"/> based on the passed configuration.
 /// </summary>
 public static ICommunicator CreateCommunicator(CommunicatorConfiguration configuration)
 {
     return(CreateCommunicatorBuilder(configuration)
            .Build());
 }