示例#1
0
        public bool Parse(ref string requestString, JsonPropertyAttribute attribute, PropertyInfo property, object propertyValue, object propertyParent)
        {
            if (!attribute.PropertyName.Contains("include_total_count"))
            {
                return(false);
            }

            var doInclude = (bool)propertyValue;

            if (doInclude)
            {
                RequestStringBuilder.ApplyParameterToRequestString(ref requestString, $"include[]", "total_count");
            }

            return(true);
        }
        public bool Parse(ref string requestString, JsonPropertyAttribute attribute, PropertyInfo property, object propertyValue, object propertyParent)
        {
            if (attribute.PropertyName != "legal_entity[additional_owners]")
            {
                return(false);
            }

            var owners = ((List <StripeAccountAdditionalOwner>)property.GetValue(propertyParent, null));

            if (owners.Count == 0)
            {
                RequestStringBuilder.ApplyParameterToRequestString(ref requestString, attribute.PropertyName, "");
                return(true);
            }

            var ownerIndex = 0;

            foreach (var owner in owners)
            {
                var properties = owner.GetType().GetRuntimeProperties();

                foreach (var prop in properties)
                {
                    var value = prop.GetValue(owner, null);
                    if (value == null)
                    {
                        continue;
                    }

                    // it must have a json attribute matching stripe's key, and only one
                    var attr = prop.GetCustomAttributes <JsonPropertyAttribute>().SingleOrDefault();
                    if (attr == null)
                    {
                        continue;
                    }

                    RequestStringBuilder.ApplyParameterToRequestString(ref requestString,
                                                                       $"{attribute.PropertyName}[{ownerIndex}]{attr.PropertyName}",
                                                                       value.ToString());
                }

                ownerIndex++;
            }

            return(true);
        }
        public bool Parse(ref string requestString, JsonPropertyAttribute attribute, PropertyInfo property, object propertyValue, object propertyParent)
        {
            if (!attribute.PropertyName.Contains("array:"))
            {
                return(false);
            }

            var values = ((IEnumerable)propertyValue).Cast <object>().Select(x => x.ToString()).ToArray();

            var key = attribute.PropertyName.Replace("array:", "") + "[]";

            foreach (var value in values)
            {
                RequestStringBuilder.ApplyParameterToRequestString(ref requestString, key, value);
            }

            return(true);
        }
示例#4
0
        public bool Parse(ref string requestString, JsonPropertyAttribute attribute, PropertyInfo property, object propertyValue, object propertyParent)
        {
            if (!attribute.PropertyName.Contains("metadata") && !attribute.PropertyName.Contains("fraud_details"))
            {
                return(false);
            }

            var dictionary = (Dictionary <string, string>)propertyValue;

            if (dictionary == null)
            {
                return(true);
            }

            foreach (var key in dictionary.Keys)
            {
                RequestStringBuilder.ApplyParameterToRequestString(ref requestString, $"{attribute.PropertyName}[{key}]", dictionary[key]);
            }

            return(true);
        }
示例#5
0
        public bool Parse(ref string requestString, JsonPropertyAttribute attribute, PropertyInfo property, object propertyValue, object propertyParent)
        {
            if (attribute.PropertyName != "subscription_items_array_updated")
            {
                return(false);
            }

            var items = ((List <Services.StripeSubscriptionItemUpdateOption>)property.GetValue(propertyParent, null));

            var itemIndex = 0;

            foreach (var item in items)
            {
                var properties = item.GetType().GetRuntimeProperties();

                foreach (var prop in properties)
                {
                    var value = prop.GetValue(item, null);
                    if (value == null)
                    {
                        continue;
                    }

                    // it must have a json attribute matching stripe's key, and only one
                    var attr = prop.GetCustomAttributes <JsonPropertyAttribute>().SingleOrDefault();
                    if (attr == null)
                    {
                        continue;
                    }

                    RequestStringBuilder.ApplyParameterToRequestString(ref requestString,
                                                                       $"items[{itemIndex}][{attr.PropertyName}]", value.ToString());
                }

                itemIndex++;
            }

            return(true);
        }
示例#6
0
        public bool Parse(ref string requestString, JsonPropertyAttribute attribute, PropertyInfo property, object propertyValue, object propertyParent)
        {
            if (property.PropertyType != typeof(StripeDateFilter))
            {
                return(false);
            }

            var filter = (StripeDateFilter)propertyValue;

            if (filter.EqualTo.HasValue)
            {
                RequestStringBuilder.ApplyParameterToRequestString(ref requestString, attribute.PropertyName, filter.EqualTo.Value.ToUniversalTime().ConvertDateTimeToEpoch().ToString());
            }

            if (filter.LessThan.HasValue)
            {
                RequestStringBuilder.ApplyParameterToRequestString(ref requestString, attribute.PropertyName + "[lt]", filter.LessThan.Value.ToUniversalTime().ConvertDateTimeToEpoch().ToString());
            }

            if (filter.LessThanOrEqual.HasValue)
            {
                RequestStringBuilder.ApplyParameterToRequestString(ref requestString, attribute.PropertyName + "[lte]", filter.LessThanOrEqual.Value.ToUniversalTime().ConvertDateTimeToEpoch().ToString());
            }

            if (filter.GreaterThan.HasValue)
            {
                RequestStringBuilder.ApplyParameterToRequestString(ref requestString, attribute.PropertyName + "[gt]", filter.GreaterThan.Value.ToUniversalTime().ConvertDateTimeToEpoch().ToString());
            }

            if (filter.GreaterThanOrEqual.HasValue)
            {
                RequestStringBuilder.ApplyParameterToRequestString(ref requestString, attribute.PropertyName + "[gte]", filter.GreaterThanOrEqual.Value.ToUniversalTime().ConvertDateTimeToEpoch().ToString());
            }

            return(true);
        }