//Settle should be run here if site is setup for auth/capture, Payment Module will always be processing a transactions as an Auth public override string ProcessCard(int orderNumber, int customerID, Decimal orderTotal, bool useLiveTransactions, TransactionModeEnum transactionMode, Address useBillingAddress, string cardExtraCode, Address useShippingAddress, string CAVV, string ECI, string XID, out string AVSResult, out string authorizationResult, out string authorizationCode, out string authorizationTransID, out string transactionCommandOut, out string transactionResponse) { Customer ThisCustomer = new Customer(customerID, true); authorizationResult = AVSResult = authorizationCode = authorizationTransID = transactionCommandOut = transactionResponse = ""; string approvalCode = ""; string AVSCode = AVSResult = ""; string CVCode = ""; string responseCode = ""; string responseError = ""; string responseReferenceNumber = ""; string authResponse = ""; string TransID = ""; string TransStatus = ""; string result = AppLogic.ro_OK; if (ThisCustomer != null && ThisCustomer.CustomerID > 0) { if (ThisCustomer.IsAdminUser && (AppLogic.ExceedsFailedTransactionsThreshold(ThisCustomer) || AppLogic.IPIsRestricted(ThisCustomer.LastIPAddress))) { return(AppLogic.GetString("gateway.FailedTransactionThresholdExceeded", ThisCustomer.SkinID, ThisCustomer.LocaleSetting)); } } Encoding encoding = System.Text.Encoding.GetEncoding(1252); FirstPayXmlCommand transactionCommand = new FirstPayXmlCommand(transaction_center_id.ToString(), gateway_id, processor_id); if (transactionMode == TransactionModeEnum.authcapture) { transactionCommand.Settle(XID, Localization.CurrencyStringForGatewayWithoutExchangeRate(orderTotal)); } else { transactionCommand.Query(orderNumber.ToString(), DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1)); } string rawResponseString = ""; FirstPayXmlResponse xmlResponse; if (GetXmlResponse(transactionCommand.InnerXml, out rawResponseString, out xmlResponse)) { if (xmlResponse.Fields.Count > 0) { responseCode = xmlResponse.Fields.ContainsKey("status1") ? xmlResponse.Fields["status1"] : (xmlResponse.Fields.ContainsKey("trans_status1") ? xmlResponse.Fields["trans_status1"] : ""); authResponse = xmlResponse.Fields.ContainsKey("response1") ? xmlResponse.Fields["response1"] : ""; responseError = xmlResponse.Fields.ContainsKey("error1") ? xmlResponse.Fields["error1"] : (xmlResponse.Fields.ContainsKey("error") ? xmlResponse.Fields["error"] : ""); TransStatus = xmlResponse.Fields.ContainsKey("trans_status1") ? xmlResponse.Fields["trans_status1"] : null; responseReferenceNumber = xmlResponse.Fields.ContainsKey("reference_number1") ? xmlResponse.Fields["reference_number1"] : ""; } // rawResponseString now has gateway response transactionResponse = rawResponseString; authorizationCode = approvalCode; authorizationResult = rawResponseString; authorizationTransID = TransID; AVSResult = AVSCode; if (CVCode.Length > 0) { AVSResult += ", CV Result: " + CVCode; } transactionCommandOut = transactionCommand.InnerXml.Replace(gateway_id, "***"); if (responseCode == "1" && (string.IsNullOrEmpty(TransStatus) || TransStatus == "1")) { result = AppLogic.ro_OK; } else if (responseCode == "2") { result = "DECLINED"; if (authResponse.Length > 0) { result += ". " + authResponse; } } else if (responseCode == "0") { result = "Error: " + authResponse + " | " + responseError; } else { result = "System Error: " + rawResponseString; } if (transactionMode == TransactionModeEnum.authcapture) { OrderTransactionCollection transactions = new OrderTransactionCollection(orderNumber); transactions.AddTransaction(AppLogic.ro_TXStateCaptured, transactionCommand.InnerXml.Replace(gateway_id, "***"), rawResponseString, responseReferenceNumber, responseCode, AppLogic.ro_PMCreditCard, DisplayName(ThisCustomer.LocaleSetting), orderTotal); } } else { result = "Error calling 1stPay gateway."; } if (result != AppLogic.ro_OK) { string IP = ""; SqlParameter[] sqlParams = { new SqlParameter("@CustomerID", customerID) , new SqlParameter("@OrderNumber", orderNumber) , new SqlParameter("@IP", IP) , new SqlParameter("@Gateway", DisplayName(ThisCustomer.LocaleSetting)) , new SqlParameter("@PaymentMethod", AppLogic.ro_PMCreditCard) , new SqlParameter("@Command", transactionCommandOut) , new SqlParameter("@Result", transactionResponse) }; if (ThisCustomer != null) { IP = ThisCustomer.LastIPAddress; } string sql = "insert into FailedTransaction(CustomerID,OrderNumber,IPAddress,OrderDate,PaymentGateway,PaymentMethod,TransactionCommand,TransactionResult) " + "values(@CustomerID,@OrderNumber,@IP,getdate(),@Gateway,@PaymentMethod,@Command,@Result)"; using (SqlConnection dbconn = DB.dbConn()) { dbconn.Open(); using (SqlCommand cmd = new SqlCommand(sql, dbconn)) { cmd.Parameters.AddRange(sqlParams.ToArray()); cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); } } } return(result); }
public override string CaptureOrder(Order order) { string result = AppLogic.ro_OK; bool useLiveTransactions = AppLogic.AppConfigBool("UseLiveTransactions"); Customer ThisCustomer = new Customer(order.CustomerID, true); order.CaptureTXCommand = ""; order.CaptureTXResult = ""; string TransID = order.AuthorizationPNREF; Decimal OrderTotal = order.OrderBalance; string AuthorizationCode = order.AuthorizationCode; order.CaptureTXCommand = TransID; if (string.IsNullOrEmpty(TransID) || TransID.Length == 0 || TransID == "0") { result = "Invalid or Empty Transaction ID"; } else { try { string[] TXInfo = TransID.Split('|'); Encoding encoding = System.Text.Encoding.GetEncoding(1252); FirstPayXmlCommand transactionCommand = new FirstPayXmlCommand(transaction_center_id.ToString(), gateway_id, processor_id); transactionCommand.Settle(TXInfo[0], Localization.CurrencyStringForGatewayWithoutExchangeRate(OrderTotal)); string rawResponseString = ""; FirstPayXmlResponse xmlResponse; if (GetXmlResponse(transactionCommand.InnerXml, out rawResponseString, out xmlResponse)) { string responseCode = ""; string responseError = ""; string authResponse = ""; string responseReferenceNumber = ""; if (xmlResponse.Fields.Count > 0) { responseCode = xmlResponse.Fields.ContainsKey("status1") ? xmlResponse.Fields["status1"] : ""; authResponse = xmlResponse.Fields.ContainsKey("response1") ? xmlResponse.Fields["response1"] : ""; responseError = xmlResponse.Fields.ContainsKey("error1") ? xmlResponse.Fields["error1"] : ""; responseReferenceNumber = xmlResponse.Fields.ContainsKey("reference_number1") ? xmlResponse.Fields["reference_number1"] : ""; } if (responseCode == "1") { result = AppLogic.ro_OK; } else if (responseCode == "2") { result = "REJECTED"; if (authResponse.Length > 0) { result += ". " + authResponse; } } else if (responseCode == "0") { result = "Error: " + authResponse + " | " + responseError; } else { result = "System Error: " + rawResponseString; } OrderTransactionCollection transactions = new OrderTransactionCollection(order.OrderNumber); transactions.AddTransaction(AppLogic.ro_TXStateCaptured, transactionCommand.InnerXml.Replace(gateway_id, "***"), rawResponseString, responseReferenceNumber, responseCode, AppLogic.ro_PMCreditCard, DisplayName(ThisCustomer.LocaleSetting), OrderTotal); } else { result = "Error calling 1stPay gateway."; } order.CaptureTXResult = result; order.CaptureTXCommand = transactionCommand.InnerXml.Replace(gateway_id, "***"); } catch (Exception ex) { result = ex.Message; } } return(result); }