public async Task <Payment> CreatePayment(Account account, PayBy payBy, DateTime date, IEnumerable <Service> services)
        {
            var retVal = new Payment();

            retVal.Account   = account;
            retVal.AccountId = account.Id;
            retVal.Enabled   = true;
            try
            {
                if (!await Login2Site())
                {
                    return(null);
                }
                using (HttpResponseMessage response = await client.GetAsync(string.Format(createPaymentUrl, account.InternalId, (int)payBy, date.AddMonths(-1).ToString("yyyyMM"))))
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var url = response.RequestMessage.RequestUri.ToString();
                        if (!url.Contains("/ru/service/publicutilities/orderedit"))
                        {
                            return(null);
                        }
                        retVal.ErcId = Convert.ToInt64(url.Split('/').Last());
                        var page = await response.Content.ReadAsStringAsync();

                        var doc = new HtmlDocument();
                        doc.LoadHtml(page);
                        var json = doc.DocumentNode.SelectSingleNode("//script[text()[contains(.,'\"bbl\":')]]").InnerText.Replace("jQuery.extend(Drupal.settings, ", "").Replace(");", "");
                        using (var reader = new JsonTextReader(new StringReader(json)))
                        {
                            while (reader.Read())
                            {
                                if (reader.Value != null && Convert.ToString(reader.Value) == "bbl")
                                {
                                    reader.Read();
                                    retVal.Bbl = Convert.ToString(reader.Value);
                                    break;
                                }
                            }
                        }
                        retVal.PaymentItems.AddRange(await GetPaymentItems(retVal.ErcId, services));
                        retVal.PaymentItems.ForEach(item => item.Enabled = true);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                throw ex;
            }
            return(retVal);
        }
Beispiel #2
0
        public List <PayBy> getPayBy()
        {
            DAAddReceipt   dm     = new DAAddReceipt();
            ListDictionary Params = new ListDictionary();
            DataSet        ds     = dm.getPayBay(Params);
            PayBy          b;
            List <PayBy>   l = new List <PayBy>();

            foreach (DataRow item in ds.Tables[0].Rows)
            {
                b       = new PayBy();
                b.Code  = BLCtrl.getInt(item, "Code", 0);
                b.payBy = BLCtrl.getString(item, "PayBy", "");
                l.Add(b);
            }
            return(l);
        }