protected virtual CheckoutMerchantUrls GetMerchantUrls(ICart cart) { if (PaymentMethodDto == null) { return(null); } var configuration = GetConfiguration(cart.MarketId); Uri ToFullSiteUrl(Func <CheckoutConfiguration, string> fieldSelector) { var url = fieldSelector(configuration).Replace("{orderGroupId}", cart.OrderLink.OrderGroupId.ToString()); if (Uri.TryCreate(url, UriKind.Absolute, out var uri)) { return(uri); } return(new Uri(SiteUrlHelper.GetCurrentSiteUrl(), url)); } return(new CheckoutMerchantUrls { Terms = ToFullSiteUrl(c => c.TermsUrl).ToString(), CancellationTerms = !string.IsNullOrEmpty(configuration.CancellationTermsUrl) ? ToFullSiteUrl(c => c.CancellationTermsUrl).ToString() : null, Checkout = ToFullSiteUrl(c => c.CheckoutUrl).ToString(), Confirmation = ToFullSiteUrl(c => c.ConfirmationUrl).ToString(), Push = ToFullSiteUrl(c => c.PushUrl).ToString(), AddressUpdate = ToFullSiteUrl(c => c.AddressUpdateUrl).ToString(), ShippingOptionUpdate = ToFullSiteUrl(c => c.ShippingOptionUpdateUrl).ToString(), Notification = ToFullSiteUrl(c => c.NotificationUrl).ToString(), Validation = ToFullSiteUrl(c => c.OrderValidationUrl).ToString() }); }
public async Task <bool> CreateOrUpdateSession(ICart cart, IDictionary <string, object> dic = null) { var additional = dic ?? new Dictionary <string, object>(); return(await CreateOrUpdateSession( cart, new SessionSettings(SiteUrlHelper.GetCurrentSiteUrl()) { AdditionalValues = additional }) .ConfigureAwait(false)); }
public static string ToAbsoluteUrl(this string url) { var siteUri = SiteUrlHelper.GetCurrentSiteUrl(); if (siteUri == null || url == null) { return(null); } return(new Uri(siteUri, url).ToString()); }
private string ToFullSiteUrl(Uri siteUrl, string url) { if (Uri.TryCreate(url, UriKind.Absolute, out var absolute)) { return(absolute.ToString()); } if (siteUrl == null) { siteUrl = SiteUrlHelper.GetCurrentSiteUrl(); } return(new Uri(siteUrl, url).ToString()); }
private void UpdateOrderLines(IList <OrderLine> orderLines, CheckoutConfiguration checkoutConfiguration) { foreach (var lineItem in orderLines) { if (lineItem != null && lineItem.Type.Equals("physical")) { EntryContentBase entryContent = null; FashionProduct product = null; if (!string.IsNullOrEmpty(lineItem.Reference)) { var contentLink = _referenceConverter.Service.GetContentLink(lineItem.Reference); if (!ContentReference.IsNullOrEmpty(contentLink)) { entryContent = _contentRepository.Service.Get <EntryContentBase>(contentLink); var parentLink = entryContent.GetParentProducts(_relationRepository.Service).SingleOrDefault(); product = _contentRepository.Service.Get <FashionProduct>(parentLink); } } var patchedOrderLine = (PatchedOrderLine)lineItem; if (patchedOrderLine.ProductIdentifiers == null) { patchedOrderLine.ProductIdentifiers = new PatchedProductIdentifiers(); } patchedOrderLine.ProductIdentifiers.Brand = product?.Brand; patchedOrderLine.ProductIdentifiers.GlobalTradeItemNumber = "GlobalTradeItemNumber test"; patchedOrderLine.ProductIdentifiers.ManuFacturerPartNumber = "ManuFacturerPartNumber test"; patchedOrderLine.ProductIdentifiers.CategoryPath = "test / test"; if (checkoutConfiguration.SendProductAndImageUrl && entryContent != null) { ((PatchedOrderLine)lineItem).ProductUrl = SiteUrlHelper.GetAbsoluteUrl() + entryContent.GetUrl(_relationRepository.Service, _urlResolver.Service); } } } }
private static OrderLine GetOrderLine(ILineItem lineItem, bool includeProductAndImageUrl, int unitPrice, int totalAmount, int totalDiscountAmount, int totalTaxAmount, int taxRate) { var orderLine = new PatchedOrderLine { Quantity = (int)lineItem.Quantity, Name = lineItem.DisplayName, Reference = lineItem.Code.Length > 64 ? lineItem.Code.Substring(0, (_maxOrderlineReference - 1)) : lineItem.Code, // can't use more then 64 characters for the order reference Type = "physical" }; if (string.IsNullOrEmpty(orderLine.Name)) { var entry = lineItem.GetEntryContent(); if (entry != null) { orderLine.Name = entry.DisplayName; } } orderLine.UnitPrice = unitPrice; orderLine.TotalAmount = totalAmount; orderLine.TotalDiscountAmount = totalDiscountAmount; orderLine.TotalTaxAmount = totalTaxAmount; orderLine.TaxRate = taxRate; if (includeProductAndImageUrl) { var contentLink = _referenceConverter.Service.GetContentLink(lineItem.Code); if (!ContentReference.IsNullOrEmpty(contentLink)) { orderLine.ProductUrl = SiteUrlHelper.GetAbsoluteUrl() + _urlResolver.Service.GetUrl(contentLink); orderLine.ProductImageUrl = SiteUrlHelper.GetAbsoluteUrl() + GetVariantImage(contentLink); } } return(orderLine); }
public Session Build(Session session, ICart cart, PaymentsConfiguration paymentsConfiguration, IDictionary <string, object> dic = null, bool includePersonalInformation = false) { if (includePersonalInformation && paymentsConfiguration.CustomerPreAssessment) { session.Customer = new Customer { DateOfBirth = "1980-01-01", Gender = "Male", LastFourSsn = "1234" }; } session.MerchantReference2 = "12345"; if (paymentsConfiguration.UseAttachments) { var converter = new IsoDateTimeConverter { DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'" }; var customerAccountInfos = new List <Dictionary <string, object> > { new Dictionary <string, object> { { "unique_account_identifier", "Test Testperson" }, { "account_registration_date", DateTime.Now }, { "account_last_modified", DateTime.Now } } }; var emd = new Dictionary <string, object> { { "customer_account_info", customerAccountInfos } }; session.Attachment = new Attachment { ContentType = "application/vnd.klarna.internal.emd-v2+json", Body = JsonConvert.SerializeObject(emd, converter) }; } if (session.OrderLines != null) { foreach (var lineItem in session.OrderLines) { if (lineItem.Type.Equals("physical")) { EntryContentBase entryContent = null; FashionProduct product = null; if (!string.IsNullOrEmpty(lineItem.Reference)) { var contentLink = _referenceConverter.Service.GetContentLink(lineItem.Reference); if (!ContentReference.IsNullOrEmpty(contentLink)) { entryContent = _contentRepository.Service.Get <EntryContentBase>(contentLink); var parentLink = entryContent.GetParentProducts(_relationRepository.Service).SingleOrDefault(); product = _contentRepository.Service.Get <FashionProduct>(parentLink); } } var patchedOrderLine = (PatchedOrderLine)lineItem; if (patchedOrderLine.ProductIdentifiers == null) { patchedOrderLine.ProductIdentifiers = new PatchedProductIdentifiers(); } patchedOrderLine.ProductIdentifiers.Brand = product?.Brand; patchedOrderLine.ProductIdentifiers.GlobalTradeItemNumber = "GlobalTradeItemNumber test"; patchedOrderLine.ProductIdentifiers.ManuFacturerPartNumber = "ManuFacturerPartNumber test"; patchedOrderLine.ProductIdentifiers.CategoryPath = "test / test"; if (paymentsConfiguration.SendProductAndImageUrlField && entryContent != null) { ((PatchedOrderLine)lineItem).ProductUrl = SiteUrlHelper.GetAbsoluteUrl() + entryContent.GetUrl(_linksRepository.Service, _urlResolver.Service); } } } } return(session); }
public static Uri GetSiteUrl(this ICart cart) { var url = cart.Properties[Constants.KlarnaSiteUrlCartField]?.ToString() ?? string.Empty; return(Uri.TryCreate(url, UriKind.Absolute, out var uri) ? uri : SiteUrlHelper.GetCurrentSiteUrl()); }