Esempio n. 1
0
        public void valid(string id)
        {
            var tid = new TerminalId(id);

            Assert.Equal(int.Parse(id), tid.Value);
            Assert.Equal(id, tid.ToString());
        }
Esempio n. 2
0
        public override string ToString()
        {
            StringBuilder result = new StringBuilder();

            // Message type (= Payment request), Length: 4, Fieldtype: AN
            result.Append(StringValueAttribute.GetStringValue(MessageType));
            // Terminal number, Length: 8, Fieldtype: N
            result.Append(TerminalId.ToString(CultureInfo.InvariantCulture).PadLeft(8, '0'));
            // Message version number, Length: 1, Fieldtype: N
            // 0 = No addittional information, 1 = additional information
            result.Append(HasAdditionalInformation ? "1" : "0");
            // Amount, Length: 11, Fieldtype: N
            result.Append(Amount.ToString("#.##", CultureInfo.CurrentCulture).Replace(
                              CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, "").PadLeft(11, '0'));
            // Product info, Length: 20, Fieldtype: AN (Future use)
            result.Append(new String(' ', 20));
            // Receipt number, Length: 6, Fieldtype: N
            result.Append(ReceiptNumber.ToString(CultureInfo.InvariantCulture).PadLeft(6, '0'));
            // Transaction type, Length: 2, Fieldtype: N
            // 00 = Purchase
            result.Append(StringValueAttribute.GetStringValue(TransactionType));
            // Length of additional information, Length: 3, Fieldtype: N
            result.Append(AdditionalInformation.Length.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0'));
            // Indicator additional information, Length: 2, Fieldtype: N
            // 01 = Currency, 02 = Product information (only for petrol)
            // 03 = Product information (Special terminal)
            result.Append(StringValueAttribute.GetStringValue(AdditionalInformationType));
            // Additional information, Length: variable, Fieldtype: AN
            result.Append(AdditionalInformation);
            // End of text
            result.Append((Char)TwoStepProtocol.EndOfText);
            // LRC Checksum
            result.Append(TerminalRequest.CalculateLongitudinalRedundancyCheck(result.ToString()));
            // Start of text
            result.Insert(0, (Char)TwoStepProtocol.StartOfText);
            return(result.ToString());
        }
Esempio n. 3
0
        private void PrintTransaction(string OrderType)
        {
            try
            {
                int    TransactionId       = 0;
                string NumeratorCurrency   = "BTC"; //TODO: make currencies classes, with code as properties.
                string DenominatorCurrency = CryptoCurrency.FiatCode;
                string Reference           = "";

                // Write transaction to database
                //change terminal id to int
                Decimal tx = cardClient.WriteTransaction(TagId, OrderType, TerminalId.ToString(), NumeratorCurrency, DenominatorCurrency, CryptoCurrency.Fiat, Price, Reference, TransactionId);
                if (tx > 0)
                {
                    // Get the text for the paper receipt.
                    string receiptText = Environment.NewLine;
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;

                    receiptText += String.Format("DATE:{0}", DateTime.Now) + Environment.NewLine;
                    receiptText += "TERMINAL:" + TerminalId + Environment.NewLine;
                    receiptText += "TRANS ID:" + TransactionId + Environment.NewLine;
                    receiptText += "TAG ID:" + TagId + Environment.NewLine;
                    receiptText += "TRANS TYPE:" + OrderType + Environment.NewLine;
                    receiptText += "COIN NAME:" + NumeratorCurrency + Environment.NewLine;
                    receiptText += "FIAT TYPE" + DenominatorCurrency + Environment.NewLine;
                    receiptText += "FIAT AMOUNT:" + CryptoCurrency.Fiat + Environment.NewLine;
                    receiptText += "COIN AMOUNT:" + CryptoCurrency.Amount + Environment.NewLine;
                    receiptText += "RATE:" + Price + Environment.NewLine;
                    receiptText += "http://diamondcircle.net";
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;

                    // Initialise the printer if required.
                    if (!Factory.GetPrinter().Initialised)
                    {
                        try
                        {
                            Factory.GetPrinter().Initialise();
                        }
                        catch (Exception ex)
                        {
                            lblStatusMessage.Text = "Cannot Print Receipt.";
                            GeneralExceptions("PrintTransaction - Initalise", System.Diagnostics.TraceEventType.Error, ex);
                            return;
                        }
                    }
                    // Print the receipt.
                    ErrorCode writeErrorCode = Factory.GetPrinter().PrintText(receiptText);
                    if (writeErrorCode != ErrorCode.None)
                    {
                        lblStatusMessage.Text = "Cannot Print Receipt";
                        throw new System.InvalidOperationException("PrintTransaction - Cannot Print Receipt");
                    }
                }
                else
                {
                    throw new System.InvalidOperationException("Could not Write Transaction to Database - System Error");
                }
            }
            catch (Exception ex)
            {
                lblStatusMessage.Text = "Cannot Print Receipt.";
                GeneralExceptions("PrintTransaction", System.Diagnostics.TraceEventType.Critical, ex);
                ReturnToMainMenu();
                return;
            }
        }