Esempio n. 1
0
        private void HandleFinishedPurchase(TransactionFlowState txState)
        {
            PurchaseResponse purchaseResponse;

            switch (txState.Success)
            {
            case Message.SuccessState.Success:
                Console.WriteLine($"# WOOHOO - WE GOT PAID!");
                purchaseResponse = new PurchaseResponse(txState.Response);
                Console.WriteLine("# Response: {0}", purchaseResponse.GetResponseText());
                Console.WriteLine("# RRN: {0}", purchaseResponse.GetRRN());
                Console.WriteLine("# Scheme: {0}", purchaseResponse.SchemeName);
                Console.WriteLine("# Customer Receipt:");
                Console.WriteLine(!purchaseResponse.WasCustomerReceiptPrinted() ? purchaseResponse.GetCustomerReceipt().TrimEnd() : "# PRINTED FROM EFTPOS");
                Console.WriteLine("# PURCHASE: {0}", purchaseResponse.GetPurchaseAmount());
                Console.WriteLine("# TIP: {0}", purchaseResponse.GetTipAmount());
                Console.WriteLine("# SURCHARGE: {0}", purchaseResponse.GetSurchargeAmount());
                Console.WriteLine("# CASHOUT: {0}", purchaseResponse.GetCashoutAmount());
                Console.WriteLine("# BANKED NON-CASH AMOUNT: {0}", purchaseResponse.GetBankNonCashAmount());
                Console.WriteLine("# BANKED CASH AMOUNT: {0}", purchaseResponse.GetBankCashAmount());

                break;

            case Message.SuccessState.Failed:
                Console.WriteLine($"# WE DID NOT GET PAID :(");
                if (txState.Response != null)
                {
                    purchaseResponse = new PurchaseResponse(txState.Response);
                    Console.WriteLine("# Error: {0}", txState.Response.GetError());
                    Console.WriteLine("# Error Detail: {0}", txState.Response.GetErrorDetail());
                    Console.WriteLine("# Response: {0}", purchaseResponse.GetResponseText());
                    Console.WriteLine("# RRN: {0}", purchaseResponse.GetRRN());
                    Console.WriteLine("# Scheme: {0}", purchaseResponse.SchemeName);
                    Console.WriteLine("# Customer Receipt:");
                    Console.WriteLine(!purchaseResponse.WasCustomerReceiptPrinted()
                            ? purchaseResponse.GetCustomerReceipt().TrimEnd()
                            : "# PRINTED FROM EFTPOS");
                }
                break;

            case Message.SuccessState.Unknown:
                Console.WriteLine($"# WE'RE NOT QUITE SURE WHETHER WE GOT PAID OR NOT :/");
                Console.WriteLine($"# CHECK THE LAST TRANSACTION ON THE EFTPOS ITSELF FROM THE APPROPRIATE MENU ITEM.");
                Console.WriteLine($"# IF YOU CONFIRM THAT THE CUSTOMER PAID, CLOSE THE ORDER.");
                Console.WriteLine($"# OTHERWISE, RETRY THE PAYMENT FROM SCRATCH.");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        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);
        }