/// <summary> /// Request a direct payment session /// </summary> /// <param name="credentials">PagSeguro credentials</param> /// <returns><c cref="T:Uol.PagSeguro.CancelRequestResponse">Result</c></returns> public static Session CreateSession(Credentials credentials) { PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "SessionService.Register() - begin")); try { using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpPostConnection( PagSeguroConfiguration.SessionUri.AbsoluteUri, BuildSessionURL(credentials))) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { Session result = new Session(); SessionSerializer.Read(reader, result); PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "SessionService.Register({0}) - end", result.ToString())); return result; } } } catch (WebException exception) { PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response); PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "SessionService.Register() - error {0}", pse)); throw pse; } }
/// <summary> /// Read a direct payment session request result /// </summary> /// <param name="reader"></param> /// <param name="result"></param> public static void Read(XmlReader reader, Session session) { if (reader.IsEmptyElement) { XMLParserUtils.SkipNode(reader); return; } while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Text: session.id = reader.Value; break; } } }