Ejemplo n.º 1
0
        /// <summary>
        /// Check balance button event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkBalanceBtn_Click(object sender, EventArgs e)
        {
            try
            {
                lblAvailableBalanceAmt.Text     = string.Empty;
                lblApplyBalanceError.Text       = string.Empty;
                lblEmptyCardNumberError.Visible = false;

                if (string.IsNullOrWhiteSpace(txtGiftCardNumber.Text))
                {
                    lblEmptyCardNumberError.Visible = true;
                    lblEmptyCardNumberError.Text    = "Please enter gift card number.";
                }
                else
                {
                    try
                    {
                        FinancialCard financialCardHelper = new FinancialCard(txtGiftCardNumber.Text);
                        txtGiftCardNumber.Text = financialCardHelper.CardNumber;
                    }
                    catch (Exception ex)
                    {
                        _logger.WriteLogError(ex, "FinancialCard for swap GiftCard Tender");
                    }
                    GetGiftCardBalance();
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "bLoyal Gift Card checkBalanceBtn_Click");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Apply button click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void applyBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(txtGiftCardNumber.Text))
                {
                    int tenderId = 0;
                    var tenders  = TendersCache.Tenders;

                    if (tenders != null && tenders.Any())
                    {
                        var getGiftCardTender = tenders.ToList().Find(t => t.TenderTypeName.Equals(_conFigHelper.DW_GIFTCARD_TENDER_NAME, StringComparison.CurrentCultureIgnoreCase));
                        if (getGiftCardTender != null && !string.IsNullOrWhiteSpace(getGiftCardTender.ID))
                        {
                            int.TryParse(getGiftCardTender.ID, out tenderId);
                        }
                    }
                    if (tenderId != 0)
                    {
                        decimal applyBalanceAmt = 0;
                        decimal.TryParse(textApplyBalance.Text, out applyBalanceAmt);

                        try
                        {
                            FinancialCard financialCardHelper = new FinancialCard(txtGiftCardNumber.Text);
                            txtGiftCardNumber.Text = financialCardHelper.CardNumber;
                        }
                        catch (Exception ex)
                        {
                            _logger.WriteLogError(ex, "applyBtn_Click error for Swap GiftCard");
                        }

                        var cardResponse = GetGiftCardBalance(false);
                        lblEmptyCardNumberError.Visible = false;
                        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";
                            lblApplyBalanceError.Text   = cardResponse.Message;
                        }
                        else if (cardResponse.Status == PaymentEngine.CardRequestStatus.Declined)
                        {
                            lblAvailableBalance.Visible = false;
                            lblAvailableBalanceAmt.Text = "0";
                            lblApplyBalanceError.Text   = cardResponse.Message;
                        }
                        else if (applyBalanceAmt <= 0)
                        {
                            lblApplyBalanceError.Text = "Please enter an amount greater than 0.";
                        }
                        else if (_ticketAmountDue == 0)
                        {
                            var ticketMenuItems = _dinerwareProvider.GetTicketMenuItems(_currentUserId, _currentOpenTicketId);
                            lblApplyBalanceError.Text = ticketMenuItems != null && ticketMenuItems.Count() > 0 ? "Amount due on this ticket is $0." : "Please add at least 1 item to apply Gift Card tender.";
                        }
                        else if (applyBalanceAmt > _ticketAmountDue)
                        {
                            lblApplyBalanceError.Text = "Entered amount exceeds ticket amount due of $" + Math.Round(_ticketAmountDue, 2);
                        }
                        else if (((_availableBalance >= applyBalanceAmt) || _availableBalance <= _ticketAmountDue))
                        {
                            if (AddTransactionToTicket(tenderId, _availableBalance >= applyBalanceAmt ? applyBalanceAmt : _availableBalance))
                            {
                                bLoyalGiftCardTenderExtension.currentOpenTicketId = string.Empty;
                                this.Close();
                            }
                            else
                            {
                                lblApplyBalanceError.Text = Messages.SERVICE_UNAVAILBLE_WARNING;
                            }
                        }
                    }
                    else
                    {
                        //bLoyal GiftCard Tenders not find in Dinerware
                        this.Hide();
                        frmTenderNotFoundWarning show = new frmTenderNotFoundWarning(Messages.GC_TENDER_NOT_CONFIGURED);
                        show.ShowDialog();
                        this.Close();
                    }
                }
                else
                {
                    lblEmptyCardNumberError.Visible = true;
                    lblEmptyCardNumberError.Text    = "Please enter gift card number.";
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "bLoyal Gift Card applyBtn_Click");
            }
        }
        /// <summary>
        /// Apply Load GiftCard Item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void applyBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(txtGiftCardNumber.Text))
                {
                    lblEmptyCardNumberError.Visible = true;
                    lblEmptyCardNumberError.Text    = "Please enter gift card number.";
                }
                else
                {
                    try
                    {
                        FinancialCard financialCardHelper = new FinancialCard(txtGiftCardNumber.Text);
                        txtGiftCardNumber.Text = financialCardHelper.CardNumber;
                    }
                    catch (Exception ex)
                    {
                        _logger.WriteLogError(ex, "FinancialCard for swap Load GiftCard");
                    }

                    lblEmptyCardNumberError.Visible = false;
                    if (!string.IsNullOrWhiteSpace(txtGiftCardNumber.Text))
                    {
                        CalculateTransactionHelper transaction = new CalculateTransactionHelper();

                        string checkLoadGiftCrad = transaction.CheckLoadGiftCard(txtGiftCardNumber.Text);

                        if (!string.IsNullOrWhiteSpace(checkLoadGiftCrad))
                        {
                            this.Hide();
                            frmLoadGiftCardWarning loadGiftCardWarning = new frmLoadGiftCardWarning(checkLoadGiftCrad);
                            loadGiftCardWarning.ShowDialog();
                            this.Show();
                        }
                        else
                        {
                            CalculateCartCommand request = null;
                            if (_calculatedCart != null && _calculatedCart.Cart != null && _calculatedCart.Cart.Lines != null && _calculatedCart.Cart.Lines.Any())
                            {
                                var line = _calculatedCart.Cart.Lines.ToList().Find(t => t.ProductName.Equals(_loadGiftItem, StringComparison.InvariantCultureIgnoreCase) && t.ProductExternalId.Equals(_loadMenuItem.TIID));
                                if (line != null)
                                {
                                    line.GiftCardNumber = txtGiftCardNumber.Text;
                                    _giftCardNumber     = txtGiftCardNumber.Text;
                                }
                                else
                                {
                                    var newline = new CartLine {
                                        ProductName = _loadMenuItem.ItemName, ProductCode = _loadMenuItem.ID, GiftCardNumber = txtGiftCardNumber.Text, Price = _loadMenuItem.Price / _loadMenuItem.Quantity, Quantity = _loadMenuItem.Quantity, ExternalId = _loadMenuItem.ID, ProductExternalId = _loadMenuItem.TIID
                                    };
                                    _calculatedCart.Cart.Lines.Add(newline);
                                }
                                request = new CalculateCartCommand()
                                {
                                    Cart = _calculatedCart.Cart,
                                    Uid  = _calculatedCart.Cart.Uid
                                };
                            }
                            else
                            {
                                var cart = new Cart {
                                    Lines = new List <CartLine>(), SourceExternalId = _currentOpenTicketId.ToString()
                                };
                                var cartLineHelper = new CartLineHelper();

                                var lines = cartLineHelper.GetCartLines(_ticket);

                                if (lines != null && lines.Any())
                                {
                                    var line = lines.ToList().Find(t => t.ProductName.Equals(_loadGiftItem, StringComparison.InvariantCultureIgnoreCase) && t.ProductExternalId.Equals(_loadMenuItem.TIID));
                                    if (line != null)
                                    {
                                        line.GiftCardNumber = txtGiftCardNumber.Text;
                                        _giftCardNumber     = txtGiftCardNumber.Text;
                                    }
                                    cart.Lines = lines;
                                    request    = new CalculateCartCommand()
                                    {
                                        Cart = cart
                                    };
                                }
                            }

                            if (request != null)
                            {
                                _services.CalculateCart(request);
                            }

                            this.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "bLoyal Load GiftCard applyBtn_Click");
            }
        }