public async Task <string> GetHiresPdfLink(string orderId, int line) { var order = await orderViewClient.GetOrderByOrderId(orderId); if (!order.Success || order.Payload == null) { logger.LogError("GetHiresPdfLink", $"Failed to call OrderView microservice. {order.ErrorMessages}"); return(documents.GetDocumentAbsoluteUrl(resources.GetSettingsKey("KDA_HiresPdfLinkFail"))); } var fileKey = order.Payload.Items?.FirstOrDefault(i => i.LineNumber == line)?.FileKey; if (string.IsNullOrEmpty(fileKey)) { logger.LogError("GetHiresPdfLink", $"Order doesn't contain line #{line} with valid FileKey"); return(GetCustomizedFailUrl(order.Payload.SiteId)); } var linkResult = await fileClient.GetShortliveSecureLink(fileKey); if (!linkResult.Success || string.IsNullOrEmpty(linkResult.Payload)) { logger.LogError("GetHiresPdfLink", $"Failed to call File microservice. {order.ErrorMessages}"); return(GetCustomizedFailUrl(order.Payload.SiteId)); } return(linkResult.Payload); }
private async Task <OrderListDto> GetOrders(int pageNumber) { var siteName = _site.GetKenticoSite().Name; BaseResponseDto <OrderListDto> response = null; if (_permissions.IsAuthorizedPerResource("Kadena_Orders", "KDA_SeeAllOrders", siteName)) { response = await _orderClient.GetOrders(siteName, pageNumber, _pageCapacity); } else { var customer = _kenticoUsers.GetCurrentCustomer(); response = await _orderClient.GetOrders(customer?.Id ?? 0, pageNumber, _pageCapacity); } if (response?.Success ?? false) { return(response.Payload); } else { _logger.LogError("OrderListService - GetOrders", response?.Error?.Message); return(new OrderListDto()); } }
public async Task <bool> UpdateTemplate(Guid templateId, string name, int quantity) { var meta = new Dictionary <string, object> { { nameof(TemplateMetaData.quantity), quantity } }; var result = await _templateClient.UpdateTemplate(templateId, name, meta); if (!result.Success) { _logger.LogError("Template set name", result.ErrorMessages); } return(result.Success); }
/// <summary> /// Service for handling SaveToken request from 3DSi /// </summary> public async Task <bool> SaveToken(SaveTokenData tokenData) { if (tokenData == null || tokenData.Approved == 0) { logger.LogError("3DSi SaveToken", "Empty or not approved token data received from 3DSi"); return(false); } var submission = submissionService.GetSubmission(tokenData.SubmissionID); if (submission == null || !submission.AlreadyVerified) { logger.LogError("3DSi SaveToken", $"Unknown or already used submissionId : {tokenData.SubmissionID}"); return(false); } logger.LogInfo("3DSi SaveToken", "Info", $"Received SaveTokenData request, status: " + tokenData?.SubmissionStatusMessage); var tokenId = await SaveTokenToUserData(submission.UserId.ToString(), tokenData); if (string.IsNullOrEmpty(tokenId)) { MarkSubmissionProcessed(submission, false, string.Empty); return(false); } var orderData = JsonConvert.DeserializeObject <OrderDTO>(submission.OrderJson, SerializerConfig.CamelCaseSerializer); orderData.PaymentOption.TokenId = tokenId; orderData.PaymentOption.PaymentGatewayCustomerCode = resources.GetSettingsKey("KDA_CreditCard_Code"); var sendOrderResult = await sendOrder.SubmitOrderData(orderData); if (!(sendOrderResult?.Success ?? false)) { MarkSubmissionProcessed(submission, false, sendOrderResult?.Payload); logger.LogError("PayOrderByCard", "Failed to save order to microservice. " + sendOrderResult?.Error?.Message); return(false); } logger.LogInfo("PayOrderByCard", "info", $"Order #{sendOrderResult.Payload} was saved into microservice"); var orderSuccess = ClearKenticoShoppingCart(submission.UserId, submission.SiteId); MarkSubmissionProcessed(submission, orderSuccess, sendOrderResult?.Payload); return(orderSuccess); }
private async Task <decimal> EstimateTotalTax(string serviceEndpoint, TaxCalculatorRequestDto taxRequest) { if (taxRequest.TotalBasePrice == 0.0d && taxRequest.ShipCost == 0.0d) { // no need for tax estimation return(0.0m); } var cacheKey = $"DeliveryPriceEstimationClient|{serviceEndpoint}|{Newtonsoft.Json.JsonConvert.SerializeObject(taxRequest)}"; var cachedResult = cache.Get(cacheKey); if (cachedResult != null) { return((decimal)cachedResult); } var response = await taxCalculator.CalculateTax(taxRequest); if (response.Success) { var result = response.Payload; cache.Insert(cacheKey, result); return(result); } else { kenticoLog.LogError("TaxCalculatorClient", $"Call for tax estimation to service URL '{serviceEndpoint}' resulted with error {response.Error?.Message ?? string.Empty}"); return(0.0m); } }
public async Task <string> GetUrlFromS3(string key) { var linkResult = await _fileClient.GetShortliveSecureLink(key); if (!linkResult.Success || string.IsNullOrEmpty(linkResult.Payload)) { _logger.LogError("GetUrlFromS3", "Failed to get link for file from S3."); return(null); } return(linkResult.Payload); }
private async Task <Guid> CallRunGeneratePdfTask(CartItem cartItem) { var response = await templateService.RunGeneratePdfTask(cartItem.EditorTemplateId.ToString(), cartItem.ProductChiliPdfGeneratorSettingsId.ToString()); if (response.Success && response.Payload != null) { return(new Guid(response.Payload.TaskId)); } else { kenticoLog.LogError($"Call run generate PDF task", $"Template service client with templateId = {cartItem.EditorTemplateId} and settingsId = {cartItem.ProductChiliPdfGeneratorSettingsId}" + response?.Error?.Message ?? string.Empty); } return(Guid.Empty); }
private async Task <string> UpdateSiteProducts(string customerErpId) { var products = await microserviceInventory.GetInventoryItems(customerErpId).ConfigureAwait(false); if (!products.Success) { kenticoLog.LogError("UpdateInventory", products.ErrorMessages); return(products.ErrorMessages); } if (products.Payload == null || products.Payload.Length == 0) { return($"Customer with ErpId {customerErpId} done, but no products data were received from microservice and updated"); } foreach (var product in products.Payload.Where(p => p.ClientId == customerErpId)) { productsProvider.SetSkuAvailableQty(product.Id, (int)product.AvailableQty); } return($"Customer with ErpId {customerErpId} done successfully"); }
public async Task <SubmitOrderResult> SubmitOrderData(OrderDTO orderData) { if ((orderData?.Items?.Count() ?? 0) <= 0) { throw new ArgumentOutOfRangeException("Items", "Cannot submit order without items"); } var serviceResultDto = await orderClient.SubmitOrder(orderData); var serviceResult = mapper.Map <SubmitOrderResult>(serviceResultDto); if (serviceResult.Success) { log.LogInfo("Submit order", "INFORMATION", $"Order {serviceResult.Payload} successfully created"); } else { log.LogError("Submit order", $"Order {serviceResult?.Payload} error. {serviceResult?.Error?.Message}"); } return(serviceResult); }
public async Task <OrderDetail> GetOrderDetail(string orderId) { CheckOrderDetailPermisson(orderId, kenticoUsers.GetCurrentCustomer()); var microserviceResponse = await orderViewClient.GetOrderByOrderId(orderId); if (!microserviceResponse.Success || microserviceResponse.Payload == null) { kenticoLog.LogError("GetOrderDetail", microserviceResponse.ErrorMessages); throw new Exception("Failed to obtain order detail from microservice"); // TODO refactor using checking null } var data = microserviceResponse.Payload; var genericStatus = kenticoOrder.MapOrderStatus(data.Status); var orderDetail = new OrderDetail() { DateTimeNAString = resources.GetResourceString("Kadena.Order.ItemShippingDateNA"), CommonInfo = new CommonInfo() { OrderDate = new TitleValuePair <DateTime> { Title = resources.GetResourceString("Kadena.Order.OrderDateTitle"), Value = data.OrderDate }, ShippingDate = new TitleValuePair <DateTime?> { Title = resources.GetResourceString("Kadena.Order.ShippingDatePrefix"), Value = data.ShippingInfo?.ShippingDate }, Status = new TitleValuePair <string> { Title = resources.GetResourceString("Kadena.Order.StatusPrefix"), Value = genericStatus }, TotalCost = new TitleValuePair <string> { Title = resources.GetResourceString("Kadena.Order.TotalCostPrefix"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Summary + data.PaymentInfo.Shipping + data.PaymentInfo.Tax) } }, PaymentInfo = new PaymentInfo() { Date = null, // TODO payment date unknown yet PaidBy = data.PaymentInfo.PaymentMethod, PaymentDetail = string.Empty, PaymentIcon = GetPaymentMethodIcon(data.PaymentInfo.PaymentMethod), Title = resources.GetResourceString("Kadena.Order.PaymentSection"), DatePrefix = resources.GetResourceString("Kadena.Order.PaymentDatePrefix"), BUnitLabel = resources.GetResourceString("Kadena.Order.BusinessUnitLabel"), BUnitName = businessUnits.GetDistributorBusinessUnit(data.campaign != null ? data.campaign.DistributorID : 0) }, PricingInfo = new PricingInfo() { Title = resources.GetResourceString("Kadena.Order.PricingSection"), Items = new List <PricingInfoItem>() { new PricingInfoItem() { Title = resources.GetResourceString("Kadena.Order.PricingSummary"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Summary) }, new PricingInfoItem() { Title = resources.GetResourceString("Kadena.Order.PricingShipping"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Shipping) }, new PricingInfoItem() { Title = resources.GetResourceString("Kadena.Order.PricingSubtotal"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Summary + data.PaymentInfo.Shipping) }, new PricingInfoItem() { Title = resources.GetResourceString("Kadena.Order.PricingTax"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Tax) }, new PricingInfoItem() { Title = resources.GetResourceString("Kadena.Order.PricingTotals"), Value = String.Format("$ {0:#,0.00}", data.PaymentInfo.Summary + data.PaymentInfo.Shipping + data.PaymentInfo.Tax) } } }, OrderedItems = new OrderedItems() { Title = resources.GetResourceString("Kadena.Order.OrderedItemsSection"), Items = await MapOrderedItems(data.Items) } }; var mailingTypeCode = OrderItemTypeDTO.Mailing.ToString(); var hasOnlyMailingListProducts = data.Items.All(item => item.Type == mailingTypeCode); if (hasOnlyMailingListProducts) { orderDetail.ShippingInfo = new ShippingInfo { Title = resources.GetResourceString("Kadena.Order.ShippingSection"), Message = resources.GetResourceString("Kadena.Checkout.UndeliverableText") }; } else { orderDetail.ShippingInfo = new ShippingInfo { Title = resources.GetResourceString("Kadena.Order.ShippingSection"), DeliveryMethod = shoppingCart.GetShippingProviderIcon(data.ShippingInfo.Provider), Address = mapper.Map <DeliveryAddress>(data.ShippingInfo.AddressTo), Tracking = null // TODO Track your package url unknown }; orderDetail.ShippingInfo.Address.Country = localization .GetCountries() .FirstOrDefault(s => s.Code.Equals(data.ShippingInfo.AddressTo.isoCountryCode)); } if (!permissions.UserCanSeePrices()) { orderDetail.HidePrices(); } return(orderDetail); }