/// <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.PaymentUri.AbsoluteUri, BuildCheckoutUrl(credentials, payment))) { if (HttpStatusCode.OK.Equals(response.StatusCode)) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { PaymentRequestResponse paymentResponse = new PaymentRequestResponse(PagSeguroConfiguration.PaymentRedirectUri); 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; } }
/// <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, bool preApproval) { PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByCode(transactionCode={0}) - begin", transactionCode)); try { using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByCode(credentials, transactionCode, preApproval))) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { Transaction transaction = new Transaction(); TransactionSerializer.Read(reader, transaction, preApproval); 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; } }
/// <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; } }
/// <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))) { 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; } }
/// <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> /// 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> /// 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, Boolean 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; } }
/// <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 (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildTransactionNotificationUrl(credentials,notificationCode))) { 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 = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response); PagSeguroTrace.Error( String.Format(CultureInfo.InvariantCulture, "NotificationService.CheckTransaction(notificationCode={0}) - error {1}", notificationCode, pse)); throw pse; } }
/// <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 (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildCancelUrl(credentials, preApprovalCode))) { if (HttpStatusCode.OK.Equals(response.StatusCode)) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { 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(response); PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PreApprovalService.CancelPreApproval({0}) - error {1}", preApprovalCode, pse)); throw pse; } } } catch (WebException exception) { PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response); PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PreApprovalService.CancelPreApproval({0}) - error {1}", preApprovalCode, pse)); throw pse; } }
/// <summary> /// /// </summary> /// <param name="credentials"></param> /// <param name="notificationCode"></param> /// <returns></returns> private static string BuildTransactionNotificationUrl(Credentials credentials, string notificationCode) { QueryStringBuilder transactionNotificationUrl = new QueryStringBuilder("{url}/{notificationCode}?{credential}"); transactionNotificationUrl.ReplaceValue("{url}", PagSeguroConfiguration.NotificationUri.AbsoluteUri); transactionNotificationUrl.ReplaceValue("{notificationCode}", HttpUtility.UrlEncode(notificationCode)); transactionNotificationUrl.ReplaceValue("{credential}", new QueryStringBuilder().EncodeCredentialsAsQueryString(credentials).ToString()); return transactionNotificationUrl.ToString(); }
/// <summary> /// /// </summary> /// <param name="credentials">PagSeguro credentials</param> /// <param name="transactionCode">Transaction Code</param> /// <returns></returns> private static string BuildCancelURL(Credentials credentials, string transactionCode) { QueryStringBuilder builder = new QueryStringBuilder(); builder.EncodeCredentialsAsQueryString(credentials); builder.Append("transactionCode", transactionCode); return builder.ToString(); }
/// <summary> /// /// </summary> /// <param name="credentials"></param> /// <param name="notificationCode"></param> /// <returns></returns> private static string BuildTransactionNotificationUrl(Credentials credentials, string notificationCode, bool preApproval) { QueryStringBuilder transactionNotificationUrl = new QueryStringBuilder("{url}/{notificationCode}?{credential}"); if (preApproval == true) transactionNotificationUrl.ReplaceValue("{url}", PagSeguroConfiguration.CurrentConfig.PreApprovalNotificationUrl.AbsoluteUri); else transactionNotificationUrl.ReplaceValue("{url}", PagSeguroConfiguration.CurrentConfig.NotificationUrl.AbsoluteUri); transactionNotificationUrl.ReplaceValue("{notificationCode}", HttpUtility.UrlEncode(notificationCode)); transactionNotificationUrl.ReplaceValue("{credential}", new QueryStringBuilder().EncodeCredentialsAsQueryString(credentials).ToString()); return transactionNotificationUrl.ToString(); }
private static String BuildInstallmentURL(Credentials credentials, Decimal amount, String cardBrand) { QueryStringBuilder builder = new QueryStringBuilder("{url}?{credentials}&amount={amount}&cardBrand={cardBrand}"); builder.ReplaceValue("{url}", PagSeguroConfiguration.InstallmentUri.AbsoluteUri); builder.ReplaceValue("{credentials}", new QueryStringBuilder().EncodeCredentialsAsQueryString(credentials).ToString()); builder.ReplaceValue("{amount}", PagSeguroUtil.DecimalFormat(amount)); builder.ReplaceValue("{cardBrand}", HttpUtility.UrlEncode(cardBrand.ToString())); return builder.ToString(); }
/// <summary> /// /// </summary> /// <param name="credentials">PagSeguro credentials</param> /// <param name="transactionCode">Transaction Code</param> /// <param name="refundValue">Refund Value</param> /// <returns></returns> private static string BuildRefundURL(Credentials credentials, string transactionCode, decimal? refundValue) { QueryStringBuilder builder = new QueryStringBuilder(); builder.EncodeCredentialsAsQueryString(credentials); builder.Append("transactionCode", transactionCode); if (refundValue.HasValue) { builder.Append("refundValue", PagSeguroUtil.DecimalFormat(refundValue.Value)); } return builder.ToString(); }
/// <summary> /// /// </summary> /// <param name="credentials"></param> /// <param name="payment"></param> /// <returns></returns> internal static string BuildTransactionUrl(Credentials credentials, Checkout checkout) { QueryStringBuilder builder = new QueryStringBuilder(); IDictionary<string, string> data = TransactionParse.GetData(checkout); builder. EncodeCredentialsAsQueryString(credentials); foreach (KeyValuePair<string, string> pair in data) { builder.Append(pair.Key, pair.Value); } return builder.ToString(); }
/// <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(HttpWebResponse response = HttpURLConnectionUtil.GetHttpPostConnection( PagSeguroConfiguration.CancelUri.AbsoluteUri, BuildCancelURL(credentials, transactionCode))) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { RequestResponse cancel = new RequestResponse(); CancelSerializer.Read(reader, cancel); PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "CancelService.createRequest({0}) - end", cancel.ToString())); return cancel; } } } catch (WebException exception) { PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response); PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "CancelService.createRequest() - error {0}", 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; } }
/// <summary> /// Finds abandoned transactions /// </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 TransactionSearchResult SearchAbandoned(Credentials credentials, DateTime initialDate, DateTime finalDate, int? pageNumber = null, int? resultsPerPage = null) { PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchAbandoned(initialDate={0}, finalDate={1}) - begin", initialDate, finalDate)); try { using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlAbandoned(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.SearchAbandoned(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.SearchAbandoned(initialDate={0}, finalDate={1}) - error {2}", initialDate, finalDate, pse)); throw pse; } }
/// <summary> /// /// </summary> /// <param name="credentials"></param> /// <param name="initialDate"></param> /// <param name="finalDate"></param> /// <param name="pageNumber"></param> /// <param name="resultsPerPage"></param> /// <returns></returns> private static string BuildSearchUrlByDate(Credentials credentials, DateTime initialDate, DateTime finalDate, int pageNumber, int resultsPerPage, bool preApproval) { QueryStringBuilder searchUrlByCode = new QueryStringBuilder("{url}/?initialDate={initialDate}{finalDate}{page}{maxPageResults}{credential}"); if (preApproval == true) searchUrlByCode.ReplaceValue("{url}", PagSeguroConfiguration.PreApprovalSearchUri.AbsoluteUri); else searchUrlByCode.ReplaceValue("{url}", PagSeguroConfiguration.SearchUri.AbsoluteUri); searchUrlByCode.ReplaceValue("{initialDate}", PagSeguroUtil.FormatDateXml(initialDate)); searchUrlByCode.ReplaceValue("{finalDate}", finalDate < DateTime.MaxValue ? "&" + FinalDateParameterName + "=" + PagSeguroUtil.FormatDateXml(finalDate) : ""); searchUrlByCode.ReplaceValue("{page}", pageNumber > 0 ? "&" + PageNumberParameterName + "=" + pageNumber : ""); searchUrlByCode.ReplaceValue("{maxPageResults}", resultsPerPage > 0 ? "&" + MaxPageResultsParameterName + "=" + resultsPerPage : ""); searchUrlByCode.ReplaceValue("{credential}", credentials != null ? new QueryStringBuilder().AppendToQuery("&").EncodeCredentialsAsQueryString(credentials).ToString() : ""); return PagSeguroUtil.RemoveExtraSpaces(searchUrlByCode.ToString()); }
/// <summary> /// Search transactions associated with this set of credentials within a date range /// </summary> /// <param name="credentials"></param> /// <param name="initialDate"></param> /// <param name="pageNumber"></param> /// <returns></returns> public static TransactionSearchResult SearchByDate(Credentials credentials, DateTime initialDate, int pageNumber, bool preApproval) { return SearchByDateCore(credentials, initialDate, DateTime.MaxValue, pageNumber, 0, preApproval); }
/// <summary> /// Search transactions associated with this set of credentials within a date range /// </summary> /// <param name="credentials"></param> /// <param name="initialDate"></param> /// <param name="finalDate"></param> /// <param name="pageNumber"></param> /// <param name="resultsPerPage"></param> /// <returns></returns> public static TransactionSearchResult SearchByDate(Credentials credentials, DateTime initialDate, DateTime finalDate, int pageNumber, int resultsPerPage, bool preApproval) { return SearchByDateCore(credentials, initialDate, finalDate, pageNumber, resultsPerPage, preApproval); }
/// <summary> /// /// </summary> /// <param name="credentials"></param> /// <param name="transactionCode"></param> /// <returns></returns> private static string BuildSearchUrlByCode(Credentials credentials, string transactionCode, bool preApproval) { QueryStringBuilder searchUrlByCode; if (preApproval == true) { searchUrlByCode = new QueryStringBuilder("{url}/{preApprovalCode}?{credential}"); searchUrlByCode.ReplaceValue("{url}", PagSeguroConfiguration.PreApprovalSearchUri.AbsoluteUri); searchUrlByCode.ReplaceValue("{preApprovalCode}", HttpUtility.UrlEncode(transactionCode)); } else { searchUrlByCode = new QueryStringBuilder("{url}/{transactionCode}?{credential}"); searchUrlByCode.ReplaceValue("{url}", PagSeguroConfiguration.PreApprovalSearchUri.AbsoluteUri); searchUrlByCode.ReplaceValue("{transactionCode}", HttpUtility.UrlEncode(transactionCode)); } searchUrlByCode.ReplaceValue("{credential}", new QueryStringBuilder().EncodeCredentialsAsQueryString(credentials).ToString()); return searchUrlByCode.ToString(); }
/// <summary> /// Calls the PagSeguro web service and register this request for payment /// </summary> /// <param name="credentials">PagSeguro credentials</param> /// <returns>The Uri to where the user needs to be redirected to in order to complete the payment process</returns> public Uri Register(Credentials credentials) { return(PaymentService.CreateCheckoutRequest(credentials, this)); }
/// <summary> /// Search transactions associated with this set of credentials within a date range /// </summary> /// <param name="credentials"></param> /// <param name="initialDate"></param> /// <param name="finalDate"></param> /// <returns></returns> public static TransactionSearchResult SearchByDate(Credentials credentials, DateTime initialDate, DateTime finalDate, bool preApproval) { return SearchByDateCore(credentials, initialDate, finalDate, 0, 0, preApproval); }
/// <summary> /// Calls the PagSeguro web service and register this request for payment /// </summary> /// <param name="credentials">PagSeguro credentials</param> /// <returns>The Uri to where the user needs to be redirected to in order to complete the payment process</returns> public Uri Register(Credentials credentials) { return PaymentService.CreateCheckoutRequest(credentials, this); }
/// <summary> /// /// </summary> /// <param name="credentials"></param> /// <param name="notificationCode"></param> /// <returns></returns> private static string BuildSearchUrlByNotification(Credentials credentials, string notificationCode) { QueryStringBuilder searchUrlByNotification; searchUrlByNotification = new QueryStringBuilder("{url}/notifications/{notificationCode}?{credential}"); searchUrlByNotification.ReplaceValue("{url}", PagSeguroConfiguration.PreApprovalSearchUri.AbsoluteUri); searchUrlByNotification.ReplaceValue("{notificationCode}", HttpUtility.UrlEncode(notificationCode)); searchUrlByNotification.ReplaceValue("{credential}", new QueryStringBuilder().EncodeCredentialsAsQueryString(credentials).ToString()); return searchUrlByNotification.ToString(); }
/// <summary> /// Search transactions associated with this set of credentials within a date range /// </summary> /// <param name="credentials"></param> /// <param name="initialDate"></param> /// <returns></returns> public static TransactionSearchResult SearchByDate(Credentials credentials, DateTime initialDate) { return SearchByDateCore(credentials, initialDate, DateTime.MaxValue, 0, 0); }
/// <summary> /// Search transactions associated with this set of credentials within a date range /// </summary> /// <param name="credentials"></param> /// <param name="initialDate"></param> /// <param name="finalDate"></param> /// <param name="pageNumber"></param> /// <returns></returns> public static TransactionSearchResult SearchByDate(Credentials credentials, DateTime initialDate, DateTime finalDate, int pageNumber) { return SearchByDateCore(credentials, initialDate, finalDate, pageNumber, 0); }
/// <summary> /// Search transactions associated with this set of credentials within a date range /// </summary> /// <param name="credentials"></param> /// <param name="initialDate"></param> /// <param name="pageNumber"></param> /// <param name="resultsPerPage"></param> /// <returns></returns> public static TransactionSearchResult SearchByDate(Credentials credentials, DateTime initialDate, int pageNumber, int resultsPerPage) { return SearchByDateCore(credentials, initialDate, DateTime.MaxValue, pageNumber, resultsPerPage); }
/// <summary> /// /// </summary> /// <param name="credentials"></param> /// <param name="payment"></param> /// <returns></returns> internal static string BuildCheckoutUrl(Credentials credentials, PaymentRequest payment) { QueryStringBuilder builder = new QueryStringBuilder(); IDictionary<string, string> data = PaymentParse.GetData(payment); builder. EncodeCredentialsAsQueryString(credentials); foreach (KeyValuePair<string, string> pair in data) { builder.Append(pair.Key, pair.Value); } return builder.ToString(); }
/// <summary> /// /// </summary> /// <param name="credentials"></param> /// <param name="reference"></param> /// <param name="initialDate"></param> /// <param name="finalDate"></param> /// <param name="pageNumber"></param> /// <param name="resultsPerPage"></param> /// <returns></returns> private static string BuildSearchUrlByReference(Credentials credentials, String reference, DateTime initialDate, DateTime finalDate, int? pageNumber, int? resultsPerPage) { QueryStringBuilder builder = new QueryStringBuilder("{url}?reference={reference}&initialDate={initialDate}{finalDate}{page}{maxPageResults}{credential}"); builder.ReplaceValue("{url}", PagSeguroConfiguration.PreApprovalSearchUri.AbsoluteUri); builder.ReplaceValue("{reference}", HttpUtility.UrlEncode(reference)); builder.ReplaceValue("{initialDate}", PagSeguroUtil.FormatDateXml(initialDate)); builder.ReplaceValue("{finalDate}", finalDate < DateTime.MaxValue ? "&" + FinalDateParameterName + "=" + PagSeguroUtil.FormatDateXml(finalDate) : ""); if (pageNumber.HasValue) { builder.ReplaceValue("{page}", pageNumber > 0 ? "&" + PageNumberParameterName + "=" + pageNumber : ""); } if (resultsPerPage.HasValue) { builder.ReplaceValue("{maxPageResults}", resultsPerPage > 0 ? "&" + MaxPageResultsParameterName + "=" + resultsPerPage : ""); } builder.ReplaceValue("{credential}", credentials != null ? new QueryStringBuilder().AppendToQuery("&").EncodeCredentialsAsQueryString(credentials).ToString() : ""); return PagSeguroUtil.RemoveExtraSpaces(builder.ToString()); }