/// <summary> /// ApproveCartAsync /// </summary> /// <param name="approveCommand"></param> /// <returns></returns> public async Task <CartApproval> ApproveCartAsync(ApproveCartCommand approveCommand) { try { CartApproval cartApproval = null; cartApproval = await _service.CartResource.ApproveAsync(approveCommand).ConfigureAwait(true); return(cartApproval); } catch (ApiException ex) { if (ex != null && !string.IsNullOrWhiteSpace(ex.Code) && ex.Code == "ServiceRedirect") { ServiceURLHelper.IsbLoyalServiceUrlDown = true; apiException = new APIExceptions { ErrorCode = ex.Code, ErrorDescription = "A bLoyal error occurred. Please restart your Workstation and try again.", ErrorApi = "ApproveAsync" }; } _logger.WriteLogError(ex, "LoyaltyEngineServices ApproveCartAsync"); return(null); } catch (Exception ex) { _logger.WriteLogError(ex, "LoyaltyEngineServices ApproveCartAsync"); return(null); } }
/// <summary> /// EnterPaymentWindow for PaymentWindow - event /// </summary> /// <param name="theInfo"></param> /// <param name="theTicket"></param> public void enterPaymentWindow(IDisplayActions.displayActionInfo theInfo, Ticket theTicket) { try { if (!ConfigurationHelper.Instance.IS_Test_Virtual_Client_Connection || !ConfigurationHelper.Instance.IS_Test_BLoyal_Connection) { return; } if (_configurationHelper != null && _configurationHelper.ENABLE_bLOYAL && theTicket != null && theTicket.Items != null && theTicket.Items.Any()) { RefreshTicket(theTicket); if (theTicket != null) { var services = new LoyaltyEngineServices(); if (_configurationHelper.LOAD_GIFTCARD_ITEMS != null && _configurationHelper.LOAD_GIFTCARD_ITEMS.Any()) { var loadGiftCardItems = _configurationHelper.LOAD_GIFTCARD_ITEMS.Where(p => theTicket.Items.Any(p2 => p2.ItemName.Equals(p, StringComparison.InvariantCultureIgnoreCase))); if (loadGiftCardItems != null && loadGiftCardItems.Any()) { foreach (var loadGiftItem in loadGiftCardItems) { var loadGiftCardMenuItems = theTicket.Items.ToList().FindAll(t => t.ItemName.Equals(loadGiftItem, StringComparison.InvariantCultureIgnoreCase)); if (loadGiftCardMenuItems != null) { foreach (var loadItem in loadGiftCardMenuItems) { var calculatedCart = AsyncHelper.RunSync(() => services.GetCartBySourceExternalIdAsync(theTicket.ID)); CartLine giftCartLine = null; if (calculatedCart != null && calculatedCart.Cart != null && calculatedCart.Cart.Lines != null && calculatedCart.Cart.Lines.Any()) { giftCartLine = calculatedCart.Cart.Lines.FirstOrDefault(t => t.ProductName.Equals(loadGiftItem, StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrWhiteSpace(t.GiftCardNumber) && !string.IsNullOrWhiteSpace(t.ProductExternalId) && t.ProductExternalId.Equals(loadItem.TIID)); } if (giftCartLine == null || string.IsNullOrWhiteSpace(giftCartLine.GiftCardNumber)) { frmLoadGiftCardBalance loadGiftCardBalance = new frmLoadGiftCardBalance(_ticketId, string.Empty, _targetTicket, loadItem, calculatedCart, loadGiftItem); loadGiftCardBalance.ShowDialog(); loadGiftCardBalance.CheckCardNumber(); } } } } } } if (TicketDictionary.Dictionary != null && TicketDictionary.Dictionary.ContainsKey(_ticketId)) { if (TicketDictionary.Dictionary[_ticketId] == Constants.CALCULATEDCURRENT && TicketDictionary.CartDictionary != null && TicketDictionary.CartDictionary.ContainsKey(_ticketId) && TicketDictionary.CartDictionary[_ticketId] != null) { var approveCartCommand = new ApproveCartCommand { CartUid = TicketDictionary.CartDictionary[_ticketId], CartSourceExternalId = _ticketId.ToString(), ReferenceNumber = _ticketId.ToString() }; CartApproval cartApproval = AsyncHelper.RunSync(() => services.ApproveCartAsync(approveCartCommand)); if (cartApproval != null && cartApproval.Alerts != null && cartApproval.Alerts.Count > 0) { foreach (var alert in cartApproval.Alerts) { if (alert.Uid != null && alert.Uid != Guid.Empty && !string.IsNullOrWhiteSpace(alert.SnippetUrl)) { frmAlerts frmAlert = new frmAlerts(TicketDictionary.CartDictionary[_ticketId].ToString(), alert.Uid.ToString(), alert.SnippetUrl); frmAlert.ShowDialog(); } } } } else if (_configurationHelper.IS_CALCULATE_DISCOUNT_WARNING) { frmTicketMsgForm discountWarning = new frmTicketMsgForm(theInfo.userID, _ticketId); discountWarning.ShowDialog(); } } } } } catch (Exception ex) { _loggerHelper.WriteLogError(ex, "enterPaymentWindow"); } }