/// <summary>
        /// Create Customer Ticket to output the reciept
        /// </summary>
        /// <param name="ticket"></param>
        private static void CreateCustomerTicket(TransactionDetails ticket)
        {
            StringBuilder ticketContent = new StringBuilder();

            //set user message
            ticket.UserMessage = "\n\tPLEASE RETAIN RECEIPT. \n\n\tTHANK YOU.";
            ticketContent.Append($"\nApp Id: {ticket.ApplicationId}\n");
            ticketContent.Append($"App Label: {ticket.ApplicationLabel}\n");
            ticketContent.Append($"AuthCode: {ticket.AuthCode}\n");
            //ticketContent.Append($"Card holder Verification Method: {ticket.CardholderVerificationMethod}\n");
            ticketContent.Append($"Card Scheme Name: {ticket.CardSchemeName}\n");
            ticketContent.Append($"Currency: {ticket.Currency}\n");
            ticketContent.Append($"Start Date: {ticket.DateOfStart}\n");
            ticketContent.Append($"Expiry Date: {ticket.DateOfExpiry}\n");
            ticketContent.Append($"Payment Method: {ticket.PaymentMethod}\n");
            ticketContent.Append($"PAN: {ticket.PrimaryAccountNumber}\n");
            ticketContent.Append($"PAN Num Seq: {ticket.PrimaryAccountNumberSequence}\n");
            ticketContent.Append($"Transaction Id: {ticket.TransactionId}\n");
            ticketContent.Append($"Transaction Num: {ticket.TransactionNumber}\n");
            ticketContent.Append($"Transaction Result: {ticket.TransactionResult}\n");
            ticketContent.Append($"Transaction Time: {ticket.TransactionTime}\n");
            ticketContent.Append($"Transaction Type: {ticket.TransactionType}\n");
            ticketContent.Append($"\nAmount Total: {Utils.GetCurrencySymbol(ticket.Currency)}{(ticket.AmountTotal / 100.0)}\n");
            ticketContent.Append($"\t\n{ticket.UserMessage}\n");
            try
            {
                Log.Info($"Persisting Customer ticket to {ticketPath}");

                //Write the new ticket to the ticket path
                File.WriteAllText(ticketPath, ticketContent.ToString());

                PersistTransaction(ticketContent.ToString());
            }
            catch (Exception ex)
            {
                Log.Error("Error persisting ticket.");
                Log.Error(ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Starts a transaction on the terminal with the given TID.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public DiagnosticErrMsg Pay(int value, out TransactionDetails result)
        {
            int        amount;
            RestClient client            = Authenticate(url + "/pac/terminals/" + tid + "/transactions");
            bool       signatureRequired = false;

            //initialise the result - fill this with the customer reciept to display
            result = null;

            //check value
            amount = Utils.GetNumericAmountValue(value);

            if (amount == 0)
            {
                throw new Exception("Error in Amount value...");
            }

            var request = new RestRequest(Method.POST);

            request = RequestParams(request);
            request.AddParameter("Sale", "{\r\n  \"transactionType\": \"SALE\",\r\n  \"amount\": " + value + ",\r\n  \"currency\": \"" + configFile.Currency + "\"\r\n}", ParameterType.RequestBody);

            IRestResponse response = client.Execute(request);

            //check reponse isSuccessful
            if (response.IsSuccessful)
            {
                //deserialise response
                TransactionResp tranResponse = JsonConvert.DeserializeObject <TransactionResp>(response.Content);
                requestId = tranResponse.RequestId;

                //poll for result every 1 seconds block until finish
                while (true)
                {
                    Thread.Sleep(1000);
                    response = GetTransactionData(requestId, configFile.UserAccountUrl);

                    if ((response.Content.Contains("SIGNATURE_VERIFICATION")) && (signatureRequired == false))
                    {
                        signatureRequired = true;
                        response          = SignaturePutRequest(requestId, url);
                    }

                    if (response.Content.Contains("TRANSACTION_FINISHED"))
                    {
                        break;
                    }
                }
            }

            //deserialise response
            result = JsonConvert.DeserializeObject <TransactionDetails>(response.Content);

            if (result.TransactionResult.Contains("SUCCESSFUL"))
            {
                return(DiagnosticErrMsg.OK);
            }
            else
            {
                return(DiagnosticErrMsg.NOTOK);
            }
        }