Exemplo n.º 1
0
        /// <summary>
        /// Method that is executed when a message is received from the EFT via Socket.
        /// This method will analize the message and based on it's type change the appropriate flag
        /// to notify the methods that are waiting for a message from the EFT
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void DoOnReceivedMessageEventHandler(object sender, ReceivedMessageEventArgs args)
        {
            //If the message is a EFT BEGIN Confirmation
            if (args.Message.IndexOf(C3MessageTypes.EFT_BEGIN) == 0)
            {
                //If the EFT BEGIN INIT request was sent change the flag to signal that the confirmation was received
                if (waitingEFTBeginResponse)
                {
                    waitingEFTBeginResponse = false;
                }
            }
            //If the message is a EFT END Confirmation
            else if (args.Message.IndexOf(C3MessageTypes.EFT_END) == 0)
            {
                //If the EFT END request was sent change the flag to signal that the confirmation was received
                if (waitingEFTEndResponse)
                {
                    eftEndResponse = new EFTEndMessage(args.Message);

                    waitingEFTEndResponse = false;
                }
            }

            //If the message is a DISPLAY MESSAGE send the DISPLAY MESSAGE confirmation
            else if (args.Message.IndexOf(C3MessageTypes.POS_DISPLAY) == 0)
            {
                EFTPOSDispplayMessage eFTPOSDispplayMessage = new EFTPOSDispplayMessage(args.Message);

                //RESPOND_IMEDIATLY_ACTION
                if (eFTPOSDispplayMessage.ActionType == EFTPOSDisplayMessageActionTypes.RESPOND_IMEDIATLY_ACTION)
                {
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        [DISPLAY POS MESSAGE] {0} [RIC]", eFTPOSDispplayMessage.Description);
                }
                //RESPOND_WITH_1SEC_DELAY
                else if (eFTPOSDispplayMessage.ActionType == EFTPOSDisplayMessageActionTypes.RESPOND_WITH_1SEC_DELAY)
                {
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        [DISPLAY POS MESSAGE] {0} [RWD]", eFTPOSDispplayMessage.Description);

                    //Wait 1 second before sending the response message
                    Thread.Sleep(1000);
                }

                //RESPOND_AFTER USER CONFIRMATION
                else if (eFTPOSDispplayMessage.ActionType == EFTPOSDisplayMessageActionTypes.WAIT_FOR_AKNOLEDGEMENT_ACTION)
                {
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        [DISPLAY POS MESSAGE] {0} [AFC]", eFTPOSDispplayMessage.Description);
                }

                //Wait for the operator to press the "ENTER"
                Task.Run(() => { SendPosDisplayResponse(eFTPOSDispplayMessage.GetEFTPOSDispplayMessageCofirmationResponse()); });

                //Send progress message to Core
                SendProgressMessage(eFTPOSDispplayMessage.Description);
            }
            else if (args.Message.IndexOf(C3MessageTypes.PROGRESS_MESSAGE) == 0)
            {
                EFTProgressMessage eFTProgressMessage = new EFTProgressMessage(args.Message);

                Log.Info(PAY_INGENICO_IPP350_LOG, "        [PROGRESS MESSAGE]");

                Task.Run(() => { SendProgressMessageResponse(eFTProgressMessage.GetEFTProgressMessageCofirmationResponse()); });
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method that is called when the Core requests a payment .
        /// This method will make a transaction request to the c3_rpm_net.exe.
        /// Response will be provided back to the Core based on the EFT initialization response.
        /// </summary>
        public void Pay(object parameters)
        {
            Log.Info(PAY_INGENICO_IPP350_LOG, "call Pay");

            //Check if another method is executing
            if (IsCallbackMethodExecuting)
            {
                coreCommunicator.SendMessage(CommunicatorMethods.Pay, new { Status = 297, Description = "Another method is executing", PayDetails = new PayDetails() });

                Log.Info(PAY_INGENICO_IPP350_LOG, "        another method is executing.");

                Log.Info(PAY_INGENICO_IPP350_LOG, "endcall Pay");

                return;
            }
            else
            {
                IsCallbackMethodExecuting = true;
            }

            periodicalCheckTimer.Stop();

            //Get the pay request object that will be sent to the fiscal printer
            Log.Info(PAY_INGENICO_IPP350_LOG, "        deserialize the pay request parameters.");
            PayRequest payRequest = GetPayRequest(parameters.ToString());

            //Check if the pay deserialization was successful
            if (payRequest == null)
            {
                coreCommunicator.SendMessage(CommunicatorMethods.Pay, new { Status = -331, Description = "failed to deserialize the pay request parameters", PayDetails = new PayDetails() });
                Log.Info(PAY_INGENICO_IPP350_LOG, "        failed to deserialize the pay request parameters.");
                return;
            }
            Log.Info(PAY_INGENICO_IPP350_LOG, "        deserialized pay request parameters.");

            if (payRequest.Amount == 0)
            {
                coreCommunicator.SendMessage(CommunicatorMethods.Pay, new { Status = -299, Description = "amount can't be zero.", PayDetails = new PayDetails() });
                Log.Info(PAY_INGENICO_IPP350_LOG, "        amount can't be zero.");
                return;
            }

            if (string.IsNullOrEmpty(payRequest.TransactionReference))
            {
                coreCommunicator.SendMessage(CommunicatorMethods.Pay, new { Status = -298, Description = "transaction reference can't be empty.", PayDetails = new PayDetails() });
                Log.Info(PAY_INGENICO_IPP350_LOG, "        transaction reference can't be empty.");
                return;
            }

            //Connect to the C3Net
            if (!ConnectToC3Net())
            {
                coreCommunicator.SendMessage(CommunicatorMethods.Pay, new { Status = -332, Description = "the connection is down", PayDetails = new PayDetails() });
            }
            else
            {
                //Reset the waiting for response flag
                waitingEFTBeginResponse = true;

                //Reset the waiting for response flag
                waitingEFTEndResponse = true;

                //Create the result object
                eftEndResponse = new EFTEndMessage();

                //Create the eft begin init request object
                EFTBeginMessage eftBeginRequestMessage = new EFTBeginMessage();

                //Based on the selected currency create the appropriate command
                string requestString = string.Empty;
                if (CurrencyValue == "EUR")
                {
                    requestString = eftBeginRequestMessage.GetTransactionMessage(TerminalID, Currency.EUR.ToString(), payRequest.Amount.ToString(), payRequest.TransactionReference);
                }
                if (CurrencyValue == "GBP")
                {
                    requestString = eftBeginRequestMessage.GetTransactionMessage(TerminalID, Currency.GPB.ToString(), payRequest.Amount.ToString(), payRequest.TransactionReference);
                }

                //Send the eft begin init request
                if (!c3NetCommunicator.Send(requestString))
                {
                    coreCommunicator.SendMessage(CommunicatorMethods.Pay, new { Status = -334, Description = "failed to send Initialization request", PayDetails = new PayDetails() });
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        failed to send initialization request.");
                    IsCallbackMethodExecuting = false;
                    Log.Info(PAY_INGENICO_IPP350_LOG, "endcall Pay");
                    return;
                }

                //Wait the eft begin confirmationinit response
                if (!WaitingEFTBeginConfirmationResponse())
                {
                    coreCommunicator.SendMessage(CommunicatorMethods.Pay, new { Status = -335, Description = "No EFT Begin Confirmation was received", PayDetails = new PayDetails() });
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        No EFT Begin Confirmation was received");
                    IsCallbackMethodExecuting = false;
                    Log.Info(PAY_INGENICO_IPP350_LOG, "endcall Pay");
                    return;
                }
                Log.Info(PAY_INGENICO_IPP350_LOG, "        received EFT Begin Confirmation.");

                //Wait eft end response
                if (!WaitingEFTEndResponse())
                {
                    coreCommunicator.SendMessage(CommunicatorMethods.Pay, new { Status = -336, Description = "No EFT End Response was received", PayDetails = new PayDetails() });
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        No EFT End Response was received");
                    IsCallbackMethodExecuting = false;
                    Log.Info(PAY_INGENICO_IPP350_LOG, "endcall Pay");
                    return;
                }
                Log.Info(PAY_INGENICO_IPP350_LOG, "        received EFT End Confirmation.");

                PayDetails payDetails = new PayDetails();

                if (eftEndResponse.Error == 0)
                {
                    //Update the paid amount
                    payDetails.PaidAmount = payRequest.Amount;

                    //Update the tender media id
                    payDetails.TenderMediaId = eftEndResponse.TenderMedia;

                    //Save the ticket
                    if (!string.IsNullOrEmpty(eftEndResponse.CustomerTicket))
                    {
                        SaveTicket(eftEndResponse.CustomerTicket, false);
                        payDetails.HasClientReceipt = true;
                    }
                    //Save the merchant ticket
                    if (!string.IsNullOrEmpty(eftEndResponse.MerchantTicket))
                    {
                        SaveTicket(eftEndResponse.MerchantTicket, true);
                        payDetails.HasMerchantReceipt = true;
                    }

                    //Reset the timer if a payment was successful
                    periodicalCheckTimer.Stop();
                    periodicalCheckTimer.Start();

                    Log.Info(PAY_INGENICO_IPP350_LOG, "        Tender Media: {0}", eftEndResponse.TenderMedia);

                    coreCommunicator.SendMessage(CommunicatorMethods.Pay, new { Status = 0, Description = "Successful payment", PayDetails = payDetails });
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        credit card payment succeeded.");
                }
                else
                {
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        Error Code: {0}", eftEndResponse.Error);
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        Error Code Response: {0}", eftEndResponse.ErrorResponseCode);
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        Error Message:{0}", eftEndResponse.ErrorMessage);

                    //Save the ticket
                    if (!string.IsNullOrEmpty(eftEndResponse.CustomerTicket))
                    {
                        SaveTicket(eftEndResponse.CustomerTicket, false);
                        payDetails.HasClientReceipt = true;
                    }
                    //Save the merchant ticket
                    if (!string.IsNullOrEmpty(eftEndResponse.MerchantTicket))
                    {
                        SaveTicket(eftEndResponse.MerchantTicket, true);
                        payDetails.HasMerchantReceipt = true;
                    }

                    coreCommunicator.SendMessage(CommunicatorMethods.Pay, new { Status = eftEndResponse.Error, Description = eftEndResponse.ErrorMessage, PayDetails = payDetails });
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        credit card payment failed.");
                }
            }

            c3NetCommunicator.Disconnect();

            periodicalCheckTimer.Start();

            IsCallbackMethodExecuting = false;

            Log.Info(PAY_INGENICO_IPP350_LOG, "endcall Pay");
        }
Exemplo n.º 3
0
        /// <summary>
        /// It will try send a command to the terminal to get the total number of transactions
        /// (no ping method exists so this one was the only one that was available to test the terminal connection)
        /// </summary>
        private void CheckPayment()
        {
            Log.Info(PAY_INGENICO_IPP350_LOG, "        checking payment status");

            periodicalCheckTimer.Stop();

            //Connect to the C3Net
            if (!ConnectToC3Net())
            {
                IsTerminalReady = false;
                Log.Info(PAY_INGENICO_IPP350_LOG, "        the connection is down.");
            }
            else
            {
                //Change the waiting for response flag
                waitingEFTBeginResponse = true;
                //Change the waiting for response flag
                waitingEFTEndResponse = true;

                eftEndResponse = new EFTEndMessage();

                //SEND THE EFT BEGIN INIT REQUEST
                EFTBeginMessage eftBeginRequestMessage = new EFTBeginMessage();

                string requestString = eftBeginRequestMessage.GetPinpadStatusMessage(TerminalID);
                if (!c3NetCommunicator.Send(requestString))
                {
                    UpdateAndRestartThePeriodicalCkeckStatus(false, "failed to send status request.");
                    return;
                }

                //WAIT THE EFT BEGIN CONFIRMATION STATUS RESPONSE
                if (!WaitingEFTBeginConfirmationResponse())
                {
                    UpdateAndRestartThePeriodicalCkeckStatus(false, "No EFT Begin Confirmation was received");
                    return;
                }
                Log.Info(PAY_INGENICO_IPP350_LOG, "        received EFT Begin Confirmation.");

                //WAIT EFT END RESPONSE
                if (!WaitingEFTEndResponse())
                {
                    UpdateAndRestartThePeriodicalCkeckStatus(false, "No EFT End Response was received");
                    return;
                }

                if (eftEndResponse.Error == 0)
                {
                    UpdateAndRestartThePeriodicalCkeckStatus(true, "EFT ready.");
                }
                else
                {
                    UpdateAndRestartThePeriodicalCkeckStatus(false, "EFT NOT ready.");
                }
            }

            //Start the terminal periodic check
            periodicalCheckTimer.Start();

            c3NetCommunicator.Disconnect();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Method that is called when the Core requests the EFT initialization.
        /// This method will make an initialization request to the c3_rpm_net.exe.
        /// Response will be provided back to the Core based on the EFT initialization response.
        /// </summary>
        public void Init(object parameters)
        {
            Log.Info(PAY_INGENICO_IPP350_LOG, "call Initialize");

            //Check if another method is executing
            if (IsCallbackMethodExecuting)
            {
                coreCommunicator.SendMessage(CommunicatorMethods.Init, new { Status = -1 });

                Log.Info(PAY_INGENICO_IPP350_LOG, "        another method is executing.");

                Log.Info(PAY_INGENICO_IPP350_LOG, "endcall Initialize");

                return;
            }
            else
            {
                IsCallbackMethodExecuting = true;
            }

            periodicalCheckTimer.Stop();

            waitingEFTBeginResponse = false;

            //Get the initialization parameters
            if (!GetInitParameters(parameters.ToString()))
            {
                coreCommunicator.SendMessage(CommunicatorMethods.Init, new { Status = -1 });

                Log.Info(PAY_INGENICO_IPP350_LOG, "        failed to deserialize the init parameters.");
            }

            //Connect to the C3Net
            if (!ConnectToC3Net())
            {
                coreCommunicator.SendMessage(CommunicatorMethods.Init, new { Status = 332, Description = "the connection is down" });
            }
            else
            {
                //Reset the waiting for response flag
                waitingEFTBeginResponse = true;

                //Reset the waiting for response flag
                waitingEFTEndResponse = true;

                //Create the result object
                eftEndResponse = new EFTEndMessage();

                //Create the eft begin init request object
                EFTBeginMessage eftBeginRequestMessage = new EFTBeginMessage();

                //Send the eft begin init request
                string requestString = eftBeginRequestMessage.GetPinpadInitializationMessage(TerminalID);
                if (!c3NetCommunicator.Send(requestString))
                {
                    coreCommunicator.SendMessage(CommunicatorMethods.Init, new { Status = -334, Description = "failed to send Initialization request" });
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        failed to send initialization request.");
                    IsCallbackMethodExecuting = false;
                    Log.Info(PAY_INGENICO_IPP350_LOG, "endcall Initialize");
                    return;
                }

                //Wait the eft begin confirmationinit response
                if (!WaitingEFTBeginConfirmationResponse())
                {
                    coreCommunicator.SendMessage(CommunicatorMethods.Init, new { Status = -335, Description = "No EFT Begin Confirmation was received" });
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        No EFT Begin Confirmation was received");
                    IsCallbackMethodExecuting = false;
                    Log.Info(PAY_INGENICO_IPP350_LOG, "endcall Initialize");
                    return;
                }
                Log.Info(PAY_INGENICO_IPP350_LOG, "        received EFT Begin Confirmation.");

                //Wait eft end response
                if (!WaitingEFTEndResponse())
                {
                    coreCommunicator.SendMessage(CommunicatorMethods.Init, new { Status = -336, Description = "No EFT End Response was received" });
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        No EFT End Response was received");
                    IsCallbackMethodExecuting = false;
                    Log.Info(PAY_INGENICO_IPP350_LOG, "endcall Initialize");
                    return;
                }
                Log.Info(PAY_INGENICO_IPP350_LOG, "        received EFT End Confirmation.");

                if (eftEndResponse.Error == 0)
                {
                    coreCommunicator.SendMessage(CommunicatorMethods.Init, new { Status = 0, Description = "Ready" });
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        EFT succesfully initialized");

                    CheckPayment();

                    //Start the terminal periodic check
                    periodicalCheckTimer.Start();
                }
                else
                {
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        Error Code: {0}", eftEndResponse.Error);
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        Error Code Response: {0}", eftEndResponse.ErrorResponseCode);
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        Error Message:{0}", eftEndResponse.ErrorMessage);

                    coreCommunicator.SendMessage(CommunicatorMethods.Init, new { Status = eftEndResponse.Error, Description = eftEndResponse.ErrorMessage });
                    Log.Info(PAY_INGENICO_IPP350_LOG, "        EFT failed to initialized");
                }
            }

            c3NetCommunicator.Disconnect();

            IsCallbackMethodExecuting = false;

            Log.Info(PAY_INGENICO_IPP350_LOG, "endcall Initialize");
        }