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); }
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(""); }