Esempio n. 1
0
        private bool BeginPayment(decimal amount_, int tndrObjNum_)
        {
            LOG.Debug("ENTER");

            bool           retVal = false;
            string         errMsg = "";
            string         ccCode = "";
            VPI_ERROR_CODE posResp;

            bool fromTender = (tndrObjNum_ != 0);

            try
            {
                //ask for amount if no amount is received
                if (amount_ == 0.00m)
                {
                    amount_ = OpsContext.RequestAmountEntry("Ingrese monto a abonar", "Pago con Tarjeta", OpsContext.Check.TotalDue) ?? 0.00m;
                }

                if (amount_ == 0.00m)
                {
                    return(retVal);
                }

                string tip = "0";
                if (amount_ > OpsContext.Check.TotalDue)
                {
                    if (OpsContext.AskQuestion($"El monto sobrepasa el total de la cuenta.\r\n¿Desea utilizar los ${(amount_ - OpsContext.Check.TotalDue): N2} como propina?"))
                    {
                        tip = $"{OpsContext.Check.TotalDue - amount_: N2}";
                    }
                }

                //Find Credit Card Code (if we came from a Tender Media key)
                if (tndrObjNum_ != 0)
                {
                    if (ConfigMgr.Instance.PrismaCCToSimphonyObjNumMap.Values.Contains(tndrObjNum_))
                    {
                        ccCode = ConfigMgr.Instance.PrismaCCToSimphonyObjNumMap.Single(p => p.Value == tndrObjNum_).Key;
                    }
                    else
                    {
                        OpsContext.ShowError($"El medio de pago {tndrObjNum_} no está asociado a ninguna tarjeta de crédito en la configuración");
                        LOG.Error("{Message}", $"Couldn't find Tender Media Obj Num {tndrObjNum_} mapped to a PRISMA Credit Card");
                        return(retVal);
                    }
                }

                //Test LAPOS Device Status
                posResp = TestLAPOSDevice(ref errMsg);

                //Get Card Type (if we came from Extensibility Key or tender not mapped properly)
                if (ccCode == "")
                {
                    OpsContext.ShowMessage("Se obtendrá el tipo de tarjeta.\r\nInserte o deslice la tarjeta cuando el POS lo solicite.\r\n\r\nCierre este diálogo para continuar.");

                    CARDDATA_OUT cardData;
                    posResp = IntegratedPOS.GetCardData(out cardData, ref errMsg);

                    if (posResp != VPI_ERROR_CODE.VPI_OK)
                    {
                        posResp = IntegratedPOS.ClosePort(ref errMsg);
                        OpsContext.ShowError($"Error leyendo tipo de tarjeta.\r\n{errMsg}");
                        LOG.Error("{Message}", $"Error reading card data: [{posResp}] - {errMsg}");
                        return(retVal);
                    }

                    ccCode = cardData.CardCode.TrimStart('0');
                    OpsContext.ShowMessage("Remueva la tarjeta y cierre este diálogo para continuar");
                }

                //Find Card obj num in Simphony (if we came from Extensibility Key)
                if (tndrObjNum_ == 0)
                {
                    if (!ConfigMgr.Instance.PrismaCCToSimphonyObjNumMap.TryGetValue(ccCode, out tndrObjNum_))
                    {
                        OpsContext.ShowError($"No se encuentra definida la tarjeta {ccCode} en la configuración");
                        LOG.Error("{Message}", $"Couldn't find PRISMA Card [{ccCode}] mapped to a Simphony tender Obj Num");
                        return(retVal);
                    }
                }

                //Send payment order to pinpad
                int         instalment   = 1;
                PURCHASE_IN purchaseData = new PURCHASE_IN()
                {
                    IssuerCode      = ccCode,
                    Amount          = $"{ (int)(amount_ * 100.0m) }",
                    Tip             = tip,
                    CUIT            = ConfigMgr.Instance.LAPOSMerchantCUIT,
                    MerchantCode    = ConfigMgr.Instance.LAPOSMerchantCode,
                    ReceiptNumber   = $"{OpsContext.CheckNumber}",
                    Linemode        = (char)0x01,
                    InstalmentCount = $"{instalment}",
                    PlanCode        = GetCardPlan(ccCode, instalment),
                    MerchantName    = ConfigMgr.Instance.LAPOSMerchantName,
                };

                OpsContext.ShowMessage("Inserte o deslice la tarjeta cuando el POS lo solicite.\r\n\r\nCierre este diálogo para continuar.");

                TRX_OUT trxData;
                posResp = IntegratedPOS.Purchase(purchaseData, out trxData, ref errMsg);

                if (posResp != VPI_ERROR_CODE.VPI_OK || Int16.Parse(trxData.HostRespCode) != 0)
                {
                    OpsContext.ShowError($"Error en la operación de pago.\r\nCódigo Error = {trxData.HostRespCode} {errMsg.Trim()}");
                    LOG.Error("{Message}", $"Error trying to purchase with CC[{ccCode}].\r\n Error Code = ({trxData.HostRespCode}) {errMsg.Trim()}.\r\n{trxData.HostMessage}");
                    return(retVal);
                }

                retVal = (posResp == VPI_ERROR_CODE.VPI_OK);

                LOG.Info("{Message}", $"LAPOS Purchase operation returned from host:\r\n{trxData.DumpString()}");

                if (ConfigMgr.Instance.LAPOSShowPaymentResultDialog)
                {
                    OpsContext.ShowMessage(trxData.DumpString());
                }

                //Send Tender media
                if (!fromTender)
                {
                    AddTender(tndrObjNum_, amount_, trxData.AuthCode);
                    mTenderTriggeredByInterface = true;
                }
            }
            catch (Exception ex)
            {
                LOG.Fatal(ex, "{Message}", "Exception caught.");
            }
            finally
            {
                LOG.Debug("EXIT");
            }

            return(retVal);
        }
        public void ExportRecordsToCSV()
        {
            int           SuccessCount       = 0;
            int           FailureCount       = 0;
            StringBuilder AllCustomerRecords = new StringBuilder();

            string RequestedEncryptionKey = OpsContext.RequestAlphaEntry("Enter Encryption Key", "Enter Encryption Key");

            if (RequestedEncryptionKey == GetPassword()) // TODO: Fix the comparison to be safer.
            {
                bool Continue = OpsContext.AskQuestion("This will export all customer records to a CSV file on the disk. Are you sure?");

                if (!Continue)
                {
                    return;
                }
            }
            else
            {
                OpsContext.ShowError("Incorrect Encryption Key");
                return;
            }

            if (Directory.Exists(StoragePath))
            {
                foreach (var zipFile in Directory.GetFiles(StoragePath, $"{SaveFilePrefix}*.zip"))
                {
                    using (var dailyZipFile = ZipFile.Read(zipFile))
                    {
                        dailyZipFile.Encryption = EncryptionAlgorithm.WinZipAes256;
                        dailyZipFile.Password   = GetPassword();

                        foreach (var entry in dailyZipFile.Entries)
                        {
                            try
                            {
                                using (StreamReader sr = new StreamReader(entry.OpenReader()))
                                {
                                    string CustomerRecord = sr.ReadToEnd();
                                    AllCustomerRecords.AppendLine(CustomerRecord);

                                    SuccessCount++;
                                }
                            }
                            catch (Exception ex)
                            {
                                base.Logger.LogAlways($"CovidCustomerData: Failure reading from file {dailyZipFile.Name} and entry name {entry.FileName} {System.Environment.NewLine} Reason: {ex.Message}");
                                FailureCount++;
                            }
                        }
                    }
                }
            }
            else
            {
                OpsContext.ShowError($"Storage Path '{StoragePath}' cannot be found.");
            }

            try
            {
                string FilePath = WriteTextToDisk(AllCustomerRecords);

                OpsContext.ShowMessage($"Exported {SuccessCount} Customer Records to: '{FilePath}'{System.Environment.NewLine}Failed to export {FailureCount} Customer Records");
            }
            catch (Exception ex)
            {
                OpsContext.ShowError($"Failed to export to disk. Reason {ex.ToString()}");
            }
        }