/// <summary> /// Constructs a url for a section group /// </summary> /// <param name="groupName">Name of group</param> /// <returns>Url</returns> public string GetSectionGroupUrl(string groupName) { return(UriSupport.AddQueryString(RemoveQueryStringByKey(HttpContext.Current.Request.Url.AbsoluteUri, "p"), "t", HttpContext.Current.Server.UrlEncode(groupName))); }
/// <summary> /// Create a string with an absolute link to the page. Checks if furl is enabled and rewrites the link if appropriate. /// </summary> /// <param name="page">A PageData to create an absolute link from.</param> /// <returns>An absolute link to page</returns> public static string CreateExternalLink(PageData page) { UrlBuilder url = new UrlBuilder(UriSupport.Combine(Settings.Instance.SiteUrl.ToString(), page.LinkURL)); return(url.ToString()); }
/// <summary> /// Processes the unsuccessful transaction. /// </summary> /// <param name="cancelUrl">The cancel url.</param> /// <param name="errorMessage">The error message.</param> /// <returns>The url redirection after process.</returns> public string ProcessUnsuccessfulTransaction(string cancelUrl, string errorMessage) { return(UriSupport.AddQueryString(cancelUrl, "message", errorMessage)); }
/// <summary> /// Processes the successful transaction, was called when PayPal.com redirect back. /// </summary> /// <param name="orderGroup">The order group that was processed.</param> /// <param name="payment">The order payment.</param> /// <param name="acceptUrl">The redirect url when finished.</param> /// <param name="cancelUrl">The redirect url when error happens.</param> /// <returns>The url redirection after process.</returns> public string ProcessSuccessfulTransaction(IOrderGroup orderGroup, IPayment payment, string acceptUrl, string cancelUrl) { if (HttpContext.Current == null) { return(cancelUrl); } if (HttpContext.Current.Session != null) { HttpContext.Current.Session.Remove("LastCouponCode"); } if (!(orderGroup is ICart cart)) { // return to the shopping cart page immediately and show error messages return(ProcessUnsuccessfulTransaction(cancelUrl, Utilities.Translate("CommitTranErrorCartNull"))); } string redirectionUrl; using (var scope = new TransactionScope()) { SetSecurityProtocolToTls12(); var getDetailRequest = new GetExpressCheckoutDetailsRequestType { Token = payment.Properties[PayPalExpTokenPropertyName] as string // Add request-specific fields to the request. }; // Execute the API operation and obtain the response. var caller = PayPalApiHelper.GetPayPalApiCallerServices(_paymentMethodConfiguration); var getDetailsResponse = caller.GetExpressCheckoutDetails(new GetExpressCheckoutDetailsReq { GetExpressCheckoutDetailsRequest = getDetailRequest }); var errorCheck = _payPalApiHelper.CheckErrors(getDetailsResponse); if (!string.IsNullOrEmpty(errorCheck)) { RestoreSecurityProtocol(); // unsuccessful get detail call return(ProcessUnsuccessfulTransaction(cancelUrl, errorCheck)); } var expressCheckoutDetailsResponse = getDetailsResponse.GetExpressCheckoutDetailsResponseDetails; // get commerceOrderId from what we put to PayPal instead of getting from cookie payment.Properties[PayPalOrderNumberPropertyName] = expressCheckoutDetailsResponse.InvoiceID; //process details sent from paypal, changing addresses if required string emptyAddressMsg; //process billing address var payPalBillingAddress = expressCheckoutDetailsResponse.BillingAddress; if (payPalBillingAddress != null && AddressHandling.IsAddressChanged(payment.BillingAddress, payPalBillingAddress)) { emptyAddressMsg = _payPalApiHelper.ProcessOrderAddress(expressCheckoutDetailsResponse.PayerInfo, payPalBillingAddress, payment.BillingAddress, CustomerAddressTypeEnum.Billing, "CommitTranErrorPayPalBillingAddressEmpty"); if (!string.IsNullOrEmpty(emptyAddressMsg)) { RestoreSecurityProtocol(); return(ProcessUnsuccessfulTransaction(cancelUrl, emptyAddressMsg)); } } //process shipping address var payPalShippingAddress = expressCheckoutDetailsResponse.PaymentDetails[0].ShipToAddress; if (payPalShippingAddress != null && AddressHandling.IsAddressChanged(cart.GetFirstShipment().ShippingAddress, payPalShippingAddress)) { //when address was changed on PayPal site, it might cause changing tax value changed and changing order value also. var taxValueBefore = _taxCalculator.GetTaxTotal(cart, cart.Market, cart.Currency); var shippingAddress = orderGroup.CreateOrderAddress("address"); emptyAddressMsg = _payPalApiHelper.ProcessOrderAddress(expressCheckoutDetailsResponse.PayerInfo, payPalShippingAddress, shippingAddress, CustomerAddressTypeEnum.Shipping, "CommitTranErrorPayPalShippingAddressEmpty"); if (!string.IsNullOrEmpty(emptyAddressMsg)) { RestoreSecurityProtocol(); return(ProcessUnsuccessfulTransaction(cancelUrl, emptyAddressMsg)); } cart.GetFirstShipment().ShippingAddress = shippingAddress; var taxValueAfter = _taxCalculator.GetTaxTotal(cart, cart.Market, cart.Currency); if (taxValueBefore != taxValueAfter) { RestoreSecurityProtocol(); _orderRepository.Save(cart); // Saving cart to submit order address changed. scope.Complete(); return(ProcessUnsuccessfulTransaction(cancelUrl, Utilities.Translate("ProcessPaymentTaxValueChangedWarning"))); } } // Add request-specific fields to the request. // Create the request details object. var doExpressChkOutPaymentReqDetails = CreateExpressCheckoutPaymentRequest(getDetailsResponse, orderGroup, payment); // Execute the API operation and obtain the response. var doCheckOutResponse = caller.DoExpressCheckoutPayment(new DoExpressCheckoutPaymentReq { DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType(doExpressChkOutPaymentReqDetails) }); errorCheck = _payPalApiHelper.CheckErrors(doCheckOutResponse); if (!string.IsNullOrEmpty(errorCheck)) { RestoreSecurityProtocol(); // unsuccessful doCheckout response return(ProcessUnsuccessfulTransaction(cancelUrl, errorCheck)); } // everything is fine, this is a flag to tell ProcessPayment know about this case: redirect back from PayPal with accepted payment var errorMessages = new List <string>(); var cartCompleted = DoCompletingCart(cart, errorMessages); if (!cartCompleted) { RestoreSecurityProtocol(); return(UriSupport.AddQueryString(cancelUrl, "message", string.Join(";", errorMessages.Distinct().ToArray()))); } // Place order var purchaseOrder = MakePurchaseOrder(doCheckOutResponse, cart, payment); // Commit changes scope.Complete(); redirectionUrl = CreateRedirectionUrl(purchaseOrder, acceptUrl, payment.BillingAddress.Email); RestoreSecurityProtocol(); } _logger.Information($"PayPal transaction succeeds, redirect end user to {redirectionUrl}"); return(redirectionUrl); }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); MasterPageFile = UriSupport.ResolveUrlFromUIBySettings("MasterPages/Frameworks/Framework.Master"); }
public static string GetParticipantInfo(IParticipant participant, string propertyname) { if (participant == null) { return(string.Empty); } { if (String.IsNullOrEmpty(propertyname)) { return(String.Empty); } propertyname = propertyname.ToLower(); switch (propertyname) { case "editurl": var internalUrl = UrlResolver.Current.GetUrl(participant.EventPage); UrlBuilder relativeUrl = new UrlBuilder(internalUrl); Global.UrlRewriteProvider.ConvertToExternal(relativeUrl, null, System.Text.Encoding.UTF8); string url = UriSupport.AbsoluteUrlBySettings(relativeUrl.ToString()); url = EPiServer.UriSupport.AddQueryString(url, "code", participant.Code); url = EPiServer.UriSupport.AddQueryString(url, "email", participant.Email); return(url); case "username": return(participant.Username); case "registrationcode": return(participant.Code); case "email": return(participant.Email); case "price": return(participant.Price.ToString()); case "eventname": case "coursename": return(DataFactory.Instance.Get <EventPageBase>(participant.EventPage).Name); case "submitted": return(participant.DateSubmitted.ToString("yyyy-MM-dd HH:mm")); case "status": return(participant.AttendStatus.ToString()); case "fullname": return(GetParticipantInfo(participant, "FirstName") + " " + GetParticipantInfo(participant, "LastName")); case "datestring": return(GetEventDates(participant.EventPage)); case "coursedatestring": return(string.Format(LocalizationService.Current.GetString("/attend/diploma/datetext"), GetEventDates(participant.EventPage))); default: { try { SerializableXmlDocument xmlDoc = new SerializableXmlDocument(); xmlDoc.LoadXml(participant.XForm); foreach (XmlNode formNode in xmlDoc.SelectNodes("instance/*")) { if (propertyname == formNode.Name.Replace('_', ' ').ToLower()) { return(formNode.InnerText); } } foreach (XmlNode formNode in xmlDoc.SelectNodes("FormData/*")) { if (propertyname == formNode.Name.Replace('_', ' ').ToLower()) { return(formNode.InnerText); } } } catch (Exception) { } } break; } return(String.Empty); } }
public void Three_extra_args() { string uri = UriSupport.Combine("http://www.base.url", "part2", new UriArg("arg1", "val1"), new UriArg("arg2", "val2"), new UriArg("arg3", "val3")); Assert.That(uri, Is.EqualTo("http://www.base.url/part2?arg1=val1&arg2=val2&arg3=val3")); }
public void One_extra_arg() { string uri = UriSupport.Combine("http://www.base.url", "part2", new UriArg("arg1", "val1")); Assert.That(uri, Is.EqualTo("http://www.base.url/part2?arg1=val1")); }
public void One_extra_arg_when_ending_with_questionmark() { string uri = UriSupport.Combine("http://www.base.url", "part2?", new UriArg("arg1", "val1")); Assert.That(uri, Is.EqualTo("http://www.base.url/part2?arg1=val1")); }
public void Empty_apiEndpointPart(string apiEndpointPart) { string uri = UriSupport.Combine("http://www.base.url", apiEndpointPart); Assert.That(uri, Is.EqualTo("http://www.base.url")); }
public void Double_glue_slash() { string uri = UriSupport.Combine("http://www.base.url/", "/part2"); Assert.That(uri, Is.EqualTo("http://www.base.url/part2")); }
public void Empty_baseUri_not_allowed(string baseUri, string apiEndpointPart) { Assert.Throws <ArgumentException>(() => UriSupport.Combine(baseUri, apiEndpointPart)); }
public void Three_extra_args_with_non_string_value() { string uri = UriSupport.Combine("http://www.base.url", "part2", new UriArg("arg1", 42), new UriArg("arg2", Guid.Empty), new UriArg("arg3", false)); Assert.That(uri, Is.EqualTo("http://www.base.url/part2?arg1=42&arg2=00000000-0000-0000-0000-000000000000&arg3=False")); }
public void One_extra_arg_with_illegal_chars() { string uri = UriSupport.Combine("http://www.base.url", "part2", new UriArg("arg:<?&>1", "val:<?&>1")); Assert.That(uri, Is.EqualTo("http://www.base.url/part2?arg%3A%3C%3F%26%3E1=val%3A%3C%3F%26%3E1")); }
/// <summary> /// Create URL for a specified paging page. /// </summary> /// <param name="pageNumber">Number of page for which to get a url</param> /// <returns>Url for specified page</returns> public string GetPagingUrl(int pageNumber) { return(UriSupport.AddQueryString(HttpContext.Current.Request.RawUrl, "p", pageNumber.ToString())); }
public void One_extra_arg_when_existing_arg_ending_with_ampersand() { string uri = UriSupport.Combine("http://www.base.url", "part2?arg0=val0&", new UriArg("arg1", "val1")); Assert.That(uri, Is.EqualTo("http://www.base.url/part2?arg0=val0&arg1=val1")); }
/// <summary> /// Create URL for the next paging section. /// </summary> /// <returns>Url for next paging section</returns> public string GetNextPagingSectionUrl() { return(UriSupport.AddQueryString(HttpContext.Current.Request.RawUrl, "p", ((PagingSection * PagingSectionSize) + 1).ToString())); }
/// <summary> /// When search button is clicked, we reload the page to trigger a new search /// </summary> protected void SearchClick(object sender, EventArgs e) { string searchText = Server.UrlEncode(SearchKeywords.Text.Trim()); Response.Redirect(UriSupport.AddQueryString(CurrentPage.LinkURL, "q", searchText)); }