Exemple #1
0
        public virtual async Task <ApplicationFee> Refund(string applicationFeeId, int?refundAmount = null)
        {
            var url = string.Format("{0}/{1}/refund", Urls.ApplicationFees, applicationFeeId);

            url = this.ApplyAllParameters(null, url, false);

            if (refundAmount.HasValue)
            {
                url = ParameterBuilder.ApplyParameterToUrl(url, "amount", refundAmount.Value.ToString(CultureInfo.InvariantCulture));
            }

            var response = await Requestor.Post(url);

            return(Mapper <ApplicationFee> .MapFromJson(response));
        }
        public virtual SearchResults <Bank> ListBanks(int page = 1, int page_size = 20, string reference = null)
        {
            var url = Urls.Banks;

            url = ParameterBuilder.ApplyParameterToUrl(url, "page", page.ToString());
            url = ParameterBuilder.ApplyParameterToUrl(url, "page_size", page_size.ToString());
            if (reference != null)
            {
                url = ParameterBuilder.ApplyParameterToUrl(url, "reference", reference);
            }

            var response = Requestor.GetString(url, SecretKey);

            return(Mapper <Bank> .MapCollectionFromJson(response));
        }
        public virtual StripeDispute Update(string chargeId, string evidence = null)
        {
            var url = string.Format("{0}/dispute", chargeId);

            url = this.ApplyAllParameters(null, url, false);

            if (!string.IsNullOrEmpty(evidence))
            {
                url = ParameterBuilder.ApplyParameterToUrl(url, "evidence", evidence);
            }

            var response = Requestor.PostString(url, ApiKey);

            return(Mapper <StripeDispute> .MapFromJson(response));
        }
        public virtual async Task <Invoice> Upcoming(string customerId, string subscriptionId = null)
        {
            var url = string.Format("{0}/{1}", Urls.Invoices, "upcoming");

            url = ParameterBuilder.ApplyParameterToUrl(url, "customer", customerId);

            if (!String.IsNullOrEmpty(subscriptionId))
            {
                url = ParameterBuilder.ApplyParameterToUrl(url, "subscription", subscriptionId);
            }

            var response = await Requestor.Get(url);

            return(Mapper <Invoice> .MapFromJson(response));
        }
        public virtual SearchResults <Transaction> Holds(
            int page         = 1,
            int pageSize     = 20,
            string accountId = null)
        {
            var url = Urls.Holds;

            url = ParameterBuilder.ApplyParameterToUrl(url, "page", page.ToString());
            url = ParameterBuilder.ApplyParameterToUrl(url, "page_size", pageSize.ToString());

            if (!string.IsNullOrEmpty(accountId))
            {
                url = ParameterBuilder.ApplyParameterToUrl(url, "account_id", accountId);
            }

            var response = Requestor.GetString(url, SecretKey);

            return(TransactionMapper.MapCollectionFromJson(response));
        }
        private string AddBaseCurrencyParameter(string url, string baseCurrency)
        {
            if (_debug)
            {
                Console.WriteLine("BaseCurrency: " + baseCurrency);
            }

            //Use default base currency (EUR)
            if (baseCurrency.Equals(Currency.EUR))
            {
                return(url);
            }

            //Check if all symbols are valid currency
            if (!ValidateCurrency(baseCurrency))
            {
                throw new ExchangeRatesException($"The currency {baseCurrency} is unsupported, please check GetAvaibleCurrency() Method");
            }
            return(ParameterBuilder.ApplyParameterToUrl(url, "base", baseCurrency));
        }
        public virtual async Task <Charge> Capture(string chargeId, int?captureAmount = null, int?applicationFee = null)
        {
            var url = string.Format("{0}/{1}/capture", Urls.Charges, chargeId);

            url = this.ApplyAllParameters(null, url, false);

            if (captureAmount.HasValue)
            {
                url = ParameterBuilder.ApplyParameterToUrl(url, "amount", captureAmount.Value.ToString(CultureInfo.InvariantCulture));
            }

            if (applicationFee.HasValue)
            {
                url = ParameterBuilder.ApplyParameterToUrl(url, "application_fee", applicationFee.Value.ToString(CultureInfo.InvariantCulture));
            }

            var response = await Requestor.Post(url);

            return(Mapper <Charge> .MapFromJson(response));
        }
Exemple #8
0
        public List <Transaction> Detail(string payout_id, PayoutReportDetailSearchParams searchParams)
        {
            string url = "/reports/payout/" + payout_id + "/detail";

            if (searchParams != null)
            {
                if (searchParams.Offset < 0)
                {
                    throw new ArgumentOutOfRangeException("offset");
                }
                if (searchParams.Limit < 1 || searchParams.Limit > 100)
                {
                    throw new ArgumentOutOfRangeException("limit");
                }
                url = ParameterBuilder.ApplyParameterToUrl(url, "limit", searchParams.Limit.ToString());
                url = ParameterBuilder.ApplyParameterToUrl(url, "offset", searchParams.Offset.ToString());
                if (searchParams.DetailType != null)
                {
                    url = ParameterBuilder.ApplyParameterToUrl(url, "detail_type", searchParams.DetailType);
                }
            }
            return(base.List <Transaction>(url));
        }
Exemple #9
0
        public string ApplyAllParameters(object obj, string url, bool isListMethod)
        {
            var newUrl = url;

            if (obj != null)
            {
                foreach (var property in obj.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
                {
                    var value = property.GetValue(obj, null);
                    if (value == null)
                    {
                        continue;
                    }

                    foreach (var attribute in property.GetCustomAttributes(typeof(JsonPropertyAttribute), false).Cast <JsonPropertyAttribute>())
                    {
                        if (String.Compare(attribute.PropertyName, "metadata", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            var metadata = (Dictionary <string, string>)value;

                            newUrl = metadata.Keys.Aggregate(newUrl, (current, key) =>
                                                             ParameterBuilder.ApplyParameterToUrl(current, string.Format("metadata[{0}]", key), metadata[key]));
                        }
                        else if (property.PropertyType == typeof(DateFilter))
                        {
                            var filter = (DateFilter)value;

                            if (filter.EqualTo.HasValue)
                            {
                                newUrl = ParameterBuilder.ApplyParameterToUrl(newUrl, attribute.PropertyName,
                                                                              filter.EqualTo.Value.ConvertDateTimeToEpoch().ToString(CultureInfo.InvariantCulture));
                            }
                            else if (filter.LessThan.HasValue)
                            {
                                newUrl = ParameterBuilder.ApplyParameterToUrl(newUrl, attribute.PropertyName + "[lt]",
                                                                              filter.LessThan.Value.ConvertDateTimeToEpoch().ToString(CultureInfo.InvariantCulture));
                            }

                            if (filter.LessThanOrEqual.HasValue)
                            {
                                newUrl = ParameterBuilder.ApplyParameterToUrl(newUrl, attribute.PropertyName + "[lte]",
                                                                              filter.LessThanOrEqual.Value.ConvertDateTimeToEpoch().ToString(CultureInfo.InvariantCulture));
                            }

                            if (filter.GreaterThan.HasValue)
                            {
                                newUrl = ParameterBuilder.ApplyParameterToUrl(newUrl, attribute.PropertyName + "[gt]",
                                                                              filter.GreaterThan.Value.ConvertDateTimeToEpoch().ToString(CultureInfo.InvariantCulture));
                            }

                            if (filter.GreaterThanOrEqual.HasValue)
                            {
                                newUrl = ParameterBuilder.ApplyParameterToUrl(newUrl, attribute.PropertyName + "[gte]",
                                                                              filter.GreaterThanOrEqual.Value.ConvertDateTimeToEpoch().ToString(CultureInfo.InvariantCulture));
                            }
                        }
                        else if (property.PropertyType == typeof(BankAccountOptions))
                        {
                            var bankAccountOptions = (BankAccountOptions)value;
                            newUrl = ParameterBuilder.ApplyNestedObjectProperties(newUrl, bankAccountOptions);
                        }
                        else if (property.PropertyType == typeof(CreditCardOptions))
                        {
                            var creditCardOptions = (CreditCardOptions)value;
                            newUrl = ParameterBuilder.ApplyNestedObjectProperties(newUrl, creditCardOptions);
                        }
                        else if (property.PropertyType == typeof(SourceOptions))
                        {
                            var creditCardOptions = (SourceOptions)value;
                            newUrl = ParameterBuilder.ApplyNestedObjectProperties(newUrl, creditCardOptions);
                        }
                        else
                        {
                            newUrl = ParameterBuilder.ApplyParameterToUrl(newUrl, attribute.PropertyName, value.ToString());
                        }
                    }
                }
            }

            var propertiesToExpand =
                this.GetType()
                .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                .Where(p => p.Name.StartsWith("Expand") && p.PropertyType == typeof(bool))
                .Where(p => (bool)p.GetValue(this, null))
                .Select(p => p.Name);

            foreach (var propertyName in propertiesToExpand)
            {
                var expandPropertyName = propertyName.Substring("Expand".Length);
                expandPropertyName = Regex.Replace(expandPropertyName, "([a-z])([A-Z])", "$1_$2").ToLower();

                if (isListMethod)
                {
                    expandPropertyName = "data." + expandPropertyName;
                }

                newUrl = ParameterBuilder.ApplyParameterToUrl(newUrl, "expand[]", expandPropertyName);
            }

            return(newUrl);
        }