Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DirectPaymentClient"/> class.
        /// </summary>
        /// <param name="baseUri">Base URI.</param>
        /// <param name="credentials">Account credentials.</param>
        /// <param name="handler">HTTP client handler.</param>
        /// <exception cref="ArgumentException">Thrown if the base URI is null or empty.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="credentials"/> or <paramref name="handler"/> is null.</exception>
        public DirectPaymentClient(string baseUri, DirectPaymentCredentials credentials, HttpClientHandler handler)
        {
            if (string.IsNullOrEmpty(baseUri))
            {
                throw new ArgumentException("Argument is null or empty", nameof(baseUri));
            }

            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }

            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            if (baseUri.EndsWith("/"))
            {
                baseUri = baseUri.Substring(0, baseUri.Length - 1);
            }

            _client = new HttpClient(handler)
            {
                BaseAddress           = new Uri($"{baseUri}/{credentials.ServiceId}/"),
                DefaultRequestHeaders = { Authorization = new AuthenticationHeaderValue("Basic", credentials.ToBasicAuthBase64String()) }
            };
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DirectPaymentClient"/> class.
 /// </summary>
 /// <param name="credentials">Account credentials.</param>
 public DirectPaymentClient(DirectPaymentCredentials credentials)
     : this(BaseUri, credentials, new HttpClientHandler())
 {
 }