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);
        }
示例#2
0
        private void PrintFlowInfo()
        {
            if (_spi.CurrentFlow == SpiFlow.Pairing)
            {
                var pairingState = _spi.CurrentPairingFlowState;
                Console.WriteLine("### PAIRING PROCESS UPDATE ###");
                Console.WriteLine($"# {pairingState.Message}");
                Console.WriteLine($"# Finished? {pairingState.Finished}");
                Console.WriteLine($"# Successful? {pairingState.Successful}");
                Console.WriteLine($"# Confirmation Code: {pairingState.ConfirmationCode}");
                Console.WriteLine($"# Waiting Confirm from Eftpos? {pairingState.AwaitingCheckFromEftpos}");
                Console.WriteLine($"# Waiting Confirm from POS? {pairingState.AwaitingCheckFromPos}");
            }

            if (_spi.CurrentFlow == SpiFlow.Transaction)
            {
                var txState = _spi.CurrentTxFlowState;
                Console.WriteLine("### TX PROCESS UPDATE ###");
                Console.WriteLine($"# {txState.DisplayMessage}");
                Console.WriteLine($"# Id: {txState.Id}");
                Console.WriteLine($"# Type: {txState.Type}");
                Console.WriteLine($"# Amount: ${txState.AmountCents / 100.0}");
                Console.WriteLine($"# Waiting For Signature: {txState.AwaitingSignatureCheck}");
                Console.WriteLine($"# Attempting to Cancel : {txState.AttemptingToCancel}");
                Console.WriteLine($"# Finished: {txState.Finished}");
                Console.WriteLine($"# Success: {txState.Success}");

                if (txState.Finished)
                {
                    Console.WriteLine($"");
                    switch (txState.Success)
                    {
                    case Message.SuccessState.Success:
                        if (txState.Type == TransactionType.Purchase)
                        {
                            Console.WriteLine($"# WOOHOO - WE GOT PAID!");
                            var 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($"# Settlement Date:{purchaseResponse.GetSettlementDate()}");
                            Console.WriteLine("# Customer Receipt:");
                            Console.WriteLine(purchaseResponse.GetCustomerReceipt().TrimEnd());
                        }
                        else if (txState.Type == TransactionType.Refund)
                        {
                            Console.WriteLine($"# REFUND GIVEN - OH WELL!");
                            var refundResponse = new RefundResponse(txState.Response);
                            Console.WriteLine("# Response: {0}", refundResponse.GetResponseText());
                            Console.WriteLine("# RRN: {0}", refundResponse.GetRRN());
                            Console.WriteLine("# Scheme: {0}", refundResponse.SchemeName);
                            Console.WriteLine($"# Settlement Date:{refundResponse.GetSettlementDate()}");
                            Console.WriteLine("# Customer Receipt:");
                            Console.WriteLine(refundResponse.GetCustomerReceipt().TrimEnd());
                        }
                        else if (txState.Type == TransactionType.Settle)
                        {
                            Console.WriteLine($"# SETTLEMENT SUCCESSFUL!");
                            if (txState.Response != null)
                            {
                                var settleResponse = new Settlement(txState.Response);
                                Console.WriteLine("# Response: {0}", settleResponse.GetResponseText());
                                Console.WriteLine("# Merchant Receipt:");
                                Console.WriteLine(settleResponse.GetReceipt().TrimEnd());
                            }
                        }
                        break;

                    case Message.SuccessState.Failed:
                        if (txState.Type == TransactionType.Purchase)
                        {
                            Console.WriteLine($"# WE DID NOT GET PAID :(");
                            if (txState.Response != null)
                            {
                                var purchaseResponse = new PurchaseResponse(txState.Response);
                                Console.WriteLine("# Error: {0}", txState.Response.GetError());
                                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.GetCustomerReceipt().TrimEnd());
                            }
                        }
                        else if (txState.Type == TransactionType.Refund)
                        {
                            Console.WriteLine($"# REFUND FAILED!");
                            if (txState.Response != null)
                            {
                                var refundResponse = new RefundResponse(txState.Response);
                                Console.WriteLine("# Response: {0}", refundResponse.GetResponseText());
                                Console.WriteLine("# RRN: {0}", refundResponse.GetRRN());
                                Console.WriteLine("# Scheme: {0}", refundResponse.SchemeName);
                                Console.WriteLine("# Customer Receipt:");
                                Console.WriteLine(refundResponse.GetCustomerReceipt().TrimEnd());
                            }
                        }
                        else if (txState.Type == TransactionType.Settle)
                        {
                            Console.WriteLine($"# SETTLEMENT FAILED!");
                            if (txState.Response != null)
                            {
                                var settleResponse = new Settlement(txState.Response);
                                Console.WriteLine("# Response: {0}", settleResponse.GetResponseText());
                                Console.WriteLine("# Error: {0}", txState.Response.GetError());
                                Console.WriteLine("# Merchant Receipt:");
                                Console.WriteLine(settleResponse.GetReceipt().TrimEnd());
                            }
                        }

                        break;

                    case Message.SuccessState.Unknown:
                        if (txState.Type == TransactionType.Purchase)
                        {
                            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.");
                        }
                        else if (txState.Type == TransactionType.Refund)
                        {
                            Console.WriteLine($"# WE'RE NOT QUITE SURE WHETHER THE REFUND WENT THROUGH OR NOT :/");
                            Console.WriteLine($"# CHECK THE LAST TRANSACTION ON THE EFTPOS ITSELF FROM THE APPROPRIATE MENU ITEM.");
                            Console.WriteLine($"# YOU CAN THE TAKE THE APPROPRIATE ACTION.");
                        }
                        break;
                    }
                }
            }
            Console.WriteLine("");
        }