Exemplo n.º 1
0
        public ActionResult xposeSubscriber(string url, string xml, string method)
        {
            try
            {
                myReq = WebRequest.Create(url);
                mycache = new CredentialCache();
                myReq.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(credentials));
                myReq.ContentType = "Application/json;";
                if (method.ToLower() == "post")
                {
                    byte[] bytes;
                    myReq.ContentType = "text/xml; encoding='utf-8'";
                    bytes = System.Text.Encoding.ASCII.GetBytes(xml);
                    myReq.ContentLength = bytes.Length;
                    myReq.Method = method;
                    requestStream = myReq.GetRequestStream();
                    requestStream.Write(bytes, 0, bytes.Length);
                    requestStream.Close();
                }
                wr = myReq.GetResponse();
                receiveStream = wr.GetResponseStream();
                reader = new StreamReader(receiveStream, Encoding.UTF8);
                xmlDoc = new XmlDocument();
                xmlDoc.Load(wr.GetResponseStream());
                serializer = new XmlSerializer(typeof(subscriptionplans));
                rdr = new StringReader(xmlDoc.InnerXml);
                _subscriptionplans = (subscriptionplans)serializer.Deserialize(rdr);
                foreach (var item in _subscriptionplans.subscriptionplan)
                {
                    Plans plans = new Plans();
                    plans.Amount = item.amount.Value;
                    plans.Name = item.name;
                    plans.Type = item.plantype;
                    plans.Id = item.id.Value;
                    plans.ServiceLevel = item.featurelevel;
                    planlist.Add(plans);
                }
                string content = reader.ReadToEnd();

                return View("Plans", planlist);
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Exemplo n.º 2
0
        public IList<Plans> GetPlans()
        {
            try
            {
                string site = ConfigurationManager.AppSettings["apiUrl"].ToString();
                string url = string.Format("https://subs.pinpayments.com/api/v4/{0}/subscription_plans.xml", site);
                myReq = WebRequest.Create(url);
                mycache = new CredentialCache();
                myReq.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(credentials));
                myReq.ContentType = "Application/json;";
                myReq.Method = "Get";
                wr = myReq.GetResponse();
                receiveStream = wr.GetResponseStream();
                reader = new StreamReader(receiveStream, Encoding.UTF8);
                xmlDoc = new XmlDocument();
                xmlDoc.Load(wr.GetResponseStream());
                serializer = new XmlSerializer(typeof(subscriptionplans));
                rdr = new StringReader(xmlDoc.InnerXml);
                _subscriptionplans = new subscriptionplans();
                using (XmlReader reade = new XmlTextReader(rdr))
                {

                    var subscriptionplanssubscriptionplans = new XmlSerializer(typeof(subscriptionplans));
                    _subscriptionplans = subscriptionplanssubscriptionplans.Deserialize(reade) as subscriptionplans;
                    List<Plans> planlist = new List<Plans>();
                    foreach (var item in _subscriptionplans.subscriptionplan)
                    {
                        Plans plans = new Plans();
                        plans.Amount = item.amount.Value;
                        plans.Name = item.name;
                        plans.Type = item.plantype;
                        plans.Id = item.id.Value;
                        plans.ServiceLevel = item.featurelevel;
                        planlist.Add(plans);
                    }
                    return planlist;

                }
            }
            catch (Exception ex)
            {

                return null;
            }
        }