/// <summary>
        /// Finds a authorization with a matching date interval
        /// </summary>
        /// <param name="credentials">PagSeguro credentials. Required.</param>
        /// <param name="initialDate"></param>
        /// <param name="finalDate">End of date range. Use DateTime.MaxValue to search without an upper boundary.</param>
        /// <param name="pageNumber">Page number, starting with 1. If passed as 0, it will call the web service to get the default page, also page number 1.</param>
        /// <param name="resultsPerPage">Results per page, optional.</param>
        /// <returns></returns>
        public static AuthorizationSearchResult SearchByDate(Credentials credentials, DateTime initialDate, DateTime finalDate, int?pageNumber = null, int?resultsPerPage = null)
        {
            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "AuthorizationSearchService.SearchByDate(initialDate={0} - finalDate={1}) - begin", initialDate, finalDate));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByDate(credentials, initialDate, finalDate, pageNumber, resultsPerPage)))
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        AuthorizationSearchResult authorization = new AuthorizationSearchResult();
                        AuthorizationSearchResultSerializer.Read(reader, authorization);
                        return(authorization);
                    }
                }
            }
            catch (WebException exception)
            {
                throw exception;
            }
            catch (PagSeguroServiceException pse)
            {
                throw pse;
            }
        }
Пример #2
0
        /// <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>
        /// ChargePreApproval
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="payment">PreApproval payment request information</param>
        /// <returns>The Uri to where the user needs to be redirected to in order to complete the payment process</returns>
        public static string ChargePreApproval(Credentials credentials, PaymentRequest payment)
        {
            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.ChargePreApproval({0}) - begin", payment));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpPostConnection(
                           PagSeguroConfiguration.PreApprovalPaymentUri.AbsoluteUri, BuildChargeUrl(credentials, payment)))
                {
                    if (HttpStatusCode.OK.Equals(response.StatusCode))
                    {
                        using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                        {
                            PaymentRequestResponse chargeResponse = new PaymentRequestResponse(PagSeguroConfiguration.PreApprovalPaymentUri);
                            PaymentSerializer.Read(reader, chargeResponse);
                            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.ChargePreApproval({0}) - end {1}", payment, chargeResponse.PaymentRedirectUri));
                            return(chargeResponse.TransactionCode);
                        }
                    }
                    else
                    {
                        PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(response);
                        PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.ChargePreApproval({0}) - error {1}", payment, pse));
                        throw pse;
                    }
                }
            }
            catch (WebException exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.ChargePreApproval({0}) - error {1}", payment, pse));
                throw pse;
            }
        }
Пример #4
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;
     }
 }
Пример #5
0
        /// <summary>
        /// CreatePreApproval is the actual implementation of the Register method
        /// This separation serves as test hook to validate the Uri
        /// against the code returned by the service
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="preApproval">PreApproval request information</param>
        /// <returns>The Uri to where the user needs to be redirected to in order to complete the payment process</returns>
        public static Uri CreatePreApproval(Credentials credentials, PreApprovalRequest preApproval)
        {
            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalService.Register({0}) - begin", preApproval));

            try
            {
                using (var response = HttpURLConnectionUtil.GetHttpPostConnection(
                           PagSeguroConfiguration.PreApprovalUri.AbsoluteUri, BuildPreApprovalUrl(credentials, preApproval)))
                {
                    if (HttpStatusCode.OK.Equals(response.StatusCode))
                    {
                        using (XmlReader reader = XmlReader.Create(response.Content.ReadAsStreamAsync().Result))
                        {
                            PreApprovalRequestResponse preApprovalResponse = new PreApprovalRequestResponse(PagSeguroConfiguration.PreApprovalRedirectUri);
                            PreApprovalSerializer.Read(reader, preApprovalResponse);
                            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalService.Register({0}) - end {1}", preApproval, preApprovalResponse.PreApprovalRedirectUri));
                            return(preApprovalResponse.PreApprovalRedirectUri);
                        }
                    }
                    else
                    {
                        PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(new System.Exception(response.StatusCode.ToString()));
                        PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PreApprovalService.Register({0}) - error {1}", preApproval, pse));
                        throw pse;
                    }
                }
            }
            catch (System.Exception exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(exception);
                PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PreApprovalService.Register({0}) - error {1}", preApproval, pse));
                throw pse;
            }
        }
Пример #6
0
        /// <summary>
        /// CreatePreApproval is the actual implementation of the Register method
        /// This separation serves as test hook to validate the Uri
        /// against the code returned by the service
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="preApproval">PreApproval request information</param>
        /// <returns>The Uri to where the user needs to be redirected to in order to complete the payment process</returns>
        public static Uri CreatePreApproval(Credentials credentials, PreApprovalRequest preApproval)
        {
            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.Register({0}) - begin", preApproval));

            try
            {
                using (var response = HttpUrlConnectionUtil.GetHttpPostConnection(
                           PagSeguroUris.GetPreApprovalRequestUri(credentials).AbsoluteUri, BuildPreApprovalUrl(credentials, preApproval)))
                {
                    if (HttpStatusCode.OK.Equals(response.StatusCode))
                    {
                        using (var reader = XmlReader.Create(response.GetResponseStream()))
                        {
                            var preApprovalResponse = new PreApprovalRequestResponse(PagSeguroUris.GetPreApprovalRedirectUri(credentials));
                            PreApprovalSerializer.Read(reader, preApprovalResponse);
                            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.Register({0}) - end {1}", preApproval, preApprovalResponse.PreApprovalRedirectUri));
                            return(preApprovalResponse.PreApprovalRedirectUri);
                        }
                    }

                    var pse = HttpUrlConnectionUtil.CreatePagSeguroServiceException(response);
                    PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.Register({0}) - error {1}", preApproval, pse));
                    throw pse;
                }
            }
            catch (WebException exception)
            {
                var pse = HttpUrlConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.Register({0}) - error {1}", preApproval, pse));
                throw pse;
            }
        }
        /// <summary>
        /// Request a transaction refund from transaction code
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="transactionCode">Transaction Code</param>
        /// <returns><c cref="T:Uol.PagSeguro.CancelRequestResponse">Result</c></returns>
        public static RequestResponse RequestRefund(Credentials credentials, string transactionCode, decimal?refundValue = null)
        {
            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "RefundService.Register(transactionCode = {0}) - begin", transactionCode));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpPostConnection(
                           PagSeguroConfiguration.RefundUri.AbsoluteUri, BuildRefundURL(credentials, transactionCode, refundValue)))
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        RequestResponse refund = new RequestResponse();
                        RefundSerializer.Read(reader, refund);
                        PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "RefundService.Register({0}) - end", refund.ToString()));
                        return(refund);
                    }
                }
            }
            catch (WebException exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "RefundService.Register() - error {0}", pse));
                throw pse;
            }
        }
Пример #8
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;
            }
        }
        /// <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;
            }
        }
Пример #10
0
        /// <summary>
        /// CancelPreApproval
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="preApprovalCode">PreApproval code</param>
        /// <returns>The PreApprovalRequestResponse wich contains the response</returns>
        public static bool CancelPreApproval(Credentials credentials, string preApprovalCode)
        {
            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.CancelPreApproval({0}) - begin", preApprovalCode));

            try
            {
                using (var response = HttpUrlConnectionUtil.GetHttpGetConnection(BuildCancelUrl(credentials, preApprovalCode)))
                {
                    if (HttpStatusCode.OK.Equals(response.StatusCode))
                    {
                        using (var reader = XmlReader.Create(response.GetResponseStream()))
                        {
                            var paymentResponse = new PreApprovalRequestResponse(PagSeguroUris.GetPreApprovalCancelUri(credentials));
                            PreApprovalSerializer.Read(reader, paymentResponse);
                            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.CancelPreApproval({0}) - end {1}", preApprovalCode, paymentResponse.Status));
                            return(paymentResponse.Status.Equals("OK", StringComparison.CurrentCultureIgnoreCase));
                        }
                    }

                    var pse = HttpUrlConnectionUtil.CreatePagSeguroServiceException(response);
                    PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.CancelPreApproval({0}) - error {1}", preApprovalCode, pse));
                    throw pse;
                }
            }
            catch (WebException exception)
            {
                var pse = HttpUrlConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "PreApprovalService.CancelPreApproval({0}) - error {1}", preApprovalCode, pse));
                throw pse;
            }
        }
 /// <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 Installments GetInstallments(Credentials credentials, Decimal amount, String cardBrand)
 {
     PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "InstallmentService.GetInstallments() - begin"));
     try
     {
         using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(
                    BuildInstallmentURL(credentials, amount, cardBrand)))
         {
             using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
             {
                 Installments result = new Installments();
                 InstallmentsSerializer.Read(reader, result);
                 PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "InstallmentService.Register({0}) - end", result.ToString()));
                 return(result);
             }
         }
     }
     catch (ArgumentException exception)
     {
         PagSeguroServiceException pse = new PagSeguroServiceException(exception.Message);
         PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "InstallmentService.Register() - error {0}", exception.Message));
         throw pse;
     }
     catch (WebException exception)
     {
         PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
         PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "InstallmentService.Register() - error {0}", pse));
         throw pse;
     }
 }
Пример #12
0
        /// <summary>
        /// createCheckoutRequest is the actual implementation of the Register method
        /// This separation serves as test hook to validate the Uri
        /// against the code returned by the service
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="payment">Payment request information</param>
        /// <returns>The Uri to where the user needs to be redirected to in order to complete the payment process</returns>
        public static Uri CreateCheckoutRequest(Credentials credentials, PaymentRequest payment)
        {
            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PaymentService.Register({0}) - begin", payment));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpPostConnection(
                           PagSeguroConfiguration.CurrentConfig.PaymentUrl.AbsoluteUri, BuildCheckoutUrl(credentials, payment)))
                {
                    if (HttpStatusCode.OK.Equals(response.StatusCode))
                    {
                        using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                        {
                            PaymentRequestResponse paymentResponse = new PaymentRequestResponse(PagSeguroConfiguration.CurrentConfig.PaymentRedirectUrl);
                            PaymentSerializer.Read(reader, paymentResponse);
                            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PaymentService.Register({0}) - end {1}", payment, paymentResponse.PaymentRedirectUri));
                            return(paymentResponse.PaymentRedirectUri);
                        }
                    }
                    else
                    {
                        PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(response);
                        PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PaymentService.Register({0}) - error {1}", payment, pse));
                        throw pse;
                    }
                }
            }
            catch (WebException exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PaymentService.Register({0}) - error {1}", payment, pse));
                throw pse;
            }
        }
Пример #13
0
        /// <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;
            }
        }
Пример #14
0
        /// <summary>
        /// Creates a new authorization request
        /// </summary>
        /// <param name="credentials">PagSeguro credentials. Required</param>
        /// <param name="authorizationRequest">PagSeguro AuthorizationRequest</param>
        /// <param name="onlyAuthorizationCode"></param>
        /// <returns></returns>
        public static string CreateAuthorizationRequest(Credentials credentials, AuthorizationRequest authorizationRequest, bool onlyAuthorizationCode)
        {
            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "AuthorizationService.CreateAuthorizationRequest() - begin"));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpPostConnection(
                           PagSeguroConfiguration.AuthorizarionRequestUri.AbsoluteUri, buildAuthorizationRequestUrl(credentials, authorizationRequest)))
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        AuthorizationResponse authorization = new AuthorizationResponse();
                        AuthorizationSerializer.Read(reader, authorization);

                        if (onlyAuthorizationCode)
                        {
                            return(authorization.Code);
                        }
                        else
                        {
                            return(BuildAuthorizationURL(authorization.Code));
                        }
                    }
                }
            }
            catch (WebException pse)
            {
                throw pse;
            }
            catch (PagSeguroServiceException pse)
            {
                throw pse;
            }
        }
Пример #15
0
        /// <summary>
        /// Creates a new authorization request
        /// </summary>
        /// <param name="credentials">PagSeguro credentials. Required</param>
        /// <param name="authorizationRequest">PagSeguro AuthorizationRequest</param>
        /// <param name="onlyAuthorizationCode"></param>
        /// <returns></returns>
        public static string CreateAuthorizationRequest(Credentials credentials, AuthorizationRequest authorizationRequest, bool onlyAuthorizationCode)
        {
            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "AuthorizationService.CreateAuthorizationRequest() - begin"));

            try
            {
                using (var response = HttpUrlConnectionUtil.GetHttpPostConnection(
                           PagSeguroUris.GetAuthorizarionRequestUri(credentials).AbsoluteUri, BuildAuthorizationRequestUrl(credentials, authorizationRequest)))
                {
                    using (var reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        var authorization = new AuthorizationResponse();
                        AuthorizationSerializer.Read(reader, authorization);

                        return(onlyAuthorizationCode ? authorization.Code : BuildAuthorizationUrl(credentials, authorization.Code));
                    }
                }
            }
            catch (WebException pse)
            {
                throw pse;
            }
            catch (PagSeguroServiceException pse)
            {
                throw pse;
            }
        }
Пример #16
0
        /// <summary>
        /// CancelPreApproval
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="preApprovalCode">PreApproval code</param>
        /// <returns>The PreApprovalRequestResponse wich contains the response</returns>
        public static bool CancelPreApproval(Credentials credentials, string preApprovalCode)
        {
            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalService.CancelPreApproval({0}) - begin", preApprovalCode));

            try
            {
                using (var response = HttpURLConnectionUtil.GetHttpGetConnection(BuildCancelUrl(credentials, preApprovalCode)))
                {
                    if (HttpStatusCode.OK.Equals(response.StatusCode))
                    {
                        using (XmlReader reader = XmlReader.Create(response.Content.ReadAsStreamAsync().Result))
                        {
                            PreApprovalRequestResponse paymentResponse = new PreApprovalRequestResponse(PagSeguroConfiguration.PreApprovalCancelUri);
                            PreApprovalSerializer.Read(reader, paymentResponse);
                            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalService.CancelPreApproval({0}) - end {1}", preApprovalCode, paymentResponse.Status));
                            return(paymentResponse.Status.Equals("OK", StringComparison.CurrentCultureIgnoreCase));
                        }
                    }
                    else
                    {
                        PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(new System.Exception(response.StatusCode.ToString()));
                        PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PreApprovalService.CancelPreApproval({0}) - error {1}", preApprovalCode, pse));
                        throw pse;
                    }
                }
            }
            catch (System.Exception exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(exception);
                PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PreApprovalService.CancelPreApproval({0}) - error {1}", preApprovalCode, pse));
                throw pse;
            }
        }
 /// <summary>
 /// Request a transaction cancellation from transaction code
 /// </summary>
 /// <param name="credentials">PagSeguro credentials</param>
 /// <param name="transactionCode">Transaction Code</param>
 /// <returns><c cref="T:Uol.PagSeguro.CancelRequestResponse">Result</c></returns>
 public static RequestResponse RequestCancel(Credentials credentials, string transactionCode)
 {
     PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "CancelService.Register(transactionCode = {0}) - begin", transactionCode));
     try {
         using (var response = HttpUrlConnectionUtil.GetHttpPostConnection(
                    PagSeguroUris.GetCancelUri(credentials).AbsoluteUri, BuildCancelUrl(credentials, transactionCode)))
         {
             using (var reader = XmlReader.Create(response.GetResponseStream()))
             {
                 var cancel = new RequestResponse();
                 CancelSerializer.Read(reader, cancel);
                 PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "CancelService.createRequest({0}) - end", cancel.ToString()));
                 return(cancel);
             }
         }
     } catch (WebException exception) {
         var pse = HttpUrlConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
         PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "CancelService.createRequest() - error {0}", pse));
         throw pse;
     }
 }
Пример #18
0
 /// <summary>
 /// Request a transaction cancellation from transaction code
 /// </summary>
 /// <param name="credentials">PagSeguro credentials</param>
 /// <param name="transactionCode">Transaction Code</param>
 /// <returns><c cref="T:Uol.PagSeguro.CancelRequestResponse">Result</c></returns>
 public static RequestResponse RequestCancel(Credentials credentials, string transactionCode)
 {
     PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "CancelService.Register(transactionCode = {0}) - begin", transactionCode));
     try {
         using (var response = HttpURLConnectionUtil.GetHttpPostConnection(
                    PagSeguroConfiguration.CancelUri.AbsoluteUri, BuildCancelURL(credentials, transactionCode)))
         {
             using (XmlReader reader = XmlReader.Create(response.Content.ReadAsStreamAsync().Result))
             {
                 RequestResponse cancel = new RequestResponse();
                 CancelSerializer.Read(reader, cancel);
                 PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "CancelService.createRequest({0}) - end", cancel.ToString()));
                 return(cancel);
             }
         }
     } catch (System.Exception exception) {
         PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(exception);
         PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "CancelService.createRequest() - error {0}", pse));
         throw pse;
     }
 }
Пример #19
0
 /// <summary>
 /// Finds a pre-approval with a matching date interval
 /// </summary>
 /// <param name="credentials">PagSeguro credentials</param>
 /// <param name="initialDate"></param>
 /// <param name="finalDate">End of date range. Use DateTime.MaxValue to search without an upper boundary.</param>
 /// <param name="pageNumber">Page number, starting with 1. If passed as 0, it will call the web service to get the default page, also page number 1.</param>
 /// <param name="resultsPerPage">Results per page, optional.</param>
 /// <returns></returns>
 public static PreApprovalSearchResult SearchByDate(Credentials credentials, DateTime initialDate, DateTime finalDate, int?pageNumber = null, int?resultsPerPage = null)
 {
     PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByDate(initialDate={0} - finalDate={1}) - begin", initialDate, finalDate));
     try
     {
         using (var response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByDate(credentials, initialDate, finalDate, pageNumber, resultsPerPage)))
         {
             using (XmlReader reader = XmlReader.Create(response.Content.ReadAsStreamAsync().Result))
             {
                 PreApprovalSearchResult preApproval = new PreApprovalSearchResult();
                 PreApprovalSearchResultSerializer.Read(reader, preApproval);
                 PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByDate(initialDate={0} - finalDate={1}) - end {2}", initialDate, finalDate, preApproval));
                 return(preApproval);
             }
         }
     }
     catch (System.Exception exception)
     {
         PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(exception);
         PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByDate(initialDate={0} - finalDate={1}) - error {2}", initialDate, finalDate, pse));
         throw pse;
     }
 }
 /// <summary>
 /// Finds a pre-approval with a matching pre-approval reference
 /// </summary>
 /// <param name="credentials">PagSeguro credentials</param>
 /// <param name="reference">PagSeguro Pre-Approval Reference</param>
 /// <param name="initialDate"></param>
 /// <param name="finalDate">End of date range. Use DateTime.MaxValue to search without an upper boundary.</param>
 /// <param name="pageNumber">Page number, starting with 1. If passed as 0, it will call the web service to get the default page, also page number 1.</param>
 /// <param name="resultsPerPage">Results per page, optional.</param>
 /// <returns></returns>
 public static PreApprovalSearchResult SearchByReference(Credentials credentials, string reference, DateTime initialDate, DateTime finalDate, int?pageNumber = null, int?resultsPerPage = null)
 {
     PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByReference(reference={0}) - begin", reference));
     try
     {
         using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByReference(credentials, reference, initialDate, finalDate, pageNumber, resultsPerPage)))
         {
             using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
             {
                 PreApprovalSearchResult preApproval = new PreApprovalSearchResult();
                 PreApprovalSearchResultSerializer.Read(reader, preApproval);
                 PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByReference(reference={0}) - end {1}", reference, preApproval));
                 return(preApproval);
             }
         }
     }
     catch (WebException exception)
     {
         PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
         PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByReference(reference={0}) - error {1}", reference, pse));
         throw pse;
     }
 }
Пример #21
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;
            }
        }
Пример #22
0
        /// <summary>
        /// Common implmentation of all SearchByDate methods
        /// </summary>
        /// <param name="credentials">PagSeguro credentials. Required.</param>
        /// <param name="initialDate"></param>
        /// <param name="finalDate">End of date range. Use DateTime.MaxValue to search without an upper boundary.</param>
        /// <param name="pageNumber">Page number, starting with 1. If passed as 0, it will call the web service to get the default page, also page number 1.</param>
        /// <param name="resultsPerPage">Results per page, optional.</param>
        /// <returns></returns>
        private static TransactionSearchResult SearchByDateCore(Credentials credentials, DateTime initialDate, DateTime finalDate, int pageNumber, int resultsPerPage)
        {
            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByDate(initialDate={0}, finalDate={1}) - begin", initialDate, finalDate));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByDate(credentials, initialDate, finalDate, pageNumber, resultsPerPage)))
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        TransactionSearchResult result = new TransactionSearchResult();
                        TransactionSearchResultSerializer.Read(reader, result);
                        PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByDate(initialDate={0}, finalDate={1}) - end {2}", initialDate, finalDate, result));
                        return(result);
                    }
                }
            }
            catch (WebException exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByDate(initialDate={0}, finalDate={1}) - error {2}", initialDate, finalDate, pse));
                throw pse;
            }
        }
        /// <summary>
        /// Finds a transaction with a matching reference code
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="reference">Reference</param>
        /// <returns></returns>
        public static TransactionSearchResult SearchByReference(Credentials credentials, string reference)
        {
            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByReference(reference={0}) - begin", reference));

            try
            {
                using (var response = HttpUrlConnectionUtil.GetHttpGetConnection(BuildSearchUrlByReference(credentials, reference)))
                {
                    using (var reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        var result = new TransactionSearchResult();
                        TransactionSearchResultSerializer.Read(reader, result);
                        PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByReference(reference={0}) - end", reference));
                        return(result);
                    }
                }
            }
            catch (WebException exception)
            {
                var pse = HttpUrlConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByReference(reference={0}) - error {1}", reference, pse));
                throw pse;
            }
        }
Пример #24
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;
            }
        }
 /// <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>
        /// 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;
            }
        }
Пример #27
0
        /// <summary>
        /// Finds a transaction with a matching reference code
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="reference">Reference</param>
        /// <returns></returns>
        public static TransactionSearchResult SearchByReference(Credentials credentials, string reference)
        {
            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByReference(reference={0}) - begin", reference));

            try
            {
                using (var response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByReference(credentials, reference)))
                {
                    using (XmlReader reader = XmlReader.Create(response.Content.ReadAsStreamAsync().Result))
                    {
                        TransactionSearchResult result = new TransactionSearchResult();
                        TransactionSearchResultSerializer.Read(reader, result);
                        PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByReference(reference={0}) - end", reference));
                        return(result);
                    }
                }
            }
            catch (System.Exception exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(exception);
                PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByReference(reference={0}) - error {1}", reference, pse));
                throw pse;
            }
        }
Пример #28
0
        /// <summary>
        /// Finds a pre-approval with a matching day interval
        /// </summary>
        /// <param name="credentials">PagSeguro credentials</param>
        /// <param name="interval">Day interval</param>
        /// <returns cref="T:Uol.PagSeguro.PreApprovalSearchResult"><c>PreApprovalSearchResult</c></returns>
        public static PreApprovalSearchResult SearchByInterval(Credentials credentials, int interval)
        {
            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByInterval(Days={0}) - begin", interval));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByInterval(credentials, interval)))
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        PreApprovalSearchResult preApproval = new PreApprovalSearchResult();
                        PreApprovalSearchResultSerializer.Read(reader, preApproval);
                        PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByInterval(Days={0}) - end {1}", interval, preApproval));
                        return(preApproval);
                    }
                }
            }
            catch (WebException exception)
            {
                PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response);
                PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByInterval(Days={0}) - error {1}", interval, pse));
                throw pse;
            }
        }