/// <summary>
        /// Finds a pre-approval with a matching notification code
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="notificationCode">Notification code</param>
        /// <returns cref="T:Uol.PagSeguro.Transaction"><c>Transaction</c></returns>
        public static PreApprovalTransaction SearchByNofication(Credentials credentials, string notificationCode)
        {
            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByNotification(notificationCode={0}) - begin", notificationCode));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByNotification(credentials, notificationCode)))
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        PreApprovalTransaction preApproval = new PreApprovalTransaction();
                        PreApprovalTransactionSerializer.Read(reader, preApproval);
                        PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByNotification(notificationCode={0}) - end {1}", notificationCode, preApproval));
                        return(preApproval);
                    }
                }
            }
            catch (WebException exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByNotification(notificationCode={0}) - error {1}", notificationCode, pse));
                throw pse;
            }
        }
示例#2
0
        /// <summary>
        /// Finds a pre-approval with a matching pre-approval code
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="preApprovalCode">Pre-Approval code</param>
        /// <returns cref="T:Uol.PagSeguro.Transaction"><c>Transaction</c></returns>
        public static PreApprovalTransaction SearchByCode(Credentials credentials, string preApprovalCode)
        {
            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByCode(preApprovalCode={0}) - begin", preApprovalCode));

            try
            {
                using (var response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByCode(credentials, preApprovalCode)))
                {
                    using (XmlReader reader = XmlReader.Create(response.Content.ReadAsStreamAsync().Result))
                    {
                        PreApprovalTransaction preApproval = new PreApprovalTransaction();
                        PreApprovalTransactionSerializer.Read(reader, preApproval);
                        PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByCode(preApprovalCode={0}) - end {1}", preApprovalCode, preApproval));
                        return(preApproval);
                    }
                }
            }
            catch (System.Exception exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(exception);
                PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByCode(preApprovalCode={0}) - error {1}", preApprovalCode, pse));
                throw pse;
            }
        }