コード例 #1
0
        public void GetSchemeSettlementEntries_OnValidResponse_ReturnCount()
        {
            // arrange
            var          stlEnqMsg            = new SettlementEnquiryRequest(RequestIdHelper.Id("stlenq")).ToMessage();
            var          transactionFlowState = new TransactionFlowState("1", TransactionType.SettlementEnquiry, 0, stlEnqMsg, $"Waiting for EFTPOS connection to make a settlement enquiry");
            var          secrets = SpiClientTestUtils.SetTestSecrets();
            const string jsonStr = @"{""message"":{""data"":{""accumulacxted_purchase_count"":""1"",""accumulated_purchase_value"":""1000"",""accumulated_settle_by_acquirer_count"":""1"",""accumulated_settle_by_acquirer_value"":""1000"",""accumulated_total_count"":""1"",""accumulated_total_value"":""1000"",""bank_date"":""14062019"",""bank_time"":""160940"",""host_response_code"":""941"",""host_response_text"":""CUTOVER COMPLETE"",""merchant_acquirer"":""EFTPOS FROM BANK SA"",""merchant_address"":""213 Miller Street"",""merchant_city"":""Sydney"",""merchant_country"":""Australia"",""merchant_name"":""Merchant4"",""merchant_postcode"":""2060"",""merchant_receipt"":""EFTPOS FROM BANK SA\r\nMerchant4\r\n213 Miller Street\r\nSydney 2060\r\n\r\nAustralia\r\n\r\n\r\n SETTLEMENT CUTOVER\r\nTSP     100612348842\r\nTIME   14JUN19 16:09\r\nTRAN   001137-001137\r\nFROM   13JUN19 20:00\r\nTO     14JUN19 16:09\r\n\r\nDebit\r\nTOT     0      $0.00\r\n\r\nMasterCard\r\nTOT     0      $0.00\r\n\r\nVisa\r\nPUR     1     $10.00\r\nTOT     1     $10.00\r\n\r\nBANKED  1     $10.00\r\n\r\nAmex\r\nTOT     0      $0.00\r\n\r\nDiners\r\nTOT     0      $0.00\r\n\r\nJCB\r\nTOT     0      $0.00\r\n\r\nUnionPay\r\nTOT     0      $0.00\r\n\r\nTOTAL\r\nPUR     1     $10.00\r\nTOT     1     $10.00\r\n\r\n (941) CUTOVER COMP\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"",""schemes"":[{""scheme_name"":""Debit"",""settle_by_acquirer"":""Yes"",""total_count"":""0"",""total_value"":""0""},{""scheme_name"":""MasterCard"",""settle_by_acquirer"":""Yes"",""total_count"":""0"",""total_value"":""0""},{""scheme_name"":""Visa"",""settle_by_acquirer"":""Yes"",""total_count"":""1"",""total_purchase_count"":""1"",""total_purchase_value"":""1000"",""total_value"":""1000""},{""scheme_name"":""Amex"",""settle_by_acquirer"":""No"",""total_count"":""0"",""total_value"":""0""},{""scheme_name"":""Diners"",""settle_by_acquirer"":""No"",""total_count"":""0"",""total_value"":""0""},{""scheme_name"":""JCB"",""settle_by_acquirer"":""No"",""total_count"":""0"",""total_value"":""0""},{""scheme_name"":""UnionPay"",""settle_by_acquirer"":""No"",""total_count"":""0"",""total_value"":""0""}],""settlement_period_end_date"":""14Jun19"",""settlement_period_end_time"":""16:09"",""settlement_period_start_date"":""13Jun19"",""settlement_period_start_time"":""20:00"",""settlement_triggered_date"":""14Jun19"",""settlement_triggered_time"":""16:09:40"",""stan"":""000000"",""success"":true,""terminal_id"":""100612348842"",""transaction_range"":""001137-001137""},""datetime"":""2019-06-14T16:09:46.395"",""event"":""settle_response"",""id"":""settle116""}}";

            // act
            var msg = Message.FromJson(jsonStr, secrets);

            transactionFlowState.Response = msg;
            var comWrapper     = new ComWrapper();
            var schemeArray    = comWrapper.GetSchemeSettlementEntries(transactionFlowState);
            var settleResponse = new Settlement(transactionFlowState.Response);
            var schemes        = settleResponse.GetSchemeSettlementEntries();
            var schemeList     = new List <SchemeSettlementEntry>();

            foreach (var s in schemes)
            {
                schemeList.Add(s);
            }

            // assert
            Assert.Equal(schemeArray.ToList().Count, schemeList.Count);
        }
コード例 #2
0
        public void TransactionFlowState_OnValidRequestGotGltResponse_ReturnObject()
        {
            // arrange
            var stlEnqMsg            = new SettlementEnquiryRequest(RequestIdHelper.Id("stlenq")).ToMessage();
            var transactionFlowState = new TransactionFlowState("1", TransactionType.SettlementEnquiry, 0, stlEnqMsg, $"Waiting for EFTPOS connection to make a settlement enquiry");

            // act
            transactionFlowState.GotGltResponse();

            // assert
            Assert.False(transactionFlowState.AwaitingGltResponse);
        }
コード例 #3
0
        public void TransactionFlowState_OnValidRequestCancelFailed_ReturnObjects()
        {
            // arrange
            var stlEnqMsg            = new SettlementEnquiryRequest(RequestIdHelper.Id("stlenq")).ToMessage();
            var transactionFlowState = new TransactionFlowState("1", TransactionType.SettlementEnquiry, 0, stlEnqMsg, $"Waiting for EFTPOS connection to make a settlement enquiry");

            // act
            transactionFlowState.CancelFailed("CancelFailed");

            // assert
            Assert.False(transactionFlowState.AttemptingToCancel);
            Assert.Equal("CancelFailed", transactionFlowState.DisplayMessage);
        }
コード例 #4
0
        public void TransactionFlowState_OnValidRequestAuthCodeSent_ReturnObjects()
        {
            // arrange
            var stlEnqMsg            = new SettlementEnquiryRequest(RequestIdHelper.Id("stlenq")).ToMessage();
            var transactionFlowState = new TransactionFlowState("1", TransactionType.SettlementEnquiry, 0, stlEnqMsg, $"Waiting for EFTPOS connection to make a settlement enquiry");

            // act
            transactionFlowState.AuthCodeSent("AuthCodeSent");

            // assert
            Assert.False(transactionFlowState.AwaitingPhoneForAuth);
            Assert.Equal("AuthCodeSent", transactionFlowState.DisplayMessage);
        }
コード例 #5
0
        public void TransactionFlowState_OnValidRequestCallingGlt_ReturnObjects()
        {
            // arrange
            var stlEnqMsg            = new SettlementEnquiryRequest(RequestIdHelper.Id("stlenq")).ToMessage();
            var transactionFlowState = new TransactionFlowState("1", TransactionType.SettlementEnquiry, 0, stlEnqMsg, $"Waiting for EFTPOS connection to make a settlement enquiry");

            // act
            transactionFlowState.CallingGlt("25");

            // assert
            Assert.True(transactionFlowState.AwaitingGltResponse);
            Assert.NotNull(transactionFlowState.LastStateRequestTime);
            Assert.Equal("25", transactionFlowState.LastGltRequestId);
        }
コード例 #6
0
        public void TransactionFlowState_OnValidRequestFailed_ReturnObjects()
        {
            // arrange
            var stlEnqMsg            = new SettlementEnquiryRequest(RequestIdHelper.Id("stlenq")).ToMessage();
            var transactionFlowState = new TransactionFlowState("1", TransactionType.SettlementEnquiry, 0, stlEnqMsg, $"Waiting for EFTPOS connection to make a settlement enquiry");

            // act
            transactionFlowState.Failed(stlEnqMsg, "Failed");

            // assert
            Assert.Equal(stlEnqMsg, transactionFlowState.Response);
            Assert.True(transactionFlowState.Finished);
            Assert.Equal(Message.SuccessState.Failed, transactionFlowState.Success);
            Assert.Equal("Failed", transactionFlowState.DisplayMessage);
        }
コード例 #7
0
        public void TransactionFlowState_OnValidState_ReturnObjects()
        {
            // arrange
            var stlEnqMsg = new SettlementEnquiryRequest(RequestIdHelper.Id("stlenq")).ToMessage();

            // act
            var transactionFlowState = new TransactionFlowState("1", TransactionType.SettlementEnquiry, 0, stlEnqMsg, $"Waiting for EFTPOS connection to make a settlement enquiry");

            // assert
            Assert.Equal("1", transactionFlowState.PosRefId);
            Assert.Equal("1", transactionFlowState.Id);
            Assert.Equal(TransactionType.SettlementEnquiry, transactionFlowState.Type);
            Assert.Equal(0, transactionFlowState.AmountCents);
            Assert.False(transactionFlowState.AwaitingSignatureCheck);
            Assert.False(transactionFlowState.RequestSent);
            Assert.False(transactionFlowState.Finished);
            Assert.Equal(Message.SuccessState.Unknown, transactionFlowState.Success);
            Assert.Equal($"Waiting for EFTPOS connection to make a settlement enquiry", transactionFlowState.DisplayMessage);
        }
コード例 #8
0
        private void btnSettle_Click(object sender, EventArgs e)
        {
            ActionsForm.btnAction1.Visible  = false;
            ActionsForm.btnAction2.Visible  = false;
            ActionsForm.btnAction3.Visible  = false;
            ActionsForm.lblAction1.Visible  = false;
            ActionsForm.txtAction1.Visible  = false;
            ActionsForm.lblAction2.Visible  = false;
            ActionsForm.txtAction2.Visible  = false;
            ActionsForm.lblAction3.Visible  = false;
            ActionsForm.txtAction3.Visible  = false;
            ActionsForm.lblAction4.Visible  = false;
            ActionsForm.txtAction4.Visible  = false;
            ActionsForm.cboxAction1.Visible = false;
            TransactionForm.Enabled         = false;

            var settleRes = SpiClient.InitiateSettleTx(RequestIdHelper.Id("settle"), Options);

            ActionsForm.listBoxFlow.Items.Add(settleRes.Initiated ? "# Settle Initiated. Will be updated with Progress." : "# Could not initiate settlement: " + settleRes.Message + ". Please Retry.");
            ActionsForm.Show();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: metinavc1/spi-samples-cs
        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);
        }
コード例 #10
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}");
            }
        }
コード例 #11
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);
        }
コード例 #12
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();
        }
コード例 #13
0
 public static Message GeneratePingRequest()
 {
     return(new Message(RequestIdHelper.Id("ping"), Events.Ping, null, true));
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: metinavc1/spi-samples-cs
        private void AcceptUserInput()
        {
            var bye = false;

            while (!bye)
            {
                var input   = Console.ReadLine();
                var spInput = input.Split(':');
                switch (spInput[0].ToLower())
                {
                case "open":
                    if (!CheckInput(spInput, 2))
                    {
                        break;
                    }
                    ;
                    var label = "";
                    if (spInput.Length > 3)
                    {
                        label = spInput[3];
                    }
                    OpenTable(spInput[1], spInput[2], label);
                    Console.Write("> ");
                    break;

                case "close":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    CloseTable(spInput[1]);
                    Console.Write("> ");
                    break;

                case "locked":
                    if (!CheckInput(spInput, 2))
                    {
                        break;
                    }
                    ;
                    var isLock = false;
                    bool.TryParse(spInput[2], out isLock);
                    LockTable(spInput[1], isLock);
                    Console.Write("> ");
                    break;

                case "add":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    AddToTable(spInput[1], int.Parse(spInput[2]));
                    Console.Write("> ");
                    break;

                case "table":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    PrintTable(spInput[1]);
                    Console.Write("> ");
                    break;

                case "bill":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    PrintBill(spInput[1]);
                    Console.Write("> ");
                    break;

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

                case "purchase":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    var pres = _spi.InitiatePurchaseTxV2("purchase-" + DateTime.Now.ToString("o"), int.Parse(spInput[1]), 0, 0, false);
                    if (!pres.Initiated)
                    {
                        Console.WriteLine($"# Could not initiate purchase: {pres.Message}. Please Retry.");
                    }
                    break;

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

                case "pos_id":
                    Console.Clear();
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    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 (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    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 "pat_enabled":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    bool output = false;
                    bool.TryParse(spInput[1], out output);
                    _pat.Config.PayAtTableEnabled = output;
                    _pat.PushPayAtTableConfig();
                    Console.Write("> ");
                    break;

                case "pat_all_enable":
                    EnablePayAtTableConfigs();
                    _pat.PushPayAtTableConfig();
                    Console.Write("> ");
                    break;

                case "operatorid_enabled":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    output = false;
                    bool.TryParse(spInput[1], out output);
                    _pat.Config.OperatorIdEnabled = output;
                    _pat.PushPayAtTableConfig();
                    Console.Write("> ");
                    break;

                case "equal_split":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    output = false;
                    bool.TryParse(spInput[1], out output);
                    _pat.Config.EqualSplitEnabled = output;
                    _pat.PushPayAtTableConfig();
                    Console.Write("> ");
                    break;

                case "split_by_amount":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    output = false;
                    bool.TryParse(spInput[1], out output);
                    _pat.Config.SplitByAmountEnabled = output;
                    _pat.PushPayAtTableConfig();
                    Console.Write("> ");
                    break;

                case "tipping":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    output = false;
                    bool.TryParse(spInput[1], out output);
                    _pat.Config.TippingEnabled = output;
                    _pat.PushPayAtTableConfig();
                    Console.Write("> ");
                    break;

                case "summary_report":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    output = false;
                    bool.TryParse(spInput[1], out output);
                    _pat.Config.SummaryReportEnabled = output;
                    _pat.PushPayAtTableConfig();
                    Console.Write("> ");
                    break;

                case "set_allowed_operatorid":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    allowedOperatorIdList.Add(spInput[1]);
                    _pat.Config.AllowedOperatorIds = allowedOperatorIdList;
                    _pat.PushPayAtTableConfig();
                    Console.Write("> ");
                    break;

                case "set_label_operatorid":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    _pat.Config.LabelOperatorId = spInput[1];
                    _pat.PushPayAtTableConfig();
                    Console.Write("> ");
                    break;

                case "set_label_tableid":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    _pat.Config.LabelTableId = spInput[1];
                    _pat.PushPayAtTableConfig();
                    Console.Write("> ");
                    break;

                case "set_label_paybutton":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    _pat.Config.LabelPayButton = spInput[1];
                    _pat.PushPayAtTableConfig();
                    Console.Write("> ");
                    break;

                case "table_retrieval_enabled":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    output = false;
                    bool.TryParse(spInput[1], out output);
                    _pat.Config.TableRetrievalEnabled = output;
                    _pat.PushPayAtTableConfig();
                    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 "settle":
                    var settleres = _spi.InitiateSettleTx(RequestIdHelper.Id("settle"));
                    if (!settleres.Initiated)
                    {
                        Console.WriteLine($"# Could not initiate settlement: {settleres.Message}. Please Retry.");
                    }
                    break;

                case "print_merchant_copy":
                    _spi.Config.PrintMerchantCopy = spInput[1].ToLower() == "true";
                    Console.Write("> ");
                    break;

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

                case "sig_flow_from_eftpos":
                    _spi.Config.SignatureFlowOnEftpos = spInput[1].ToLower() == "true";
                    Console.Write("> ");
                    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.");
                    Console.Write("> ");
                    break;
                }
            }
            Console.WriteLine("# BaBye!");
            PersistState();
            if (_spiSecrets != null)
            {
                Console.WriteLine($"{_posId}:{_eftposAddress}:{_spiSecrets.EncKey}:{_spiSecrets.HmacKey}");
            }
        }
コード例 #15
0
        private void AcceptUserInput()
        {
            var bye = false;

            while (!bye)
            {
                var input   = Console.ReadLine();
                var spInput = input.Split(':');
                switch (spInput[0].ToLower())
                {
                case "open":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    openTable(spInput[1]); Console.Write("> ");
                    break;

                case "close":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    closeTable(spInput[1]); Console.Write("> ");
                    break;

                case "add":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    addToTable(spInput[1], int.Parse(spInput[2])); Console.Write("> ");
                    break;

                case "table":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    printTable(spInput[1]); Console.Write("> ");
                    break;

                case "bill":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    printBill(spInput[1]); Console.Write("> ");
                    break;

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

                case "purchase":
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    var pres = _spi.InitiatePurchaseTxV2("purchase-" + DateTime.Now.ToString("o"), int.Parse(spInput[1]), 0, 0, false);
                    if (!pres.Initiated)
                    {
                        Console.WriteLine($"# Could not initiate purchase: {pres.Message}. Please Retry.");
                    }
                    break;

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

                case "pos_id":
                    Console.Clear();
                    if (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    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 (!CheckInput(spInput, 1))
                    {
                        break;
                    }
                    ;
                    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 "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.");
                    Console.Write("> ");
                    break;
                }
            }
            Console.WriteLine("# BaBye!");
            PersistState();
            if (_spiSecrets != null)
            {
                Console.WriteLine($"{_posId}:{_eftposAddress}:{_spiSecrets.EncKey}:{_spiSecrets.HmacKey}");
            }
        }