public Transaction_Result Sale(Sale_Details details) { try { var gateway = newClient(); DoTransactionResponseMessage gateWayResult = gateway.doTransaction( "ONE_ZERO", SafeKey, transactionType.PAYMENT, authenticationType.NA, new additionalInfo { merchantReference = details.ExtRef }, new customer { address1 = details.CustomerAddress, addressCity = details.CustomerCity, countryOfResidence = details.CustomerCountry, firstName = details.CustomerFirstName, lastName = details.CustomerLastName }, new basket { amountInCents = (details.Amount * 100).ToString("F0"), currencyCode = details.CurrencyCode }, null, new creditCard[] { new creditCard { amountInCents = (details.Amount * 100).ToString("F0"), cardExpiry = GatewayUtils.formatExpiryDate(details.CardExpiryMonth, details.CardExpiryYear), cardNumber = details.CardNumber, cvv = details.CardCCV, nameOnCard = details.CustomerFirstName + " " + details.CustomerLastName } }, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null ); var results = gateWayResult; if (results.successful) { return(new Transaction_Result { isApproved = true, ApprovalCode = results.resultCode, ResultCode = results.resultCode, ResultText = results.resultMessage, TransactionIndex = results.payUReference, hasServerError = false, FullRequest = getXmlString(details), FullResponse = getXmlString(results) }); } else { return(new Transaction_Result { isApproved = false, hasServerError = false, ErrorCode = results.resultCode, ErrorText = results.resultMessage, FullResponse = getXmlString(results), FullRequest = getXmlString(details) }); } } catch (Exception ex) { return(new Transaction_Result { isApproved = false, hasServerError = true, ErrorText = ex.Message }); } }
public Transaction_Result Auth(Sale_Details details) { try { var xmlString = getAuthXML( PayGateID, Password, details.ExtRef, details.CustomerFirstName + " " + details.CustomerLastName, details.CardNumber, GatewayUtils.formatExpiryDate(details.CardExpiryMonth, details.CardExpiryYear), "0", //budget period 0 == Straight (details.Amount * 100).ToString("F0"), //takes amounts in cents details.CurrencyCode, details.CardCCV ); var xml = GatewayUtils.PostXMLTransaction(url, xmlString); XmlNode protocol = xml.GetElementsByTagName("protocol").Item(0); XmlNode errorNode = protocol.SelectNodes("errorrx").Item(0); string cardnumber = details.CardNumber; Regex rgx = new Regex(@"[^\d]"); cardnumber = rgx.Replace(cardnumber, String.Empty); //removes dashes spaces, etc string last4digits = cardnumber.Substring(details.CardNumber.Length - 4); var stringwriter = new System.IO.StringWriter(); var serializer = new XmlSerializer(details.GetType()); serializer.Serialize(stringwriter, details); var fullrequest = stringwriter.ToString(); fullrequest = fullrequest.Replace(cardnumber, last4digits); fullrequest = fullrequest.Replace(details.CardCCV, "***"); var respstringwriter = new System.IO.StringWriter(); xml.Save(respstringwriter); if (errorNode == null) { XmlNode successNode = protocol.SelectNodes("authrx").Item(0); string transactionID = successNode.Attributes.GetNamedItem("tid").Value; //The unique reference number assign by PayGate to the original transaction. string customerReference = successNode.Attributes.GetNamedItem("cref").Value; //This is your reference number for use by your internal systems. Must be different per transaction string status = successNode.Attributes.GetNamedItem("stat").Value; //Transaction status. string statusDesc = successNode.Attributes.GetNamedItem("sdesc").Value; //Transaction status description. string resultCode = successNode.Attributes.GetNamedItem("res").Value; //Result Code string resultDesc = successNode.Attributes.GetNamedItem("rdesc").Value; //Result Code description. string authCode = successNode.Attributes.GetNamedItem("auth").Value; //The Authorisation code returned by the acquirer (bank). string risk = successNode.Attributes.GetNamedItem("risk").Value; //X - NA, A - Authenticated, N - Not Authenticated This is a 2-character field containing a risk indicator for this transaction. string cardTypeCode = successNode.Attributes.GetNamedItem("ctype").Value; //Card type code 0 - Unknown, 1 - Visa, 2 - MasterCard, 3 - Amex, 4 - Diners return(new Transaction_Result { TransactionIndex = transactionID, isApproved = status != "0" && status != "2", hasServerError = false, ApprovalCode = statusDesc, ResultCode = resultCode, ResultText = resultDesc, ProcessorCode = authCode, FullRequest = fullrequest, FullResponse = xml.OuterXml }); } else { string errorCode = errorNode.Attributes.GetNamedItem("ecode").Value; string errorDesc = errorNode.Attributes.GetNamedItem("edesc").Value; return(new Transaction_Result { isApproved = false, hasServerError = false, ErrorCode = errorCode, ErrorText = errorDesc, }); } } catch (Exception ex) { return(new Transaction_Result { isApproved = false, hasServerError = true, ErrorText = ex.Message }); } }