public void AddLoyaltyPayment(IRetailTransaction retailTransaction, ICardInfo cardInfo, decimal amount) { try { try { NewMessageWindow(50051, LSPosMessageTypeButton.NoButtons, System.Windows.Forms.MessageBoxIcon.Information); this.transaction = (RetailTransaction)retailTransaction; // Getting the loyalty info for the card, how many points have previously been earned LoyaltyItem paymentLoyaltyItem = GetLoyaltyItem(ref cardInfo); if (paymentLoyaltyItem != null) { //customerData. if (this.transaction.Customer == null || string.Equals(this.transaction.Customer.CustomerId, paymentLoyaltyItem.CustID, StringComparison.OrdinalIgnoreCase) == false) { UpdateTransactionWithNewCustomer(paymentLoyaltyItem.CustID); } // if the amount is higher than the "new" NetAmountWithTax, then it is acceptable to lower the amount if (Math.Abs(amount) > Math.Abs(this.transaction.TransSalePmtDiff)) { amount = this.transaction.TransSalePmtDiff; } // Getting all possible loyalty posssiblities for the found scheme id DataTable loyaltyPointsTable = GetLoyaltyPointsSchemeFromDB(paymentLoyaltyItem.SchemeID); decimal totalNumberOfPoints = 0; bool tenderRuleFound = false; // now we add the points needed to pay current tender totalNumberOfPoints = CalculatePointsForTender(ref tenderRuleFound, cardInfo.TenderTypeId, amount, loyaltyPointsTable); if (tenderRuleFound) { bool cardIsValid = false; string comment = string.Empty; int loyaltyTenderTypeBase = 0; decimal pointsEarned = 0; // check to see if the user can afford so many points GetPointStatus(ref pointsEarned, ref cardIsValid, ref comment, ref loyaltyTenderTypeBase, paymentLoyaltyItem.LoyaltyCardNumber); if ((cardIsValid) && ((LoyaltyTenderTypeBase)loyaltyTenderTypeBase != LoyaltyTenderTypeBase.NoTender)) { if (pointsEarned >= (totalNumberOfPoints * -1)) { //customerData. if (this.transaction.Customer == null || string.Equals(this.transaction.Customer.CustomerId, paymentLoyaltyItem.CustID, StringComparison.OrdinalIgnoreCase) == false) { UpdateTransactionWithNewCustomer(paymentLoyaltyItem.CustID); } //Add loyalty item to transaction. this.transaction.LoyaltyItem = paymentLoyaltyItem; this.transaction.LoyaltyItem.UsageType = LoyaltyItemUsageType.UsedForLoyaltyTender; // Gathering tender information TenderData tenderData = new TenderData(ApplicationSettings.Database.LocalConnection, ApplicationSettings.Database.DATAAREAID); ITender tenderInfo = tenderData.GetTender(cardInfo.TenderTypeId, ApplicationSettings.Terminal.StoreId); // this is the grand total decimal totalAmountDue = this.transaction.TransSalePmtDiff - amount; TenderRequirement tenderRequirement = new TenderRequirement((Tender)tenderInfo, amount, true, this.transaction.TransSalePmtDiff); if (!string.IsNullOrWhiteSpace(tenderRequirement.ErrorText)) { using (LSRetailPosis.POSProcesses.frmMessage dialog = new LSRetailPosis.POSProcesses.frmMessage(tenderRequirement.ErrorText, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error)) { LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog); } } //Add a loyalty tender item to transaction. LoyaltyTenderLineItem loyaltyTenderItem = (LoyaltyTenderLineItem)this.Application.BusinessLogic.Utility.CreateLoyaltyTenderLineItem(); loyaltyTenderItem.CardNumber = paymentLoyaltyItem.LoyaltyCardNumber; loyaltyTenderItem.CardTypeId = cardInfo.CardTypeId; loyaltyTenderItem.Amount = amount; //tenderInfo. loyaltyTenderItem.Description = tenderInfo.TenderName; loyaltyTenderItem.TenderTypeId = cardInfo.TenderTypeId; loyaltyTenderItem.LoyaltyPoints = totalNumberOfPoints; //convert from the store-currency to the company-currency... loyaltyTenderItem.CompanyCurrencyAmount = this.Application.Services.Currency.CurrencyToCurrency( ApplicationSettings.Terminal.StoreCurrency, ApplicationSettings.Terminal.CompanyCurrency, amount); // the exchange rate between the store amount(not the paid amount) and the company currency loyaltyTenderItem.ExchrateMST = this.Application.Services.Currency.ExchangeRate( ApplicationSettings.Terminal.StoreCurrency) * 100; // card tender processing and printing require an EFTInfo object to be attached. // however, we don't want loyalty info to show up where other EFT card info would on the receipt // because loyalty has its own receipt template fields, so we just assign empty EFTInfo object loyaltyTenderItem.EFTInfo = Application.BusinessLogic.Utility.CreateEFTInfo(); // we don't want Loyalty to be 'captured' by payment service, so explicitly set not to capture to be safe loyaltyTenderItem.EFTInfo.IsPendingCapture = false; loyaltyTenderItem.SignatureData = LSRetailPosis.POSProcesses.TenderOperation.ProcessSignatureCapture(tenderInfo, loyaltyTenderItem); this.transaction.Add(loyaltyTenderItem); } else { using (LSRetailPosis.POSProcesses.frmMessage dialog = new LSRetailPosis.POSProcesses.frmMessage(50057, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error)) { LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog); } // Not enough points available to complete payment } } else { LSRetailPosis.POSProcesses.frmMessage dialog = null; try { if (string.IsNullOrEmpty(comment)) { dialog = new LSRetailPosis.POSProcesses.frmMessage(50058, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } else { dialog = new LSRetailPosis.POSProcesses.frmMessage(comment, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog); // Invalid loyaltycard } finally { if (dialog != null) { dialog.Dispose(); } } } } else { using (LSRetailPosis.POSProcesses.frmMessage dialog = new LSRetailPosis.POSProcesses.frmMessage(50059, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error)) { LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog); // Not enough points available to complete payment } } } } finally { CloseExistingMessageWindow(); } } catch (Exception ex) { NetTracer.Error(ex, "Loyalty::AddLoyaltyPayment failed for retailTransaction {0} cardInfo {1} amount {2}", retailTransaction.TransactionId, cardInfo.CardNumber, amount); LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), ex); throw; } }
private void AddCorporateCardTenderLine() { try { LogMessage("Adding the tender line to the transaction", LSRetailPosis.LogTraceLevel.Trace, "CorporateCard.AddCorporateCardTenderLine"); bool getAdditionalInfo = false; // Generate the tender line for the card CorporateCardTenderLineItem cardTenderLine = (CorporateCardTenderLineItem)this.Application.BusinessLogic.Utility.CreateCorporateCardTenderLineItem(); cardTenderLine.TenderTypeId = iCardInfo.TenderTypeId; cardTenderLine.CardName = iCardInfo.CardName; cardTenderLine.Description = LSRetailPosis.ApplicationLocalizer.Language.Translate(50150) + " " + iCardInfo.CardName; //Card payment cardTenderLine.Amount = this.amountValue; if (iCardInfo.CardEntryType == CardEntryTypes.MAGNETIC_STRIPE_READ) { // We have the track, from which we need to get the card number and exp date string track2Data = LSRetailPosis.Settings.HardwareProfiles.MSR.Track2Data(iCardInfo.Track2); cardTenderLine.CardNumber = track2Data.Substring(0, track2Data.IndexOf("-")); cardTenderLine.ExpiryDate = track2Data.Substring(track2Data.IndexOf("-") + 1, 4); } else { // We have the card number and the exp. date cardTenderLine.CardNumber = iCardInfo.CardNumber; cardTenderLine.ExpiryDate = iCardInfo.ExpDate; getAdditionalInfo = true; } // Get information about the tender... TenderData tenderData = new TenderData(ApplicationSettings.Database.LocalConnection, ApplicationSettings.Database.DATAAREAID); ITender tenderInfo = tenderData.GetTender(iCardInfo.TenderTypeId, ApplicationSettings.Terminal.StoreId); cardTenderLine.OpenDrawer = tenderInfo.OpenDrawer; cardTenderLine.ChangeTenderID = tenderInfo.ChangeTenderID; cardTenderLine.MinimumChangeAmount = tenderInfo.MinimumChangeAmount; cardTenderLine.AboveMinimumTenderId = tenderInfo.AboveMinimumTenderId; //Get additional information on corporate card if needed if (getAdditionalInfo && !GetAdditionalInformation(cardTenderLine, this.Application)) { return; } //convert from the store-currency to the company-currency... cardTenderLine.CompanyCurrencyAmount = this.Application.Services.Currency.CurrencyToCurrency( ApplicationSettings.Terminal.StoreCurrency, ApplicationSettings.Terminal.CompanyCurrency, this.amountValue); // the exchange rate between the store amount(not the paid amount) and the company currency cardTenderLine.ExchrateMST = this.Application.Services.Currency.ExchangeRate( ApplicationSettings.Terminal.StoreCurrency) * 100; cardTenderLine.SignatureData = LSRetailPosis.POSProcesses.TenderOperation.ProcessSignatureCapture(tenderInfo, cardTenderLine); retailTransaction.Add(cardTenderLine); ((IPosTransactionV2)retailTransaction).LastRunOperationIsValidPayment = true; } catch (Exception x) { LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), x); throw; } }