コード例 #1
0
        /// <summary>
        /// Returns a transaction from a notification code
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="notificationCode">Transaction notification code</param>
        /// <returns><c cref="T:Uol.PagSeguro.Transaction">Transaction</c></returns>
        public static Transaction CheckTransaction(Credentials credentials, string notificationCode)
        {
            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckTransaction(notificationCode={0}) - begin", notificationCode));

            try
            {
                using (var response = HttpURLConnectionUtil.GetHttpGetConnection(BuildTransactionNotificationUrl(credentials, notificationCode)))
                {
                    using (XmlReader reader = XmlReader.Create(response.Content.ReadAsStreamAsync().Result))
                    {
                        Transaction transaction = new Transaction();
                        TransactionSerializer.Read(reader, transaction);

                        PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckTransaction(notificationCode={0}) - end {1}", notificationCode, transaction));
                        return(transaction);
                    }
                }
            }
            catch (System.Exception exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(exception);
                PagSeguroTrace.Error(
                    String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckTransaction(notificationCode={0}) - error {1}", notificationCode, pse));
                throw pse;
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns a transaction from a notification code
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="notificationCode">Transaction notification code</param>
        /// <returns><c cref="T:Uol.PagSeguro.Transaction">Transaction</c></returns>
        public static Transaction CheckTransaction(Credentials credentials, string notificationCode, bool preApproval)
        {
            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckTransaction(notificationCode={0}) - begin", notificationCode));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildTransactionNotificationUrl(credentials, notificationCode, preApproval)))
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        Transaction transaction = new Transaction();
                        TransactionSerializer.Read(reader, transaction, preApproval);

                        PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckTransaction(notificationCode={0}) - end {1}", notificationCode, transaction));
                        return(transaction);
                    }
                }
            }
            catch (WebException exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(
                    String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckTransaction(notificationCode={0}) - error {1}", notificationCode, pse));
                throw pse;
            }
        }
コード例 #3
0
 /// <summary>
 /// Create a new transaction checkout
 /// </summary>
 /// <param name="credentials">PagSeguro credentials</param>
 /// <param name="checkout"></param>
 /// <returns cref="T:Uol.PagSeguro.Transaction"><c>Transaction</c></returns>
 public static Transaction CreateCheckout(Credentials credentials, Checkout checkout)
 {
     PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionService.Register() - begin"));
     try
     {
         using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpPostConnection(
                    PagSeguroConfiguration.TransactionsUri.AbsoluteUri,
                    BuildTransactionUrl(credentials, checkout),
                    credentials.IsSandbox()
                    )
                )
         {
             using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
             {
                 Transaction transaction = new Transaction();
                 TransactionSerializer.Read(reader, transaction);
                 PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionService.Register() - end {0}", transaction));
                 return(transaction);
             }
         }
     }
     catch (WebException exception)
     {
         PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
         PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "TransactionService.Register() - error {0}", pse));
         throw pse;
     }
 }
コード例 #4
0
        /// <summary>
        /// Returns a transaction from a notification code
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="notificationCode">Transaction notification code</param>
        /// <returns><c cref="T:Uol.PagSeguro.Transaction">Transaction</c></returns>
        public static Transaction CheckTransaction(Credentials credentials, string notificationCode)
        {
            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }
            if (String.IsNullOrEmpty(notificationCode))
            {
                throw new ArgumentNullException("notificationCode");
            }

            UriBuilder    uriBuilder  = new UriBuilder(PagSeguroConfiguration.NotificationUri);
            StringBuilder pathBuilder = new StringBuilder(uriBuilder.Path);

            pathBuilder.Append('/');
            pathBuilder.Append(WebUtility.UrlEncode(notificationCode));
            pathBuilder.Append('/');
            uriBuilder.Path  = pathBuilder.ToString();
            uriBuilder.Query = ServiceHelper.EncodeCredentialsAsQueryString(credentials);

            WebRequest request = WebRequest.Create(uriBuilder.Uri);

            request.Method  = ServiceHelper.GetMethod;
            request.Timeout = PagSeguroConfiguration.RequestTimeout;

            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckTransaction(notificationCode={0}) - begin", notificationCode));

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        Transaction transaction = new Transaction();
                        TransactionSerializer.Read(reader, transaction);

                        PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckTransaction(notificationCode={0}) - end {1}", notificationCode, transaction));
                        return(transaction);
                    }
                }
            }
            catch (WebException exception)
            {
                PagSeguroServiceException pse = ServiceHelper.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(
                    String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckTransaction(notificationCode={0}) - error {1}", notificationCode, pse));
                throw pse;
            }
        }
コード例 #5
0
        /// <summary>
        /// Finds a transaction with a matching transaction code
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="transactionCode">Transaction code</param>
        /// <returns cref="T:Uol.PagSeguro.Transaction"><c>Transaction</c></returns>
        public static Transaction SearchByCode(Credentials credentials, string transactionCode)
        {
            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByCode(transactionCode={0}) - begin", transactionCode));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByCode(credentials, transactionCode)))
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        Transaction transaction = new Transaction();
                        TransactionSerializer.Read(reader, transaction);
                        PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByCode(transactionCode={0}) - end {1}", transactionCode, transaction));
                        return(transaction);
                    }
                }
            }
            catch (WebException exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByCode(transactionCode={0}) - error {1}", transactionCode, pse));
                throw pse;
            }
        }