コード例 #1
0
ファイル: Invoice.cs プロジェクト: smss123/moyasar-dotnet-1
        public InvoiceListResult List(int?page = null)
        {
            string finalUrl = page == null ? this.MakeInvoiceUrl : this.MakeInvoiceUrl + "?page=" + page.ToString();

            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(finalUrl);

            httpWebRequest.ContentType = "application/json; charset=utf-8";
            httpWebRequest.Method      = "GET";
            httpWebRequest.Credentials = new NetworkCredential(ApiKey, ApiKey);

            try
            {
                HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    string            result = streamReader.ReadToEnd();
                    InvoiceListResult j      = this.js.Deserialize <InvoiceListResult>(result); // JObject.Parse(result);
                    InvoiceListResult list   = new InvoiceListResult
                    {
                        Invoices = new List <InvoiceResult>(),
                        Meta     = new MetaResult()
                    };

                    List <InvoiceResult> inv = j.Invoices; //j["invoices"].Children();
                    foreach (InvoiceResult i in inv)
                    {
                        InvoiceResult invoiceResult = new InvoiceResult
                        {
                            Id           = i.Id,           //(string)i["id"],
                            Status       = i.Status,       //(string)i["status"],
                            Amount       = i.Amount,       //(string)i["amount"],
                            Currency     = i.Currency,     //(string)i["currency"],
                            Description  = i.Description,  // //(string)i["description"],
                            CallbackUrl  = i.CallbackUrl,  // (string)i["callback_url"],
                            AmountFormat = i.AmountFormat, // (string)i["amount_format"],
                            Url          = i.Url,          //(string)i["url"],
                            CreatedAt    = i.CreatedAt,    //(string)i["created_at"],
                            UpdatedAt    = i.UpdatedAt     //(string)i["updated_at"]
                        };
                        list.Invoices.Add(invoiceResult);
                    }

                    list.Meta.CurrentPage = j.Meta.CurrentPage; //(string)j["meta"]["current_page"];
                    list.Meta.NextPage    = j.Meta.NextPage;    // (string)j["meta"]["next_page"];
                    list.Meta.PrevPage    = j.Meta.PrevPage;    //(string)j["meta"]["prev_page"];
                    list.Meta.TotalCount  = j.Meta.TotalCount;  //(string)j["meta"]["total_pages"];
                    list.Meta.TotalPages  = j.Meta.TotalPages;  //(string)j["meta"]["total_count"];

                    return(list);
                }
            }
            catch (WebException webEx)
            {
                throw this.HandleRequestErrors(webEx);
            }
        }
コード例 #2
0
ファイル: Invoice.cs プロジェクト: smss123/moyasar-dotnet-1
        public IEnumerable <InvoiceListResult> ListAll()
        {
            InvoiceListResult allList = new InvoiceListResult();
            int?nextPage = null;

            do
            {
                allList  = this.List(nextPage);
                nextPage = int.Parse(allList.Meta.CurrentPage) + 1;
                yield return(allList);
            } while (allList.Meta.NextPage != null);
        }