private static StripeException BuildStripeException(StripeResponse response, HttpStatusCode statusCode, string requestUri, string responseContent)
        {
            var stripeError = requestUri.Contains("oauth")
                ? Mapper <StripeError> .MapFromJson(responseContent, null, response)
                : Mapper <StripeError> .MapFromJson(responseContent, "error", response);

            return(new StripeException(statusCode, stripeError, stripeError.Message));
        }
        private static StripeResponse BuildResponseData(HttpResponseMessage response, string responseText)
        {
            var result = new StripeResponse
            {
                RequestId    = response.Headers.Contains("Request-Id") ? response.Headers.GetValues("Request-Id").First() : "n/a",
                RequestDate  = Convert.ToDateTime(response.Headers.GetValues("Date").First(), CultureInfo.InvariantCulture),
                ResponseJson = responseText
            };

            return(result);
        }
Exemplo n.º 3
0
        // the ResponseJson on a list method is the entire list (as json) returned from stripe.
        // the ObjectJson is so we can store only the json for a single object in the list on that entity for
        // logging and/or debugging
        public static T MapFromJson(string json, string parentToken = null, StripeResponse stripeResponse = null)
        {
            var jsonToParse = string.IsNullOrEmpty(parentToken) ? json : JObject.Parse(json).SelectToken(parentToken).ToString();

            var result = JsonConvert.DeserializeObject <T>(jsonToParse);

            applyStripeResponse(json, stripeResponse, result);

            // if necessary, we might need to apply the stripe response to nested properties for StripeList<T>

            return(result);
        }
Exemplo n.º 4
0
        private static void applyStripeResponse(string json, StripeResponse stripeResponse, object obj)
        {
            if (stripeResponse == null)
            {
                return;
            }

            foreach (var property in obj.GetType().GetRuntimeProperties())
            {
                if (property.Name == nameof(StripeResponse))
                {
                    property.SetValue(obj, stripeResponse);
                }
            }

            stripeResponse.ObjectJson = json;
        }
Exemplo n.º 5
0
 public static T MapFromJson(StripeResponse stripeResponse, string parentToken = null)
 {
     return(MapFromJson(stripeResponse.ResponseJson, parentToken, stripeResponse));
 }
Exemplo n.º 6
0
 public static List <T> MapCollectionFromJson(StripeResponse stripeResponse, string token = "data")
 {
     return(MapCollectionFromJson(stripeResponse.ResponseJson, token, stripeResponse));
 }
Exemplo n.º 7
0
        public static List <T> MapCollectionFromJson(string json, string token = "data", StripeResponse stripeResponse = null)
        {
            var jObject = JObject.Parse(json);

            var allTokens = jObject.SelectToken(token);

            return(allTokens.Select(tkn => MapFromJson(tkn.ToString(), null, stripeResponse)).ToList());
        }