Ejemplo n.º 1
0
        private bool ProcessInput(string[] spInput)
        {
            switch (spInput[0].ToLower())
            {
            case "purchase":
            case "kebab":
                _retryCmd = spInput;
                DoPurchase();
                break;

            case "refund":
            case "yuck":
                _retryCmd = spInput;
                DoRefund();
                break;

            case "cashout":
                _retryCmd = spInput;
                DoCashout();
                break;

            case "13kebab":
                _retryCmd = spInput;
                DoMoto();
                break;

            case "pos_id":
                Console.Clear();
                if (_spi.SetPosId(spInput[1]))
                {
                    _posId = spInput[1];
                    Console.WriteLine($"## -> POS ID now set to {_posId}");
                }
                else
                {
                    Console.WriteLine($"## -> Could not set POS ID");
                }
                ;
                PrintStatusAndActions();
                Console.Write("> ");
                break;

            case "eftpos_address":
                Console.Clear();
                if (_spi.SetEftposAddress(spInput[1]))
                {
                    _eftposAddress = spInput[1];
                    Console.WriteLine($"## -> Eftpos Address now set to {_eftposAddress}");
                }
                else
                {
                    Console.WriteLine($"## -> Could not set Eftpos Address");
                }
                ;
                PrintStatusAndActions();
                Console.Write("> ");
                break;

            case "pair":
                var pairingInited = _spi.Pair();
                if (!pairingInited)
                {
                    Console.WriteLine($"## -> Could not Start Pairing. Check Settings.");
                }
                break;

            case "pair_cancel":
                _spi.PairingCancel();
                break;

            case "pair_confirm":
                _spi.PairingConfirmCode();
                break;

            case "unpair":
                _spi.Unpair();
                break;

            case "tx_sign_accept":
                _spi.AcceptSignature(true);
                break;

            case "tx_sign_decline":
                _spi.AcceptSignature(false);
                break;

            case "tx_cancel":
                _spi.CancelTransaction();
                break;

            case "tx_auth_code":
                var sacRes = _spi.SubmitAuthCode(spInput[1]);
                if (!sacRes.ValidFormat)
                {
                    Console.WriteLine($"Ivalid Code Format. {sacRes.Message}. Try Again.");
                }
                break;

            case "settle":
                var settleres = _spi.InitiateSettleTx(RequestIdHelper.Id("settle"));
                if (!settleres.Initiated)
                {
                    Console.WriteLine($"# Could not initiate settlement: {settleres.Message}. Please Retry.");
                }
                break;

            case "settle_enq":
                var senqres = _spi.InitiateSettlementEnquiry(RequestIdHelper.Id("stlenq"));
                if (!senqres.Initiated)
                {
                    Console.WriteLine($"# Could not initiate settlement enquiry: {senqres.Message}. Please Retry.");
                }
                break;


            case "rcpt_from_eftpos":
                _spi.Config.PromptForCustomerCopyOnEftpos = spInput[1].ToLower() == "true";
                break;

            case "sig_flow_from_eftpos":
                _spi.Config.SignatureFlowOnEftpos = spInput[1].ToLower() == "true";
                break;

            case "ok":
                Console.Clear();
                _spi.AckFlowEndedAndBackToIdle();
                PrintStatusAndActions();
                Console.Write("> ");
                break;

            case "recover":
                Console.Clear();
                var rres = _spi.InitiateRecovery(spInput[1], TransactionType.Purchase);
                if (!rres.Initiated)
                {
                    Console.WriteLine($"# Could not initiate recovery. {rres.Message}. Please Retry.");
                }
                break;

            case "glt":
                var gltres = _spi.InitiateGetLastTx();
                Console.WriteLine(gltres.Initiated ? "# GLT Initiated. Will be updated with Progress." : $"# Could not initiate GLT: {gltres.Message}. Please Retry.");
                break;

            case "status":
                Console.Clear();
                PrintStatusAndActions();
                break;

            case "ok_retry":
                Console.Clear();
                _spi.AckFlowEndedAndBackToIdle();
                Console.WriteLine($"# Order Cancelled");
                if (_spi.CurrentTxFlowState.Type == TransactionType.Purchase)
                {
                    DoPurchase();
                }
                else if (_spi.CurrentTxFlowState.Type == TransactionType.Refund)
                {
                    DoRefund();
                }
                else if (_spi.CurrentTxFlowState.Type == TransactionType.CashoutOnly)
                {
                    DoCashout();
                }
                else if (_spi.CurrentTxFlowState.Type == TransactionType.MOTO)
                {
                    DoMoto();
                }
                PrintStatusAndActions();
                break;

            case "ok_override_paid":
                Console.Clear();
                _spi.AckFlowEndedAndBackToIdle();
                Console.WriteLine($"# Order Paid");
                PrintStatusAndActions();
                break;

            case "ok_cancel":
                Console.Clear();
                _spi.AckFlowEndedAndBackToIdle();
                Console.WriteLine($"# Order Cancelled");
                PrintStatusAndActions();
                break;

            case "bye":
                return(true);

            case "":
                Console.Write("> ");
                break;

            default:
                Console.WriteLine("# I don't understand. Sorry.");
                Console.Write("> ");
                break;
            }
            return(false);
        }
Ejemplo n.º 2
0
        private bool ProcessInput(string[] spInput)
        {
            string           preauthId;
            InitiateTxResult initRes;

            switch (spInput[0].ToLower())
            {
            case "acct_verify":
            { }
                initRes = _spiPreauth.InitiateAccountVerifyTx("actvfy-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss"));
                if (!initRes.Initiated)
                {
                    Console.WriteLine($"# Could not initiate account verify request: {initRes.Message}. Please Retry.");
                }
                break;

            case "preauth_open":
            { }
                initRes = _spiPreauth.InitiateOpenTx("propen-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss"), int.Parse(spInput[1]));
                if (!initRes.Initiated)
                {
                    Console.WriteLine($"# Could not initiate preauth request: {initRes.Message}. Please Retry.");
                }
                break;

            case "preauth_topup":
                preauthId = spInput[1];
                initRes   = _spiPreauth.InitiateTopupTx("prtopup-" + preauthId + "-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss"), preauthId, int.Parse(spInput[2]));
                if (!initRes.Initiated)
                {
                    Console.WriteLine($"# Could not initiate preauth request: {initRes.Message}. Please Retry.");
                }
                break;

            case "preauth_topdown":
                preauthId = spInput[1];
                initRes   = _spiPreauth.InitiatePartialCancellationTx("prtopd-" + preauthId + "-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss"), preauthId, int.Parse(spInput[2]));
                if (!initRes.Initiated)
                {
                    Console.WriteLine($"# Could not initiate preauth request: {initRes.Message}. Please Retry.");
                }
                break;

            case "preauth_extend":
                preauthId = spInput[1];
                initRes   = _spiPreauth.InitiateExtendTx("prtopd-" + preauthId + "-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss"), preauthId);
                if (!initRes.Initiated)
                {
                    Console.WriteLine($"# Could not initiate preauth request: {initRes.Message}. Please Retry.");
                }
                break;

            case "preauth_cancel":
                preauthId = spInput[1];
                initRes   = _spiPreauth.InitiateCancelTx("prtopd-" + preauthId + "-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss"), preauthId);
                if (!initRes.Initiated)
                {
                    Console.WriteLine($"# Could not initiate preauth request: {initRes.Message}. Please Retry.");
                }
                break;

            case "preauth_complete":
                preauthId = spInput[1];
                initRes   = _spiPreauth.InitiateCompletionTx("prcomp-" + preauthId + "-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss"), preauthId, int.Parse(spInput[2]));
                if (!initRes.Initiated)
                {
                    Console.WriteLine($"# Could not initiate preauth request: {initRes.Message}. Please Retry.");
                }
                break;

            case "pos_id":
                Console.Clear();
                if (_spi.SetPosId(spInput[1]))
                {
                    _posId = spInput[1];
                    Console.WriteLine($"## -> POS ID now set to {_posId}");
                }
                else
                {
                    Console.WriteLine($"## -> Could not set POS ID");
                };
                PrintStatusAndActions();
                Console.Write("> ");
                break;

            case "eftpos_address":
                Console.Clear();
                if (_spi.SetEftposAddress(spInput[1]))
                {
                    _eftposAddress = spInput[1];
                    Console.WriteLine($"## -> Eftpos Address now set to {_eftposAddress}");
                }
                else
                {
                    Console.WriteLine($"## -> Could not set Eftpos Address");
                };
                PrintStatusAndActions();
                Console.Write("> ");
                break;

            case "pair":
                var pairingInited = _spi.Pair();
                if (!pairingInited)
                {
                    Console.WriteLine($"## -> Could not Start Pairing. Check Settings.");
                }
                break;

            case "pair_cancel":
                _spi.PairingCancel();
                break;

            case "pair_confirm":
                _spi.PairingConfirmCode();
                break;

            case "unpair":
                _spi.Unpair();
                break;

            case "glt":
                var gltres = _spi.InitiateGetLastTx();
                Console.WriteLine(gltres.Initiated ? "# GLT Initiated. Will be updated with Progress." : $"# Could not initiate GLT: {gltres.Message}. Please Retry.");
                break;

            case "tx_sign_accept":
                _spi.AcceptSignature(true);
                break;

            case "tx_sign_decline":
                _spi.AcceptSignature(false);
                break;

            case "tx_cancel":
                _spi.CancelTransaction();
                break;

            case "settle":
                var settleres = _spi.InitiateSettleTx(RequestIdHelper.Id("settle"));
                if (!settleres.Initiated)
                {
                    Console.WriteLine($"# Could not initiate settlement: {settleres.Message}. Please Retry.");
                }
                break;

            case "ok":
                Console.Clear();
                _spi.AckFlowEndedAndBackToIdle();
                PrintStatusAndActions();
                Console.Write("> ");
                break;

            case "recover":
                Console.Clear();
                var rres = _spi.InitiateRecovery(spInput[1], TransactionType.Purchase);
                if (!rres.Initiated)
                {
                    Console.WriteLine($"# Could not initiate recovery. {rres.Message}. Please Retry.");
                }
                break;

            case "status":
                Console.Clear();
                PrintStatusAndActions();
                break;

            case "bye":
                return(true);

            case "":
                Console.Write("> ");
                break;

            default:
                Console.WriteLine("# I don't understand. Sorry.");
                break;
            }
            return(false);
        }
Ejemplo n.º 3
0
        private void AcceptUserInput()
        {
            var bye = false;

            while (!bye)
            {
                var input = Console.ReadLine();
                if (input == null)
                {
                    continue;
                }
                var spInput = input.Split(':');
                switch (spInput[0])
                {
                case "pizza":
                    var pres = _spi.InitiatePurchaseTx(RequestIdHelper.Id("pizza"), 1000);
                    if (!pres.Initiated)
                    {
                        Console.WriteLine($"# Could not initiate purchase: {pres.Message}. Please Retry.");
                    }
                    break;

                case "yuck":
                    var yuckres = _spi.InitiateRefundTx(RequestIdHelper.Id("yuck"), 1000);
                    if (!yuckres.Initiated)
                    {
                        Console.WriteLine($"# Could not initiate refund: {yuckres.Message}. Please Retry.");
                    }
                    break;

                case "pos_id":
                    Console.Clear();
                    if (_spi.SetPosId(spInput[1]))
                    {
                        _posId = spInput[1];
                        Console.WriteLine($"## -> POS ID now set to {_posId}");
                    }
                    else
                    {
                        Console.WriteLine($"## -> Could not set POS ID");
                    }
                    PrintStatusAndActions();
                    Console.Write("> ");
                    break;

                case "eftpos_address":
                    Console.Clear();
                    if (_spi.SetEftposAddress(spInput[1]))
                    {
                        _eftposAddress = spInput[1];
                        Console.WriteLine($"## -> Eftpos Address now set to {_eftposAddress}");
                    }
                    else
                    {
                        Console.WriteLine($"## -> Could not set Eftpos Address");
                    }
                    PrintStatusAndActions();
                    Console.Write("> ");
                    break;

                case "pair":
                    _spi.Pair();
                    break;

                case "pair_cancel":
                    _spi.PairingCancel();
                    break;

                case "pair_confirm":
                    _spi.PairingConfirmCode();
                    break;

                case "unpair":
                    _spi.Unpair();
                    break;

                case "tx_sign_accept":
                    _spi.AcceptSignature(true);
                    break;

                case "tx_sign_decline":
                    _spi.AcceptSignature(false);
                    break;

                case "tx_cancel":
                    _spi.CancelTransaction();
                    break;

                case "settle":
                    var settleres = _spi.InitiateSettleTx(RequestIdHelper.Id("settle"));
                    if (!settleres.Initiated)
                    {
                        Console.WriteLine($"# Could not initiate settlement: {settleres.Message}. Please Retry.");
                    }
                    break;

                case "ok":
                    Console.Clear();
                    _spi.AckFlowEndedAndBackToIdle();
                    PrintStatusAndActions();
                    Console.Write("> ");
                    break;

                case "status":
                    Console.Clear();
                    PrintStatusAndActions();
                    break;

                case "bye":
                    bye = true;
                    break;

                case "":
                    Console.Write("> ");
                    break;

                default:
                    Console.WriteLine("# I don't understand. Sorry.");
                    break;
                }
            }
            Console.WriteLine("# BaBye!");
            if (_spiSecrets != null)
            {
                Console.WriteLine($"{_posId}:{_eftposAddress}:{_spiSecrets.EncKey}:{_spiSecrets.HmacKey}");
            }
        }
Ejemplo n.º 4
0
        private void StartHammering()
        {
            if (_hammering)
            {
                Console.WriteLine("Already Hammering.");
            }

            _txAttempts           = 0;
            _disconnects          = 0;
            _reconnects           = 0;
            _lastConnect          = DateTime.Now;
            _lastDisconnect       = DateTime.Now;
            _connectedDuration    = TimeSpan.Zero;
            _disconnectedDuration = TimeSpan.Zero;
            _txSuccesses          = new Dictionary <Message.SuccessState, int>();

            var tmt = new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                while (_hammering)
                {
                    Console.WriteLine("Initing a purchase");
                    _spi.InitiatePurchaseTx(RequestIdHelper.Id("prchs"), 1000);
                    _txAttempts += 1;
                    do
                    {
                        Thread.Sleep(1000);
                    } while (!_spi.CurrentTxFlowState.Finished);
                    Console.WriteLine("purchase finished");
                    if (_txSuccesses.ContainsKey(_spi.CurrentTxFlowState.Success))
                    {
                        _txSuccesses[_spi.CurrentTxFlowState.Success] += 1;
                    }
                    else
                    {
                        _txSuccesses[_spi.CurrentTxFlowState.Success] = 1;
                    }
                    _spi.AckFlowEndedAndBackToIdle();

                    if (!_hammering)
                    {
                        continue;
                    }
                    var delay = RandomGen.Next(_minTxGap, _maxTxGap);
                    PrintHammerStats();
                    Console.WriteLine($"Sleeping {delay}ms before next transaction");
                    Thread.Sleep(delay);
                }

                if (_spi.CurrentStatus == SpiStatus.PairedConnected)
                {
                    _connectedDuration = _connectedDuration.Add(DateTime.Now.Subtract(_lastConnect));
                }
                else
                {
                    _disconnectedDuration = _disconnectedDuration.Add(DateTime.Now.Subtract(_lastDisconnect));
                }
                Console.WriteLine("Stopped Hammering.");
                Log.Info("Stopped Hammering.");
                PrintHammerStats();

                // Log into app log as well.
                Log.Info($"Attempts {_txAttempts}");
                Log.Info($"Disconnects {_disconnects}");
                Log.Info($"Reconnects {_reconnects}");
                Log.Info($"Time Connected {_connectedDuration}");
                Log.Info($"Time Diconnected {_disconnectedDuration}");
                Log.InfoFormat("Successes {0}", (_txSuccesses.ContainsKey(Message.SuccessState.Success)) ? _txSuccesses[Message.SuccessState.Success] : 0);
                Log.InfoFormat("Failures {0}", (_txSuccesses.ContainsKey(Message.SuccessState.Failed)) ? _txSuccesses[Message.SuccessState.Failed] : 0);
                Log.InfoFormat("Unknowns {0}", (_txSuccesses.ContainsKey(Message.SuccessState.Unknown)) ? _txSuccesses[Message.SuccessState.Unknown] : 0);
            });

            _hammering = true;
            Console.WriteLine("Starting Hammering.");
            Log.Info("Starting Hammering.");
            tmt.Start();
        }