private String sharedKey = "raiffeisen.online.test.12gdf3"; //do uzgodnienia i zmiany oraz przemyślenia czy zaszyty w kodzie

        #endregion Fields

        #region Methods

        // Do uzgodnienia - chcą używać typu BigDecimal - nie jest wspierany przez .NET- piszemy klasę do obsługi?
        //
        public Confirmation transAlerts(Transaction transaction)
        {
            StringBuilder logMessage = new StringBuilder();
              logMessage.Append("merchantID=").AppendLine(transaction.merchantID.ToString()).
            Append("orderId=").AppendLine(transaction.orderID).
            Append("transId=").AppendLine(transaction.transID).
            Append("transDate=").AppendLine(transaction.transDate.ToString("yyyy-MM-dd HH:mm:ss")).
            Append("transTitle=").AppendLine(transaction.transTitle).
            Append("value=").AppendLine(transaction.amount.value.ToString()).
            Append("currency=").AppendLine(transaction.amount.currency.ToString()).
            Append("paywayID=").AppendLine(transaction.paywayID.ToString()).
            Append("statusDate=").AppendLine(transaction.statusDate.ToString("yyyy-MM-dd HH:mm:ss")).
            Append("status=").AppendLine(transaction.status.ToString()).
            Append("customerAddress=").AppendLine(transaction.customerData == null ? String.Empty : transaction.customerData.customerAddress).
            Append("customerNRB=").AppendLine(transaction.customerData == null ? String.Empty : transaction.customerData.customerNRB).
            Append("klucz_współdzielony=").AppendLine(sharedKey).
            Append("hash=").AppendLine(transaction.docHash);
              PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "A transaction has just arrived");
              PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, logMessage.ToString());

              StringBuilder sb = new StringBuilder();
              sb.Append(transaction.merchantID).Append(transaction.orderID).Append(transaction.transID).
            Append(transaction.transDate.ToString("yyyy-MM-dd HH:mm:ss")).
            Append(transaction.transTitle).
            Append(transaction.amount.value.ToString().Replace(",", ".")).Append(transaction.amount.currency).
            Append(transaction.paywayID).Append(transaction.statusDate.ToString("yyyy-MM-dd HH:mm:ss")).
            Append(transaction.status).Append(transaction.customerData == null ? String.Empty : transaction.customerData.customerAddress).
            Append(transaction.customerData == null ? String.Empty : transaction.customerData.customerNRB).Append(sharedKey);
              Boolean hashCorrect;
              Confirmation.ConfirmationEnum confirmationValue = Confirmation.ConfirmationEnum.CONFIRMED;
              using (MD5 md5Hash = MD5.Create())
              {
            hashCorrect = HelperMethods.VerifyHash(md5Hash, sb.ToString(), transaction.docHash);
              }
              if (hashCorrect)
              {
            try
            {
              using(RaiffeisenPazrDataClassesDataContext dc = new RaiffeisenPazrDataClassesDataContext(TaskInserter.connectionString))
              {
            var transactions = from tr in dc.itn_transactions
                               where tr.transID == transaction.transID
                               select tr;
            var currencies = from cur in dc.itn_currencies
                             where cur.currency.ToString() == transaction.amount.currency.ToString()
                             select cur;
            if (currencies.Count() == 0) // Zgodnie ze specyfikacją sytuacja nie może zaistnieć - dopuszczają tylko PLN - można zakomentować if
            {
              itn_currency newCurrency = new itn_currency() { currency = transaction.amount.currency.ToString() };
              dc.itn_currencies.InsertOnSubmit(newCurrency);
              dc.SubmitChanges();
            }
            int currencyID = currencies.First().id;
            if (transactions.Count() == 1)
            {
              itn_transaction modifiedTransaction = transactions.First();
              if (modifiedTransaction.status > 0 && transaction.status <= 0)
              {
                // jeżeli taka sytuacja zaistnieje, to błąd
                // do uzgodnienia co wtedy robimy,
                // na razie zwracam NOT_CONFIRMED;
                PTR3Core.LOG.Log(MsgStatusEnum.MS_Warning, "Transaction with id {0} wants to change the status from positive to negative. This situation is unexpected and should be verified.",modifiedTransaction.id);
                PTR3Core.LOG.Log(MsgStatusEnum.MS_Warning, "Transaction will be NOT_CONFIRMED");
                confirmationValue = Confirmation.ConfirmationEnum.NOT_CONFIRMED;
              }
              else if (modifiedTransaction.merchantID != transaction.merchantID
                || modifiedTransaction.orderID != transaction.orderID
                || modifiedTransaction.value != transaction.amount.value)
              {
                PTR3Core.LOG.Log(MsgStatusEnum.MS_Warning, "Transaction with id {0} wants to change one of the values: merchantID, orderID, value. This situation is unexpected and should be verified.", modifiedTransaction.id);
                PTR3Core.LOG.Log(MsgStatusEnum.MS_Warning, "Transaction will be NOT_CONFIRMED");
                confirmationValue = Confirmation.ConfirmationEnum.NOT_CONFIRMED;
              }
              else
              {
                PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Transaction already exists in the database.");
                modifiedTransaction.transID = transaction.transID;
                modifiedTransaction.paywayID = transaction.paywayID;
                modifiedTransaction.merchantID = transaction.merchantID;
                modifiedTransaction.status = transaction.status;
                modifiedTransaction.statusDate = transaction.transDate;
                modifiedTransaction.transTitle = transaction.transTitle;
                modifiedTransaction.customerAccount = transaction.customerData == null ? String.Empty : transaction.customerData.customerNRB;
                modifiedTransaction.customerAddress = transaction.customerData == null ? String.Empty : transaction.customerData.customerAddress;
                modifiedTransaction.transDate = transaction.transDate;
                modifiedTransaction.value = transaction.amount.value;
                modifiedTransaction.currencyID = currencyID;
                PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Transaction will be CONFIRMED and updated in the database.");
                dc.SubmitChanges();
              }
            }
            else if (transactions.Count() == 0)
            {
              PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Transaction is a new one.");
              itn_transaction newTransaction = new itn_transaction()
              {
                transID = transaction.transID,
                orderID = transaction.orderID,
                paywayID = transaction.paywayID,
                merchantID = transaction.merchantID,
                status = transaction.status,
                statusDate = transaction.transDate,
                customerAccount = transaction.customerData == null ? String.Empty : transaction.customerData.customerNRB,
                customerAddress = transaction.customerData == null ? String.Empty : transaction.customerData.customerAddress,
                transDate = transaction.transDate,
                transTitle = transaction.transTitle,
                value = transaction.amount.value,
                currencyID = currencyID
              };
              dc.itn_transactions.InsertOnSubmit(newTransaction);
              dc.SubmitChanges();
              PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Transaction will be CONFIRMED and inserted into the database.");
            }
            else
              {
              PTR3Core.LOG.Log(MsgStatusEnum.MS_Warning, "There is more than one transaction with transId {0}. This situation is unexpected and should be verified.", transaction.transID);
              }
              }
            }
            catch (Exception e)
            {
              PTR3Core.LOG.Log(MsgStatusEnum.MS_Error, "Error when connecting to database {0}", e.Message);
            }
              }
              else
              {
            PTR3Core.LOG.Log(MsgStatusEnum.MS_Warning, "Hash incorrect");
            PTR3Core.LOG.Log(MsgStatusEnum.MS_Warning, "Transaction will be NOT_CONFIRMED");
            confirmationValue = Confirmation.ConfirmationEnum.NOT_CONFIRMED;
              }
              if(confirmationValue == Confirmation.ConfirmationEnum.CONFIRMED)
              {
            String message = "ITN arrived. Timer1 is reset, Timer2 will start if it is not running. ";
            TaskInserter.shortTimer.Reset();
            if (!TaskInserter.longTimer.Timer.Enabled)
            {
              TaskInserter.longTimer.Start();
              message += "Timer 2 is not enabled and starts now.";
            }
            else
            {
              message += "Timer 2 was already started.";
            }
            PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, message);
              }
              String confirmationHash = String.Empty;
              using (MD5 md5Hash = MD5.Create())
              {
            confirmationHash = HelperMethods.GetHash(md5Hash, transaction.merchantID + transaction.orderID +
              confirmationValue.ToString() + sharedKey);
              }
              return new Confirmation()
              {
            confirmation = confirmationValue,
            merchantID = transaction.merchantID,
            orderID = transaction.orderID,
            docHash = confirmationHash
              };
        }
 partial void Updateitn_currency(itn_currency instance);
 partial void Deleteitn_currency(itn_currency instance);
 partial void Insertitn_currency(itn_currency instance);