/// <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 (var response = HttpUrlConnectionUtil.GetHttpGetConnection(BuildAuthorizationNotificationUrl(credentials, notificationCode))) { using (var reader = XmlReader.Create(response.GetResponseStream())) { var 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) { var pse = HttpUrlConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response); PagSeguroTrace.Error( string.Format(CultureInfo.InvariantCulture, "NotificationService.CheckAuthorization(notificationCode={0}) - error {1}", notificationCode, 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 (var response = HttpURLConnectionUtil.GetHttpGetConnection(BuildAuthorizationNotificationUrl(credentials, notificationCode))) { using (XmlReader reader = XmlReader.Create(response.Content.ReadAsStreamAsync().Result)) { 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 (System.Exception exception) { PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(exception); PagSeguroTrace.Error( String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckAuthorization(notificationCode={0}) - error {1}", notificationCode, pse)); throw pse; } }
/// <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; } }
static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); String nofiticationCode = "B071CC714E044E04389CC4606FBEFAA3A1BD"; try { ApplicationCredentials credentials = PagSeguroConfiguration.GetApplicationCredentials(isSandbox); // TODO: Substitute the code below with a notification code for your authorization. // You receive this notification code through a post on the URL that you specify AuthorizationSummary authorization = NotificationService.CheckAuthorization(credentials, nofiticationCode); Console.WriteLine(authorization); Console.ReadKey(); } catch (PagSeguroServiceException exception) { Console.WriteLine(exception.Message + "\n"); foreach (ServiceError element in exception.Errors) { Console.WriteLine(element + "\n"); } Console.ReadKey(); } }
static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); // TODO: Substitute the code below with a valid preApproval code for your transaction String authorizationCode = "FD455B5830A54DD58669D361932870E4"; try { ApplicationCredentials credentials = PagSeguroConfiguration.ApplicationCredentials(isSandbox); AuthorizationSummary result = AuthorizationSearchService.SearchByCode(credentials, authorizationCode); Console.WriteLine(result); Console.ReadKey(); } catch (WebException exception) { Console.WriteLine(exception.Message + "\n"); Console.ReadKey(); } catch (PagSeguroServiceException exception) { Console.WriteLine(exception.Message + "\n"); foreach (ServiceError element in exception.Errors) { Console.WriteLine(element + "\n"); } Console.ReadKey(); } }
static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); // TODO: Substitute the code below with a valid preApproval code for your transaction String authorizationCode = "(ADD-TOKEN-HERE)"; try { ApplicationCredentials credentials = PagSeguroConfiguration.GetApplicationCredentials(isSandbox); AuthorizationSummary result = AuthorizationSearchService.SearchByCode(credentials, authorizationCode); } catch (WebException exception) { } catch (PagSeguroServiceException exception) { foreach (ServiceError element in exception.Errors) { } } }
/// <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); throw new InvalidOperationException("Unexpected value = " + reader.Name); } } 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 { 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); throw new InvalidOperationException("Unexpected value"); } } else { XMLParserUtils.SkipNode(reader); } } }