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); }
// if RefundAmount == 0.0M, then then ENTIRE order amount will be refunded! public override string RefundOrder(int OriginalOrderNumber, int NewOrderNumber, decimal RefundAmount, String RefundReason, Address UseBillingAddress) { String result = String.Empty; DB.ExecuteSQL("update orders set RefundTXCommand=NULL, RefundTXResult=NULL where OrderNumber=" + OriginalOrderNumber.ToString()); String TransID = String.Empty; Decimal OrderTotal = System.Decimal.Zero; using (var con = new SqlConnection(DB.GetDBConn())) { con.Open(); using (var rs = DB.GetRS("select * from Orders with (NOLOCK) where OrderNumber=" + OriginalOrderNumber.ToString(), con)) { if (rs.Read()) { TransID = Regex.Match(DB.RSField(rs, "AuthorizationPNREF"), "(?<=CAPTURE=)[0-9A-Z]+", RegexOptions.Compiled).ToString(); OrderTotal = DB.RSFieldDecimal(rs, "OrderTotal"); } } } if (TransID.Length == 0 || TransID == "0") { result = "Invalid or Empty Transaction ID"; } else { try { RefundTransactionReq RefundReq = new RefundTransactionReq(); RefundTransactionRequestType RefundRequestType = new RefundTransactionRequestType(); RefundTransactionResponseType RefundResponse; BasicAmountType BasicAmount = new BasicAmountType(); RefundRequestType.TransactionID = TransID; RefundRequestType.Version = API_VER; BasicAmount.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), AppLogic.AppConfig("Localization.StoreCurrency"), true); //If partial refund set value ( like 1.95). If FULL Refund leave it empty. The transactionID will take care of the amount if (OrderTotal == RefundAmount || RefundAmount == 0.0M) { RefundRequestType.RefundType = RefundType.Full; } else { BasicAmount.Value = Localization.CurrencyStringForGatewayWithoutExchangeRate(RefundAmount); RefundRequestType.RefundType = RefundType.Partial; } RefundRequestType.Amount = BasicAmount; RefundRequestType.RefundTypeSpecified = true; if (!String.IsNullOrEmpty(RefundReason)) { RefundRequestType.Memo = RefundReason; } RefundReq.RefundTransactionRequest = RefundRequestType; DB.ExecuteSQL("update orders set RefundTXCommand=" + DB.SQuote(XmlCommon.SerializeObject(RefundRequestType, RefundRequestType.GetType())) + " where OrderNumber=" + OriginalOrderNumber.ToString()); RefundResponse = (RefundTransactionResponseType)IPayPalRefund.RefundTransaction(RefundReq); //if (LogToErrorTable) //{ // PayPalController.Log(XmlCommon.SerializeObject(RefundReq, RefundReq.GetType()), "RefundTransaction Request"); // PayPalController.Log(XmlCommon.SerializeObject(RefundResponse, RefundResponse.GetType()), "RefundTransaction Response"); //} DB.ExecuteSQL("update orders set RefundTXCommand=" + DB.SQuote(XmlCommon.SerializeObject(RefundReq, RefundReq.GetType())) + ", RefundTXResult=" + DB.SQuote(XmlCommon.SerializeObject(RefundResponse, RefundResponse.GetType())) + " where OrderNumber=" + OriginalOrderNumber.ToString()); String RefundTXResult = String.Empty; if (RefundResponse != null && RefundResponse.Ack.ToString().StartsWith("success", StringComparison.InvariantCultureIgnoreCase)) { result = AppLogic.ro_OK; String RefundTransID = RefundResponse.RefundTransactionID; DB.ExecuteSQL("update orders set AuthorizationPNREF=AuthorizationPNREF+'|REFUND=" + RefundTransID + "' where OrderNumber=" + OriginalOrderNumber.ToString()); } else { if (RefundResponse.Errors != null) { bool first = true; for (int ix = 0; ix < RefundResponse.Errors.Length; ix++) { if (!first) { result += ", "; } result += "Error: [" + RefundResponse.Errors[ix].ErrorCode + "] " + RefundResponse.Errors[ix].LongMessage; first = false; } result += "Note: If you are using Accelerated Boarding for PayPal Express you will not be able to modify orders until you sign up for a full account and enter your API credentials."; } } } catch { result = "NO RESPONSE FROM GATEWAY!"; } } return(result); }