public void TestCreateCommunicator() { ICommunicator communicatorInterface = Factory.CreateCommunicator(DICT, API_KEY_ID, SECRET_API_KEY); Assert.IsInstanceOf <Communicator>(communicatorInterface); Communicator communicator = (Communicator)communicatorInterface; Assert.AreSame(DefaultMarshaller.Instance, communicator.Marshaller); IConnection connection = communicator.Connection; Assert.True(connection is DefaultConnection); IAuthenticator authenticator = communicator.Authenticator; Assert.True(authenticator is DefaultAuthenticator); Assert.AreEqual(AuthorizationType.V1HMAC, GetInstanceField(typeof(DefaultAuthenticator), authenticator, "_authorizationType")); Assert.AreEqual(API_KEY_ID, GetInstanceField(typeof(DefaultAuthenticator), authenticator, "_apiKeyId")); Assert.AreEqual(SECRET_API_KEY, GetInstanceField(typeof(DefaultAuthenticator), authenticator, "_secretApiKey")); MetaDataProvider metaDataProvider = communicator.MetaDataProvider; Assert.AreEqual(typeof(MetaDataProvider), metaDataProvider.GetType()); IEnumerable <RequestHeader> requestHeaders = metaDataProvider.ServerMetaDataHeaders; Assert.AreEqual(1, requestHeaders.Count()); RequestHeader requestHeader = requestHeaders.ElementAt(0); Assert.AreEqual("X-GCS-ServerMetaInfo", requestHeader.Name); }
public void TestGetServerMetaDataHeadersNoAdditionalHeaders() { MetaDataProvider metaDataProvider = new MetaDataProvider("OnlinePayments"); IEnumerable <RequestHeader> requestHeaders = metaDataProvider.ServerMetaDataHeaders; Assert.AreEqual(1, requestHeaders.Count()); RequestHeader requestHeader = requestHeaders.First(); AssertServerMetaInfo(metaDataProvider, requestHeader); }
void AssertServerMetaInfo(MetaDataProvider metaDataProvider, RequestHeader requestHeader) { Assert.AreEqual(requestHeader.Name, "X-GCS-ServerMetaInfo"); Assert.NotNull(requestHeader.Value); byte[] data = Convert.FromBase64String(requestHeader.Value); string serverMetaInfoJson = Encoding.UTF8.GetString(data); MetaDataProvider.ServerMetaInfo serverMetaInfo = DefaultMarshaller.Instance.Unmarshal <MetaDataProvider.ServerMetaInfo>(serverMetaInfoJson); Assert.AreEqual(metaDataProvider.SdkIdentifier, serverMetaInfo.SdkIdentifier); Assert.AreEqual("OnlinePayments", serverMetaInfo.SdkCreator); Assert.AreEqual(metaDataProvider.PlatformIdentifier, serverMetaInfo.PlatformIdentifier); }
public Communicator(Uri apiEndpoint, IConnection connection, IAuthenticator authenticator, MetaDataProvider metaDataProvider, IMarshaller marshaller) { ApiEndpoint = apiEndpoint ?? throw new ArgumentException("apiEndpoint is required"); if (ApiEndpoint.LocalPath != null && ApiEndpoint.LocalPath.Length > 0 && !ApiEndpoint.LocalPath.Equals("/")) { throw new ArgumentException("apiEndpoint should not contain a path"); } if (!ApiEndpoint.UserInfo.Equals("") || !ApiEndpoint.Query.Equals("") || !ApiEndpoint.Fragment.Equals("")) { throw new ArgumentException("apiEndpoint should not contain user info, query or fragment"); } Connection = connection ?? throw new ArgumentException("connection is required"); Authenticator = authenticator ?? throw new ArgumentException("authenticator is required"); MetaDataProvider = metaDataProvider ?? throw new ArgumentException("metaDataProvider is required"); Marshaller = marshaller ?? throw new ArgumentException("marshaller is required"); // Per PCI requirements only connections using TLS 1.2 and higher are supported by the payment platform. ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; }
public static void CheckWithAdditionalRequestHeader(string additionalHeaderName, bool isAllowed) { RequestHeader additionalRequestHeader = new RequestHeader(additionalHeaderName, Guid.NewGuid().ToString()); MetaDataProviderBuilder builder = new MetaDataProviderBuilder("OnlinePayments"); if (isAllowed) { MetaDataProvider metaDataProvider = builder.WithAdditionalRequestHeader(additionalRequestHeader).Build(); IEnumerable <RequestHeader> requestHeaders = metaDataProvider.ServerMetaDataHeaders; Assert.AreEqual(2, requestHeaders.Count()); RequestHeader requestHeader = requestHeaders.First(); Assert.AreEqual("X-GCS-ServerMetaInfo", requestHeader.Name); requestHeader = requestHeaders.Skip(1).First(); Assert.AreEqual(requestHeader, additionalRequestHeader); } else { Assert.That((() => builder.WithAdditionalRequestHeader(additionalRequestHeader)), Throws.ArgumentException.With.Message.Contains(additionalHeaderName)); } }
/// <summary> /// Creates a <see cref="Client"/> based on the passed fields. /// </summary> /// <param name="apiEndpoint">The payment platform API endpoint URI to use.</param> /// <param name="connection">The <see cref="IConnection"/> to use.</param> /// <param name="authenticator">The <see cref="IAuthenticator"/> to use.</param> /// <param name="metaDataProvider">The <see cref="MetaDataProvider"/> to use.</param> public static IClient CreateClient(Uri apiEndpoint, IConnection connection, IAuthenticator authenticator, MetaDataProvider metaDataProvider) { return(CreateClient(CreateCommunicator(apiEndpoint, connection, authenticator, metaDataProvider))); }
/// <summary> /// Creates a <see cref="ICommunicator"/> based on the passed fields. /// </summary> /// <param name="apiEndpoint">The payment platform API endpoint URI to use.</param> /// <param name="connection">The <see cref="IConnection"/> to use.</param> /// <param name="authenticator">The <see cref="IAuthenticator"/> to use.</param> /// <param name="metaDataProvider">The <see cref="MetaDataProvider"/> to use.</param> /// <param name="marshaller">The <see cref="IMarshaller"/> to use.</param> public static ICommunicator CreateCommunicator(Uri apiEndpoint, IConnection connection, IAuthenticator authenticator, MetaDataProvider metaDataProvider, IMarshaller marshaller) { return(new CommunicatorBuilder() .WithApiEndpoint(apiEndpoint) .WithConnection(connection) .WithMetaDataProvider(metaDataProvider) .WithAuthenticator(authenticator) .WithMarshaller(marshaller) .Build()); }
/// <summary> /// Creates a <see cref="ICommunicator"/> based on the passed fields. /// </summary> /// <param name="apiEndpoint">The payment platform API endpoint URI to use.</param> /// <param name="connection">The <see cref="IConnection"/> to use.</param> /// <param name="authenticator">The <see cref="IAuthenticator"/> to use.</param> /// <param name="metaDataProvider">The <see cref="MetaDataProvider"/> to use.</param> public static ICommunicator CreateCommunicator(Uri apiEndpoint, IConnection connection, IAuthenticator authenticator, MetaDataProvider metaDataProvider) { return(CreateCommunicator(apiEndpoint, connection, authenticator, metaDataProvider, DefaultMarshaller.Instance)); }
/// <summary> /// Sets the <see cref="MetaDataProvider"/> to use. /// </summary> /// <param name="metaDataProvider">Meta data provider.</param> /// <returns>This.</returns> public CommunicatorBuilder WithMetaDataProvider(MetaDataProvider metaDataProvider) { _metaDataProvider = metaDataProvider; return(this); }