/// <summary> /// Finds a authorization with a matching authorization code /// </summary> /// <param name="credentials">PagSeguro credentials. Required.</param> /// <param name="code">Authorization code. Required</param> /// <returns>Authorization Summary</returns> public static AuthorizationSummary SearchByCode(Credentials credentials, String code) { PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "AuthorizationSearchService.SearchByCode({0}) - begin", code)); try { using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByCode(credentials, code))) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { AuthorizationSummary authorization = new AuthorizationSummary(); AuthorizationSummarySerializer.Read(reader, authorization); return authorization; } } } catch (WebException exception) { throw exception; } catch (PagSeguroServiceException pse) { throw pse; } }
/// <summary> /// Returns a authorization from a notification code /// </summary> /// <param name="credentials">PagSeguro credentials</param> /// <param name="notificationCode">Authorization notification code</param> /// <returns><c cref="T:Uol.PagSeguro.Transaction">Transaction</c></returns> public static AuthorizationSummary CheckAuthorization(Credentials credentials, string notificationCode) { PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckAuthorization(notificationCode={0}) - begin", notificationCode)); try { using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildAuthorizationNotificationUrl(credentials, notificationCode))) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { AuthorizationSummary authorization = new AuthorizationSummary(); AuthorizationSummarySerializer.Read(reader, authorization); PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckAuthorization(notificationCode={0}) - end {1}", notificationCode, authorization)); return authorization; } } } catch (WebException exception) { PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response); PagSeguroTrace.Error( String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckAuthorization(notificationCode={0}) - error {1}", notificationCode, pse)); throw pse; } }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <param name="result">PagSeguro AuthorizationSummary</param> internal static void Read(XmlReader reader, AuthorizationSummary result) { if (reader.IsEmptyElement) { XMLParserUtils.SkipNode(reader); return; } reader.ReadStartElement(SerializerHelper.Authorization); reader.MoveToContent(); while (!reader.EOF) { if (XMLParserUtils.IsEndElement(reader, SerializerHelper.Authorization)) { XMLParserUtils.SkipNode(reader); break; } if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case SerializerHelper.Code: result.Code = reader.ReadElementContentAsString(); break; case SerializerHelper.CreationDate: result.CreationDate = reader.ReadElementContentAsDateTime(); break; case SerializerHelper.Reference: result.Reference = reader.ReadElementContentAsString(); break; case SerializerHelper.Account: AuthorizationAccountSerializer.Read(reader, result); break; case SerializerHelper.Permissions: AuthorizationPermissionListSerializer.Read(reader, result.Permissions); break; default: XMLParserUtils.SkipElement(reader); break; } } else { XMLParserUtils.SkipNode(reader); } } }
/// <summary> /// /// </summary> /// <param name="reader">PagSeguro AuthorizationSummary</param> /// <param name="result"></param> internal static void Read(XmlReader reader, AuthorizationSummary result) { if (reader.IsEmptyElement) { XMLParserUtils.SkipNode(reader); return; } reader.ReadStartElement(SerializerHelper.Account); reader.MoveToContent(); while (!reader.EOF) { if (XMLParserUtils.IsEndElement(reader, SerializerHelper.Account)) { XMLParserUtils.SkipNode(reader); break; } if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case SerializerHelper.PublicKey: AuthorizationAccount authorizationAccount = new AuthorizationAccount(); authorizationAccount.PublicKey = reader.ReadElementContentAsString(); result.Account = authorizationAccount; break; default: XMLParserUtils.SkipElement(reader); break; } } else { XMLParserUtils.SkipNode(reader); } } }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <param name="authorizations">PagSeguro AuthorizationSummary List</param> internal static void Read(XmlReader reader, IList<AuthorizationSummary> authorizations) { authorizations.Clear(); if (reader.IsEmptyElement) { XMLParserUtils.SkipNode(reader); } reader.ReadStartElement(SerializerHelper.Authorizations); reader.MoveToContent(); while (!reader.EOF) { if (XMLParserUtils.IsEndElement(reader, SerializerHelper.Authorizations)) { XMLParserUtils.SkipNode(reader); break; } if (reader.NodeType == XmlNodeType.Element) { AuthorizationSummary authorization = new AuthorizationSummary(); switch (reader.Name) { case SerializerHelper.Authorization: AuthorizationSummarySerializer.Read(reader, authorization); authorizations.Add(authorization); break; default: XMLParserUtils.SkipElement(reader); break; } } else { XMLParserUtils.SkipNode(reader); } } }