Esempio n. 1
0
        public Configuration(
            string login,
            string tranKey,
            Uri url,
            string requestType,
            Dictionary <string, string> additional = null,
            AuthenticationSecurity auth            = null
            )
        {
            this.login   = login;
            this.tranKey = tranKey;

            if (url.ToString().EndsWith("/"))
            {
                this.url = url;
            }
            else
            {
                this.url = new Uri($"{url}/");
            }

            this.requestType = requestType;
            this.additional  = additional;
            this.auth        = auth;
        }
Esempio n. 2
0
        public Configuration(JObject data)
        {
            login   = data.GetValue(LOGIN).ToString();
            tranKey = data.GetValue(TRANKEY).ToString();

            if (data.GetValue(URL).ToString().EndsWith("/"))
            {
                url = new Uri(data.GetValue(URL).ToString());
            }
            else
            {
                url = new Uri($"{data.GetValue(URL)}/");
            }

            requestType = data.GetValue(TYPE).ToString();

            if (data.ContainsKey(ADDITIONAL))
            {
                var additionData = data.GetValue(ADDITIONAL).ToObject <JObject>();

                foreach (var item in additionData)
                {
                    additional.Add(item.Key, (string)item.Value);
                }
            }

            if (data.ContainsKey(AUTH))
            {
                auth = new AuthenticationSecurity(data.GetValue(AUTH).ToString());
            }
        }
        /// <summary>
        /// Generate auth data.
        /// </summary>
        /// <returns>Authentication</returns>
        public Authentication Generate()
        {
            if (!overrided)
            {
                auth = new AuthenticationSecurity(GetSeed(), GetNonce());
            }

            return(this);
        }
        /// <summary>
        /// Authentication constructor.
        /// </summary>
        /// <param name="data">JObject</param>
        public Authentication(JObject data)
        {
            if (!data.ContainsKey(LOGIN) || !data.ContainsKey(TRANKEY))
            {
                throw new PlacetoPayException("No login or tranKey provided on authentication");
            }

            login   = data.GetValue(LOGIN).ToString();
            tranKey = data.GetValue(TRANKEY).ToString();

            if (data.ContainsKey(AUTH))
            {
                if (!data.GetValue(AUTH).ToObject <JObject>().ContainsKey(SEED) ||
                    !data.GetValue(AUTH).ToObject <JObject>().ContainsKey(NONCE))
                {
                    throw new PlacetoPayException("Bad definition for the override");
                }

                auth      = new AuthenticationSecurity(data.GetValue(AUTH).ToString());
                overrided = true;
            }

            if (data.ContainsKey(AUTH_TYPE))
            {
                type = data.GetValue(AUTH_TYPE).ToString();
            }

            if (data.ContainsKey(AUTH_ADDITIONAL))
            {
                additional = data.GetValue(AUTH_ADDITIONAL).ToObject <JObject>();
            }

            if (data.ContainsKey(ALGORITHM))
            {
                algorithm = data.GetValue(ALGORITHM).ToString();
            }

            Generate();
        }
        /// <summary>
        /// Authentication constructor.
        /// </summary>
        /// <param name="login">string</param>
        /// <param name="tranKey">string</param>
        /// <param name="auth">AuthenticationSecurity</param>
        /// <param name="additional">JObject</param>
        public Authentication(string login, string tranKey, AuthenticationSecurity auth, JObject additional)
        {
            if (login == null || tranKey == null)
            {
                throw new PlacetoPayException("No login or tranKey provided on authentication");
            }
            this.login   = login;
            this.tranKey = tranKey;

            if (auth != null)
            {
                if (auth.Seed == null || auth.Nonce == null)
                {
                    throw new PlacetoPayException("Bad definition for the override");
                }

                this.auth = auth;
                overrided = true;
            }

            this.additional = additional;
            Generate();
        }
 /// <summary>
 /// Authentication constructor.
 /// </summary>
 /// <param name="login">string</param>
 /// <param name="trankey">string</param>
 /// <param name="auth">AuthenticationSecurity</param>
 public Authentication(string login, string trankey, AuthenticationSecurity auth) : this(login, trankey, auth, null)
 {
 }