/// <summary>
        /// Check Load Gift Card
        /// </summary>
        /// <param name="giftCardNumber"></param>
        /// <returns></returns>
        public string CheckLoadGiftCard(string giftCardNumber)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(_configurationHelper.GIFTCARD_TENDER_CODE) && !string.IsNullOrWhiteSpace(_configurationHelper.GIFTCARD_SKU))
                {
                    _paymentEngine = new PaymentEngineConnector(_configurationHelper.LOGIN_DOMAIN, _configurationHelper.ACCESS_KEY, string.Empty, string.Empty, null);

                    var cardResponse = _paymentEngine.GetCardBalance(giftCardNumber, _configurationHelper.GIFTCARD_TENDER_CODE);
                    if (cardResponse != null)
                    {
                        if (cardResponse.AvailableBalance > 0)
                        {
                            var msg = new frmGiftCardExistsMsg(giftCardNumber);
                            msg.ShowDialog();
                        }

                        if (cardResponse.Status == PaymentEngine.CardRequestStatus.Approved && !string.IsNullOrWhiteSpace(cardResponse.Message) && (cardResponse.Message.StartsWith("Current balance is") || cardResponse.Message.StartsWith("Gift card is not provisioned - number is auto provisioned enabled")))
                        {
                            return(string.Empty);
                        }
                        else if (cardResponse.Status == PaymentEngine.CardRequestStatus.Declined)
                        {
                            return(cardResponse.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "CalculateTransaction CheckLoadGiftCard");
            }
            return(string.Empty);
        }
        /// <summary>
        /// Apply Loyalty Tender
        /// </summary>
        /// <param name="tenderId"></param>
        /// <param name="applyBalance"></param>
        private void ApplyLoyaltyTender(int tenderId, decimal applyBalance)
        {
            try
            {
                _paymentEngine = new PaymentEngineConnector(_conFigHelper.LOGIN_DOMAIN, _conFigHelper.ACCESS_KEY, string.Empty, string.Empty, null);

                _transactionCode = _paymentEngine.CardRedeem(string.Empty, _conFigHelper.LOYALTY_TENDER_CODE, _cartExternalId, applyBalance, _customer.Uid);

                if (!string.IsNullOrWhiteSpace(_transactionCode))
                {
                    _applyAmount = applyBalance;

                    var response = _dwProvider.AddTransactionToTicket(_currentUserId, _currentOpenTicketId, new wsTransaction
                    {
                        PaymentAmount = applyBalance,
                        TenderType    = Constants.BLOYALLOYALTYTENDER,
                        TenderTypeID  = tenderId,
                        RefNumber     = _transactionCode
                    });

                    if (response.Result == TicketChangeResult.Success)
                    {
                        this.Close();
                    }
                }
                lblApplyBalanceError.Text = Messages.SERVICE_UNAVAILBLE_WARNING;
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "ApplyLoyaltyTender");
            }
        }
        /// <summary>
        /// Refund bLoyal Tenders
        /// </summary>
        /// <param name="ticketId"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public async Task <bool> RefundbLoyalTendersAsync(int ticketId, decimal amount)
        {
            bool isCreditbLoyalTendersError = false;

            try
            {
                var ticketTransactions = _dinerwareProvider.GetTransForTicket(ticketId, true); // Updated tenders information not getting by cache - So we need to call Dinerware API

                bool refundPayment = true;

                if (ticketTransactions != null && ticketTransactions.Any())
                {
                    foreach (var payment in ticketTransactions)
                    {
                        if (refundPayment)
                        {
                            if ((payment.Type.Equals(_configurationHelper.DW_GIFTCARD_TENDER_NAME, StringComparison.CurrentCultureIgnoreCase) ||
                                 (payment.Type.Equals(_configurationHelper.DW_LOYALTY_TENDER_NAME, StringComparison.CurrentCultureIgnoreCase)) &&
                                 payment.IsCanceled && amount == payment.NetAmount))
                            {
                                _paymentEngine = new PaymentEngineConnector(_configurationHelper.LOGIN_DOMAIN, _configurationHelper.ACCESS_KEY, string.Empty, string.Empty, null);

                                refundPayment = await PaymentRefundAsync(ticketId, amount, refundPayment, payment).ConfigureAwait(true);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                isCreditbLoyalTendersError = true;
                _logger.WriteLogError(ex, "Refund bLoyal Tenders - CreditbLoyalTenders");
            }
            return(isCreditbLoyalTendersError);
        }
        /// <summary>
        /// Get Load GiftCard Balance
        /// </summary>
        /// <param name="ticketId"></param>
        /// <param name="giftCardNumber"></param>
        /// <param name="currentUserId"></param>
        /// <returns></returns>
        public List <ApplyGiftCardSummary> ApplyLoadGiftCardBalance(int ticketId, int currentUserId)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(_configurationHelper.GIFTCARD_TENDER_CODE) && _configurationHelper.LOAD_GIFTCARD_ITEMS != null && _configurationHelper.LOAD_GIFTCARD_ITEMS.Any())
                {
                    bool isCalculateCartUpdate = false;
                    var  applyGiftCardSummary  = new List <ApplyGiftCardSummary>();
                    var  calculatedCart        = AsyncHelper.RunSync(() => _services.GetCartBySourceExternalIdAsync(ticketId.ToString()));

                    if (calculatedCart != null && calculatedCart.Cart != null && calculatedCart.Cart.Lines != null)
                    {
                        foreach (var cartLine in calculatedCart.Cart.Lines)
                        {
                            decimal giftCardAmount = cartLine.GiftCardAmount.HasValue ? cartLine.GiftCardAmount.Value : 0;
                            if (!string.IsNullOrWhiteSpace(cartLine.GiftCardNumber) && giftCardAmount == 0)
                            {
                                decimal loadGiftCardAmount = (cartLine.Price * cartLine.Quantity) - (cartLine.Discount > 0 ? cartLine.Discount * cartLine.Quantity : 0);

                                _paymentEngine = new PaymentEngineConnector(_configurationHelper.LOGIN_DOMAIN, _configurationHelper.ACCESS_KEY, string.Empty, string.Empty, null);

                                var cardResponse = _paymentEngine.GetCardBalance(cartLine.GiftCardNumber, _configurationHelper.GIFTCARD_TENDER_CODE);
                                if (cardResponse != null)
                                {
                                    if (cardResponse.Status == PaymentEngine.CardRequestStatus.Approved && loadGiftCardAmount > 0)
                                    {
                                        string transCode = _paymentEngine.CardCredit(cartLine.GiftCardNumber, _configurationHelper.GIFTCARD_TENDER_CODE, ticketId.ToString(), loadGiftCardAmount);
                                        UpdateCart(loadGiftCardAmount, cartLine, calculatedCart, transCode);
                                        isCalculateCartUpdate = true;
                                        applyGiftCardSummary.Add(new ApplyGiftCardSummary {
                                            GiftCardNumber = cartLine.GiftCardNumber, IsNewCard = cardResponse.AvailableBalance > 0 ? false : true, NetAmount = loadGiftCardAmount, IsProvision = !string.IsNullOrWhiteSpace(cardResponse.Message) && cardResponse.Message.StartsWith("Gift card is not provisioned - number is auto provisioned enabled")
                                        });
                                    }
                                }
                            }
                        }

                        if (calculatedCart != null && isCalculateCartUpdate)
                        {
                            return(UpdateCalculateCart(applyGiftCardSummary, calculatedCart));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "CalculateTransaction ApplyLoadGiftCardBalance");
            }
            return(null);
        }
        /// <summary>
        /// Credit Load GiftCard Item
        /// </summary>
        /// <param name="calculatedCart"></param>
        /// <param name="amount"></param>
        /// <param name="giftCardNumber"></param>
        /// <param name="ticketId"></param>
        /// <returns></returns>
        public bool CreditLoadGiftCardItem(CalculatedCart calculatedCart, decimal amount, string giftCardNumber, string ticketId, CartLine line)
        {
            bool result = false;

            try
            {
                _paymentEngine = new PaymentEngineConnector(_configurationHelper.LOGIN_DOMAIN, _configurationHelper.ACCESS_KEY, string.Empty, string.Empty, null);

                string transCode = _paymentEngine.CardRedeem(giftCardNumber, _configurationHelper.GIFTCARD_TENDER_CODE, ticketId, amount);

                result = !string.IsNullOrWhiteSpace(transCode);
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "CalculateTransaction CreditLoadGiftCardItem");
            }
            return(result);
        }
        /// <summary>
        /// Get Loyalty Balance
        /// </summary>
        /// <returns></returns>
        private void GetLoyaltyBalance()
        {
            try
            {
                _ticketAmountDue = _currentTicket.AmountDue;
                if (_customer != null && _customer.Uid != null && _customer.Uid != Guid.Empty)
                {
                    _paymentEngine = new PaymentEngineConnector(_conFigHelper.LOGIN_DOMAIN, _conFigHelper.ACCESS_KEY, string.Empty, string.Empty, null);

                    var cardResponse = _paymentEngine.GetCardBalance(string.Empty, _conFigHelper.LOYALTY_TENDER_CODE, _customer.Uid);

                    if (cardResponse != null)
                    {
                        if (cardResponse.AvailableBalance != 0)
                        {
                            _availableBalance = Math.Round(cardResponse.AvailableBalance, 2);
                        }

                        var balance = _availableBalance >= _ticketAmountDue?Math.Round(_ticketAmountDue, 2) : Math.Round(_availableBalance, 2);

                        textApplyBalance.Text = _ticketAmountDue == 0 ? "0" : balance.ToString();
                    }
                    else
                    {
                        lblApplyBalanceError.Text = Messages.SERVICE_UNAVAILBLE_WARNING;
                    }
                }
                else if (_ticketAmountDue != 0)
                {
                    lblCustomerNotAssigntoTicket.Enabled = false;
                    lblCustomerNotAssigntoTicket.Visible = true;
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "GetApplyCardBalance");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get Gift Card Balance
        /// </summary>
        private PaymentEngine.CardResponse GetGiftCardBalance(bool isCheckBalance = true)
        {
            var cardResponse = new PaymentEngine.CardResponse();

            try
            {
                GetTicketAmountDue();

                _paymentEngine = new PaymentEngineConnector(_conFigHelper.LOGIN_DOMAIN, _conFigHelper.ACCESS_KEY, string.Empty, string.Empty, null);

                cardResponse = _paymentEngine.GetCardBalance(txtGiftCardNumber.Text, _conFigHelper.GIFTCARD_TENDER_CODE);
                if (cardResponse != null)
                {
                    if (cardResponse.AvailableBalance != 0)
                    {
                        lblAvailableBalance.Visible = true;
                        _availableBalance           = Math.Round(cardResponse.AvailableBalance, 2);
                        if (isCheckBalance)
                        {
                            if (_availableBalance <= _ticketAmountDue)
                            {
                                _ticketAmountDue      = _availableBalance;
                                textApplyBalance.Text = Math.Round(_ticketAmountDue, 2).ToString();
                            }
                            else
                            {
                                textApplyBalance.Text = Math.Round(_ticketAmountDue, 2).ToString();
                            }
                        }
                        _availableBalance = Math.Round(_availableBalance, 2);
                        lblAvailableBalanceAmt.Visible = true;
                        lblAvailableBalanceAmt.Text    = _availableBalance.ToString();
                    }
                    else if (cardResponse.AvailableBalance == 0 &&
                             cardResponse.Status == PaymentEngine.CardRequestStatus.Approved &&
                             !string.IsNullOrWhiteSpace(cardResponse.Message) &&
                             (cardResponse.Message.StartsWith("Current balance is") ||
                              cardResponse.Message.StartsWith("Gift card is not provisioned - number is auto provisioned enabled")))
                    {
                        lblAvailableBalance.Visible = true;
                        lblAvailableBalanceAmt.Text = "0";
                        textApplyBalance.Text       = "0";
                        lblApplyBalanceError.Text   = cardResponse.Message;
                    }
                    else if (cardResponse.Status == PaymentEngine.CardRequestStatus.Declined)
                    {
                        textApplyBalance.Text          = "0";
                        lblAvailableBalance.Visible    = false;
                        lblAvailableBalanceAmt.Visible = false;
                        lblApplyBalanceError.Text      = cardResponse.Message;
                    }
                    else if (cardResponse.AvailableBalance == 0 && cardResponse.Status == PaymentEngine.CardRequestStatus.Approved)
                    {
                        textApplyBalance.Text          = "0";
                        lblAvailableBalance.Visible    = true;
                        lblAvailableBalanceAmt.Visible = true;
                        lblAvailableBalanceAmt.Text    = "0";
                    }
                }
                else
                {
                    lblApplyBalanceError.Text = "Service unavailable. Please try again later.";
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "bLoyal GiftCardTender GetApplyCardBalance");
                frmbLoyalServiceUrlDownWarning frmServiceUrlDown = new frmbLoyalServiceUrlDownWarning();
                frmServiceUrlDown.ShowDialog();
            }
            return(cardResponse);
        }