Ejemplo n.º 1
0
        public void CancelTransactionResponse_OnValidResponse_ReturnObjects()
        {
            // arrange
            var          secrets = SpiClientTestUtils.SetTestSecrets();
            const string jsonStr = @"{""message"": {""event"": ""cancel_response"", ""id"": ""0"", ""datetime"": ""2018-02-06T15:16:44.094"", ""data"": {""pos_ref_id"": ""123456abc"", ""success"": false, ""error_reason"": ""TXN_PAST_POINT_OF_NO_RETURN"", ""error_detail"":""Txn has passed the point of no return"" }}}";

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

            // assert
            Assert.Equal("cancel_response", msg.EventName);
            Assert.False(response.Success);
            Assert.Equal("123456abc", response.PosRefId);
            Assert.Equal("TXN_PAST_POINT_OF_NO_RETURN", response.GetErrorReason());
            Assert.True(response.WasTxnPastPointOfNoReturn());
            Assert.NotNull(response.GetErrorDetail());
            Assert.Equal(response.GetResponseValueWithAttribute("pos_ref_id"), response.PosRefId);

            // act
            response = new CancelTransactionResponse();

            // assert
            Assert.Null(SpiClientTestUtils.GetInstanceField(response.GetType(), response, "_m"));
            Assert.Null(response.PosRefId);
        }
Ejemplo n.º 2
0
        public void SpiPayAtTable_OnValidRequest_ReturnStatus()
        {
            // arrange
            var spi = new Spi();

            // act
            var spiPay = new SpiPayAtTable(spi);

            // assert
            Assert.NotNull(spiPay.Config);

            // act
            var spi2 = (Spi)SpiClientTestUtils.GetInstanceField(spiPay.GetType(), spiPay, "_spi");

            // assert
            Assert.Equal(spi.CurrentStatus, spi2.CurrentStatus);

            // arrange
            spiPay = new SpiPayAtTable();

            // act
            var spi3 = (Spi)SpiClientTestUtils.GetInstanceField(spiPay.GetType(), spiPay, "_spi");

            // assert
            Assert.Null(spi3);
        }
Ejemplo n.º 3
0
        public void RetriesBeforeResolvingDeviceAddress_OnValidValue_Checked()
        {
            // arrange
            const int retriesBeforeResolvingDeviceAddress = 3;

            // act
            Spi spi = new Spi();

            // assert
            Assert.Equal(retriesBeforeResolvingDeviceAddress, SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_retriesBeforeResolvingDeviceAddress"));
        }
Ejemplo n.º 4
0
        public void SleepBeforeReconnectMs_OnValidValue_Checked()
        {
            // arrange
            const int sleepBeforeReconnectMs = 3000;

            // act
            Spi spi = new Spi();

            // assert
            Assert.Equal(sleepBeforeReconnectMs, SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_sleepBeforeReconnectMs"));
        }
Ejemplo n.º 5
0
        public void RetriesBeforePairing_OnValidValue_Checked()
        {
            // arrange
            const int retriesBeforePairing = 3;

            // act
            Spi spi = new Spi();

            // assert
            Assert.Equal(retriesBeforePairing, SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_retriesBeforePairing"));
        }
Ejemplo n.º 6
0
        public void SpiInitiate_OnValidCharactersForPosId_IsSet()
        {
            // arrange
            const string posId         = "RamenPos@";
            const string eftposAddress = "10.20.30.40";

            // act
            var spi   = new Spi(posId, "", eftposAddress, null);
            var value = SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_posId");

            // assert
            Assert.NotEqual("", value);
        }
Ejemplo n.º 7
0
        public void SpiInitate_OnValidCharactersForEftposAddress_IsSet()
        {
            // arrange
            const string eftposAddress = "10.20.30.40";
            const string posId         = "DummyPos";

            // act
            var spi   = new Spi(posId, "", eftposAddress, null);
            var value = SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_eftposAddress").ToString().Replace("ws://", "");

            // assert
            Assert.Equal(eftposAddress, value);
        }
Ejemplo n.º 8
0
        public void SetPosId_OnValidCharacters_IsSet()
        {
            // arrange
            const string posId         = "RamenPos";
            const string eftposAddress = "10.20.30.40";
            var          spi           = new Spi(posId, "", eftposAddress, null);

            // act
            spi.SetPosId(posId);
            var value = SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_posId");

            // assert
            Assert.Equal(posId, value);
        }
Ejemplo n.º 9
0
        public void SetPosId_OnInvalidLength_IsSet()
        {
            // arrange
            const string posId         = "12345678901234567";
            const string eftposAddress = "10.20.30.40";
            var          spi           = new Spi(posId, "", eftposAddress, null);

            // act
            spi.SetPosId(posId);
            var value = SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_posId");

            // assert
            Assert.NotEqual("", value);
        }
Ejemplo n.º 10
0
        public void SetAutoAddressResolution_TurnOnAutoAddress_Enabled()
        {
            // arrange
            const bool autoAddressResolutionEnable = true;
            var        spi = new Spi("", "", "", null);

            SpiClientTestUtils.SetInstanceField(spi, "_currentStatus", SpiStatus.Unpaired);

            // act
            spi.SetAutoAddressResolution(autoAddressResolutionEnable);

            // assert
            Assert.Equal(autoAddressResolutionEnable, SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_autoAddressResolutionEnabled"));
        }
Ejemplo n.º 11
0
        public void SetSerialNumber_ValidSerialNumber_IsSet()
        {
            // arrange
            const string serialNumber = "111-111-111";
            var          spi          = new Spi("", "", "", null);

            SpiClientTestUtils.SetInstanceField(spi, "_currentStatus", SpiStatus.Unpaired);

            // act
            spi.SetSerialNumber(serialNumber);

            // assert
            Assert.Equal(serialNumber, SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_serialNumber"));
        }
Ejemplo n.º 12
0
        public void PurchaseResponse_OnValidResponse_ReturnObjects()
        {
            // arrange
            var          secrets = SpiClientTestUtils.SetTestSecrets();
            const string jsonStr = @"{""message"":{""data"":{""account_type"":""SAVINGS"",""auth_code"":""278045"",""bank_cash_amount"":200,""bank_date"":""06062019"",""bank_noncash_amount"":1200,""bank_settlement_date"":""06062019"",""bank_time"":""110750"",""card_entry"":""MAG_STRIPE"",""cash_amount"":200,""currency"":""AUD"",""customer_receipt"":""EFTPOS FROM BANK SA\r\nMerchant4\r\n213 Miller Street\r\nSydney 2060\r\nAustralia\r\n\r\nTIME 06JUN19   11:07\r\nMID         22341842\r\nTSP     100612348842\r\nRRN     190606001102\r\nDebit(S)         SAV\r\nCARD............5581\r\nAUTH          278045\r\n\r\nPURCHASE    AUD10.00\r\nCASH         AUD2.00\r\nSURCHARGE    AUD2.00\r\nTOTAL       AUD14.00\r\n\r\n   (000) APPROVED\r\n\r\n  *CUSTOMER COPY*\r\n\r\n\r\n\r\n\r\n\r\n\r\n"",""customer_receipt_printed"":false,""expiry_date"":""0822"",""host_response_code"":""000"",""host_response_text"":""APPROVED"",""informative_text"":""                "",""masked_pan"":""............5581"",""merchant_acquirer"":""EFTPOS FROM BANK SA"",""merchant_addr"":""213 Miller Street"",""merchant_city"":""Sydney"",""merchant_country"":""Australia"",""merchant_id"":""22341842"",""merchant_name"":""Merchant4"",""merchant_postcode"":""2060"",""merchant_receipt"":""EFTPOS FROM BANK SA\r\nMerchant4\r\n213 Miller Street\r\nSydney 2060\r\nAustralia\r\n\r\nTIME 06JUN19   11:07\r\nMID         22341842\r\nTSP     100612348842\r\nRRN     190606001102\r\nDebit(S)         SAV\r\nCARD............5581\r\nAUTH          278045\r\n\r\nPURCHASE    AUD10.00\r\nCASH         AUD2.00\r\nSURCHARGE    AUD2.00\r\nTOTAL       AUD14.00\r\n\r\n   (000) APPROVED\r\n\r\n\r\n\r\n\r\n\r\n\r\n"",""merchant_receipt_printed"":false,""online_indicator"":""Y"",""pos_ref_id"":""prchs-06-06-2019-11-07-50"",""purchase_amount"":1000,""rrn"":""190606001102"",""scheme_name"":""Debit"",""stan"":""001102"",""success"":true,""surcharge_amount"":200,""terminal_id"":""100612348842"",""terminal_ref_id"":""12348842_06062019110812"",""transaction_type"":""PURCHASE""},""datetime"":""2019-06-06T11:08:12.946"",""event"":""purchase_response"",""id"":""prchs5""}}";

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

            // assert
            Assert.Equal("purchase_response", msg.EventName);
            Assert.True(response.Success);
            Assert.Equal("prchs5", response.RequestId);
            Assert.Equal("prchs-06-06-2019-11-07-50", response.PosRefId);
            Assert.Equal("Debit", response.SchemeName);
            Assert.Equal("190606001102", response.GetRRN());
            Assert.Equal(1000, response.GetPurchaseAmount());
            Assert.Equal(200, response.GetCashoutAmount());
            Assert.Equal(0, response.GetTipAmount());
            Assert.Equal(200, response.GetSurchargeAmount());
            Assert.Equal(1200, response.GetBankNonCashAmount());
            Assert.Equal(200, response.GetBankCashAmount());
            Assert.NotNull(response.GetCustomerReceipt());
            Assert.NotNull(response.GetMerchantReceipt());
            Assert.Equal("APPROVED", response.GetResponseText());
            Assert.Equal("000", response.GetResponseCode());
            Assert.Equal("12348842_06062019110812", response.GetTerminalReferenceId());
            Assert.Equal("MAG_STRIPE", response.GetCardEntry());
            Assert.Equal("SAVINGS", response.GetAccountType());
            Assert.Equal("278045", response.GetAuthCode());
            Assert.Equal("06062019", response.GetBankDate());
            Assert.Equal("110750", response.GetBankTime());
            Assert.Equal("............5581", response.GetMaskedPan());
            Assert.Equal("100612348842", response.GetTerminalId());
            Assert.False(response.WasCustomerReceiptPrinted());
            Assert.False(response.WasMerchantReceiptPrinted());
            Assert.Equal(DateTime.ParseExact(msg.GetDataStringValue("bank_settlement_date"), "ddMMyyyy", CultureInfo.InvariantCulture).Date, response.GetSettlementDate());
            Assert.Equal(response.GetResponseValue("pos_ref_id"), response.PosRefId);

            // act
            response = new PurchaseResponse();

            // assert
            Assert.Null(SpiClientTestUtils.GetInstanceField(response.GetType(), response, "_m"));
            Assert.Null(response.PosRefId);
        }
Ejemplo n.º 13
0
        public void SetEftposAddress_OnValidCharacters_IsSet()
        {
            // arrange
            const string eftposAddress = "10.20.30.40";
            var          spi           = new Spi();
            var          conn          = new Connection();

            SpiClientTestUtils.SetInstanceField(spi, "_currentStatus", SpiStatus.Unpaired);
            SpiClientTestUtils.SetInstanceField(spi, "_conn", conn);

            // act
            spi.SetEftposAddress(eftposAddress);
            var value = SpiClientTestUtils.GetInstanceField(typeof(Spi), spi, "_eftposAddress").ToString().Replace("ws://", "");

            // assert
            Assert.Equal(eftposAddress, value);
        }
Ejemplo n.º 14
0
        public void RefundResponse_OnValidResponse_ReturnObjects()
        {
            // arrange
            var          secrets = SpiClientTestUtils.SetTestSecrets();
            const string jsonStr = @"{""message"":{""data"":{""account_type"":""CREDIT"",""auth_code"":""067849"",""bank_date"":""06062019"",""bank_noncash_amount"":1000,""bank_settlement_date"":""06062019"",""bank_time"":""114905"",""card_entry"":""EMV_CTLS"",""currency"":""AUD"",""customer_receipt"":""EFTPOS FROM BANK SA\r\nMerchant4\r\n213 Miller Street\r\nSydney 2060\r\nAustralia\r\n\r\nTIME 06JUN19   11:49\r\nMID         22341842\r\nTSP     100612348842\r\nRRN     190606001105\r\nVisa(C)           CR\r\nCARD............5581\r\nAUTH          067849\r\n\r\nREFUND      AUD10.00\r\n\r\n   (000) APPROVED\r\n\r\n  *CUSTOMER COPY*\r\n\r\n\r\n\r\n\r\n\r\n\r\n"",""customer_receipt_printed"":false,""emv_actioncode"":""ARQ"",""emv_actioncode_values"":""67031BCC5AD15818"",""expiry_date"":""0822"",""host_response_code"":""000"",""host_response_text"":""APPROVED"",""informative_text"":""                "",""masked_pan"":""............5581"",""merchant_acquirer"":""EFTPOS FROM BANK SA"",""merchant_addr"":""213 Miller Street"",""merchant_city"":""Sydney"",""merchant_country"":""Australia"",""merchant_id"":""22341842"",""merchant_name"":""Merchant4"",""merchant_postcode"":""2060"",""merchant_receipt"":""EFTPOS FROM BANK SA\r\nMerchant4\r\n213 Miller Street\r\nSydney 2060\r\nAustralia\r\n\r\nTIME 06JUN19   11:49\r\nMID         22341842\r\nTSP     100612348842\r\nRRN     190606001105\r\nVisa(C)           CR\r\nCARD............5581\r\nAUTH          067849\r\n\r\nREFUND      AUD10.00\r\n\r\n   (000) APPROVED\r\n\r\n\r\n\r\n\r\n\r\n\r\n"",""merchant_receipt_printed"":false,""online_indicator"":""Y"",""pos_ref_id"":""rfnd-06-06-2019-11-49-05"",""refund_amount"":1000,""rrn"":""190606001105"",""scheme_name"":""Visa"",""stan"":""001105"",""success"":true,""terminal_id"":""100612348842"",""terminal_ref_id"":""12348842_06062019114915"",""transaction_type"":""REFUND""},""datetime"":""2019-06-06T11:49:15.038"",""event"":""refund_response"",""id"":""refund150""}}";

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

            //assert
            Assert.Equal("refund_response", msg.EventName);
            Assert.True(response.Success);
            Assert.Equal("refund150", response.RequestId);
            Assert.Equal("rfnd-06-06-2019-11-49-05", response.PosRefId);
            Assert.Equal("Visa", response.SchemeName);
            Assert.Equal("Visa", response.SchemeAppName);
            Assert.Equal("190606001105", response.GetRRN());
            Assert.Equal(1000, response.GetRefundAmount());
            Assert.NotNull(response.GetCustomerReceipt());
            Assert.NotNull(response.GetMerchantReceipt());
            Assert.Equal("APPROVED", response.GetResponseText());
            Assert.Equal("000", response.GetResponseCode());
            Assert.Equal("12348842_06062019114915", response.GetTerminalReferenceId());
            Assert.Equal("EMV_CTLS", response.GetCardEntry());
            Assert.Equal("CREDIT", response.GetAccountType());
            Assert.Equal("067849", response.GetAuthCode());
            Assert.Equal("06062019", response.GetBankDate());
            Assert.Equal("114905", response.GetBankTime());
            Assert.Equal("............5581", response.GetMaskedPan());
            Assert.Equal("100612348842", response.GetTerminalId());
            Assert.False(response.WasCustomerReceiptPrinted());
            Assert.False(response.WasMerchantReceiptPrinted());
            Assert.Equal(DateTime.ParseExact(msg.GetDataStringValue("bank_settlement_date"), "ddMMyyyy", CultureInfo.InvariantCulture).Date, response.GetSettlementDate());
            Assert.Equal(response.GetResponseValue("pos_ref_id"), response.PosRefId);

            // act
            response = new RefundResponse();

            // assert
            Assert.Null(SpiClientTestUtils.GetInstanceField(response.GetType(), response, "_m"));
            Assert.Null(response.PosRefId);
        }
Ejemplo n.º 15
0
        public void AddToOpenTablesList_ValidOpenTablesList_SetObjects()
        {
            // arrange
            var getOpenTablesCom = new GetOpenTablesCom();
            var openTablesEntry  = new OpenTablesEntry();

            openTablesEntry.TableId = "1";
            openTablesEntry.Label   = "1";
            openTablesEntry.BillOutstandingAmount = 1000;

            // act
            getOpenTablesCom.AddToOpenTablesList(openTablesEntry);
            var openTablesEntries = (List <OpenTablesEntry>)SpiClientTestUtils.GetInstanceField(typeof(GetOpenTablesCom), getOpenTablesCom, "OpenTablesList");

            // assert
            Assert.Equal(openTablesEntries[0].TableId, openTablesEntry.TableId);
            Assert.Equal(openTablesEntries[0].Label, openTablesEntry.Label);
            Assert.Equal(openTablesEntries[0].BillOutstandingAmount, openTablesEntry.BillOutstandingAmount);
        }
Ejemplo n.º 16
0
        public void GetLastTransactionResponse_OnValidResponse_ReturnObjects()
        {
            // arrange
            var          secrets = SpiClientTestUtils.SetTestSecrets();
            const string jsonStr = @"{""message"":{""data"":{""account_type"":""CREDIT"",""auth_code"":""139059"",""bank_date"":""14062019"",""bank_noncash_amount"":1000,""bank_settlement_date"":""14062019"",""bank_time"":""153747"",""card_entry"":""EMV_CTLS"",""currency"":""AUD"",""customer_receipt"":"""",""customer_receipt_printed"":false,""emv_actioncode"":""ARP"",""emv_actioncode_values"":""9BDDE227547B41F43030"",""emv_pix"":""1010"",""emv_rid"":""A000000003"",""emv_tsi"":""0000"",""emv_tvr"":""0000000000"",""expiry_date"":""1122"",""host_response_code"":""000"",""host_response_text"":""APPROVED"",""informative_text"":""                "",""masked_pan"":""............3952"",""merchant_acquirer"":""EFTPOS FROM BANK SA"",""merchant_addr"":""213 Miller Street"",""merchant_city"":""Sydney"",""merchant_country"":""Australia"",""merchant_id"":""22341842"",""merchant_name"":""Merchant4"",""merchant_postcode"":""2060"",""merchant_receipt"":""EFTPOS FROM BANK SA\r\nMerchant4\r\n213 Miller Street\r\nSydney 2060\r\nAustralia\r\n\r\nTIME 14JUN19   15:37\r\nMID         22341842\r\nTSP     100612348842\r\nRRN     190614001137\r\nVisa Credit     \r\nVisa(C)           CR\r\nCARD............3952\r\nAID   A0000000031010\r\nTVR       0000000000\r\nAUTH          139059\r\n\r\nPURCHASE    AUD10.00\r\n\r\n   (000) APPROVED\r\n\r\n*DUPLICATE  RECEIPT*\r\n\r\n\r\n\r\n\r\n\r\n\r\n"",""merchant_receipt_printed"":false,""online_indicator"":""Y"",""pos_ref_id"":""prchs-14-06-2019-15-37-49"",""purchase_amount"":1000,""rrn"":""190614001137"",""scheme_app_name"":""Visa Credit"",""scheme_name"":""Visa"",""stan"":""001137"",""success"":true,""terminal_id"":""100612348842"",""terminal_ref_id"":""12348842_14062019153831"",""transaction_type"":""PURCHASE""},""datetime"":""2019-06-14T15:38:31.620"",""event"":""last_transaction"",""id"":""glt10""}}";

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

            response.CopyMerchantReceiptToCustomerReceipt();

            //assert
            Assert.Equal("last_transaction", msg.EventName);
            Assert.True(response.WasRetrievedSuccessfully());
            Assert.Equal(Message.SuccessState.Success, response.GetSuccessState());
            Assert.True(response.WasSuccessfulTx());
            Assert.Equal("PURCHASE", response.GetTxType());
            Assert.Equal("prchs-14-06-2019-15-37-49", response.GetPosRefId());
            Assert.Equal(1000, response.GetBankNonCashAmount());
            Assert.Equal("Visa", response.GetSchemeName());
            Assert.Equal("Visa", response.GetSchemeApp());
            Assert.Equal(0, response.GetAmount());
            Assert.Equal(0, response.GetTransactionAmount());
            Assert.Equal("14062019153747", response.GetBankDateTimeString());
            Assert.Equal("190614001137", response.GetRRN());
            Assert.Equal("APPROVED", response.GetResponseText());
            Assert.Equal("000", response.GetResponseCode());
            Assert.Equal(msg.GetDataStringValue("customer_receipt"), msg.GetDataStringValue("merchant_receipt"));

            // act
            response = new GetLastTransactionResponse();

            // assert
            Assert.Null(SpiClientTestUtils.GetInstanceField(response.GetType(), response, "_m"));
        }