Esempio n. 1
0
        /// <summary>
        /// Converts from json to a particular entity.
        /// </summary>
        /// <returns>Entity to which json is casted</returns>
        /// <param name="payabbhiResponse">Payabbhi response.</param>
        public static T ConvertFromJson(PayabbhiResponse payabbhiResponse)
        {
            var result = JsonConvert.DeserializeObject <T> (payabbhiResponse.ResponseJson);

            applyPayabbhiResponse(payabbhiResponse, result);
            return(result);
        }
Esempio n. 2
0
        static void applyPayabbhiResponse(PayabbhiResponse payabbhiResponse, object obj)
        {
            if (payabbhiResponse == null)
            {
                return;
            }

            PropertyInfo prop = obj.GetType().GetProperty("PayabbhiResponse", BindingFlags.Public | BindingFlags.Instance);

            if (prop != null && prop.CanWrite)
            {
                prop.SetValue(obj, payabbhiResponse, null);
            }
        }
Esempio n. 3
0
        void HandleErrors(HttpStatusCode httpStatusCode, string response)
        {
            PayabbhiResponse payabbhiResponse = new PayabbhiResponse();

            payabbhiResponse.ResponseJson = response;
            dynamic data    = null;
            string  field   = string.Empty;
            string  message = string.Empty;

            try {
                data    = JsonConvert.DeserializeObject(response);
                field   = data["error"]["field"];
                message = data["error"]["message"];
            } catch (Exception) {
                throw Error.ErrorFactory.Create(Constants.Messages.ApiError, null, payabbhiResponse, HttpStatusCode.InternalServerError);
            }

            throw Error.ErrorFactory.Create(message, field, payabbhiResponse, httpStatusCode);
        }
Esempio n. 4
0
        /// <summary>
        /// Make request to Payabbhi API service.
        /// </summary>
        /// <returns>Response from the API service</returns>
        /// <param name="relativeUrl">Relative URL.</param>
        /// <param name="method">Method.</param>
        /// <param name="options">Options.</param>
        public PayabbhiResponse Request(string relativeUrl, HttpMethod method, IDictionary <string, object> options)
        {
            string queryString = string.Empty;
            string postData    = string.Empty;

            if (method == HttpMethod.Get && options != null)
            {
                queryString = MakeQueryString(options);
                relativeUrl = relativeUrl + "?" + queryString;
            }
            else if (method == HttpMethod.Post || method == HttpMethod.Put || method == HttpMethod.Patch || method == HttpMethod.Delete)
            {
                postData = JsonConvert.SerializeObject(options);
            }
            string           responseText = MakeRequest(relativeUrl, method, postData);
            PayabbhiResponse response     = new PayabbhiResponse();

            response.ResponseJson = responseText;
            return(response);
        }