Authorize.NET SIM Implementation

B

Bobby Edward

Does anyone have any ASP.NET sample that they can sent me to integrated an
ASP.NET website with Authorize.NET using SIM? I cannot find any online
samples. I already have my gateway id, API Login ID & Transaction Key.

Thanks!
 
B

Bobby Edward

Thanks for your response Tom...

There are no ASP.NET examples for SIM though. :( At first glance it seems
that complex fingerprinting subroutines have to be generated, etc... If
anyone has done this already and can share with me your results please let
me know. Thanks!
 
G

George

Bobby Edward said:
Does anyone have any ASP.NET sample that they can sent me to integrated an
ASP.NET website with Authorize.NET using SIM? I cannot find any online
samples. I already have my gateway id, API Login ID & Transaction Key.

Thanks!



Do not remmember what is SIM but here is my class to integrate with
Authorizenet
Password is your TransactionKey, Interface is the URL path to APIs.

using System;
using System.Net;
using System.IO;
using System.Text;
using XoopsNet.BLL;

namespace XoopsNet.BLL.RetailStore
{
public class clsAuthorizeNet
{
string _sLogin;
string _sPassword;
bool _bTest;
string _sInterface;

string _sBFirst, _sBLast, _sBAddress1, _sBAddress2, _sBCity, _sBState,
_sBZip, _sBCountry, _sBPhone;
string _sShFirst, _sShLast, _sShAddress1, _sShAddress2, _sShCity,
_sShState, _sShZip, _sShCountry;
string _sCustId, _sCustomersIp;
string _sInvoiceNum, _sDescription, _sCardNum, _sCardCode;

decimal _fAmount;
int _iExpMonth, _iExpYear;
System.Text.StringBuilder _bld;

public enum TRANS_TYPE { AUTH_CAPTURE, AUTH_ONLY, CAPTURE_ONLY, CREDIT,
VOID, PRIOR_AUTH_CAPTURE};
public clsAuthorizeNet(
string sBFirst,
string sBLast,
string sBAddress1,
string sBAddress2,
string sBCity,
string sBState,
string sBZip,
string sBCountry,
string sBPhone,
string sShFirst,
string sShLast,
string sShAddress1,
string sShAddress2,
string sShCity,
string sShState,
string sShZip,
string sShCountry,
string sCustId,
string sCustomersIp,
string sInvoiceNum,
string sDescription,
string sCardNum,
string sCardCode,
decimal fAmount,
int iExpMonth,
int iExpYear)
{
_sLogin = clsGlobal._sAuthorizeLogin;
_sPassword = clsGlobal._sAuthorizePassword;
_sInterface = clsGlobal._sAuthorizeInterface;
_bTest = clsGlobal._bAuthorizeTest;

_sBFirst = sBFirst;
_sBLast = sBLast;
_sBAddress1 = sBAddress1 ;
_sBAddress2 = sBAddress2 ;
_sBCity = sBCity ;
_sBState = sBState ;
_sBZip = sBZip ;
_sBCountry = sBCountry;
_sBPhone = sBPhone;
_sShFirst = sShFirst ;
_sShLast = sShLast;
_sShAddress1 = sShAddress1 ;
_sShAddress2 = sShAddress2 ;
_sShCity = sShCity ;
_sShState = sShState ;
_sShZip = sShZip;
_sShCountry = sShCountry;
_sCustId = sCustId;
_sCustomersIp = sCustomersIp;
_sInvoiceNum = sInvoiceNum ;
_sDescription = sDescription ;
_sCardNum = sCardNum ;
_sCardCode = sCardCode ;
_fAmount = fAmount;
_iExpMonth = iExpMonth;
_iExpYear = iExpYear ;
}

public void AppendPair(string sName, string sValue, int iMaxLen)
{
if( sValue.Length > iMaxLen)
sValue = sValue.Substring(0,iMaxLen -1 );
if( _bld.Length != 0 )
_bld.Append('&');
_bld.Append(sName);
_bld.Append("=");
_bld.Append(sValue);

}
public void AppendPair(string sName, bool bValue)
{
if( bValue)
AppendPair(sName, "TRUE",5);
else
AppendPair(sName, "FALSE", 5);
}

public int SendRequest(TRANS_TYPE type, ref string sAutorizationCode, ref
string sTransactionId, out string sReasonText)
{
sReasonText = "";
string sTmp;
_bld = new System.Text.StringBuilder();
AppendPair("x_login", _sLogin, 20);
AppendPair("x_password", _sPassword, 20);
AppendPair("x_test_request", _bTest);
AppendPair("x_delim_data", true);
AppendPair("x_delim_char", ",", 1);
AppendPair("x_encap_char", "", 1);
AppendPair("x_delim_data", true);
AppendPair("x_version", "3.1", 3);

//Billing address
AppendPair("x_first_name", _sBFirst,50);
AppendPair("x_last_name", _sBLast,50);
sTmp = _sBAddress1 + " " + _sBAddress2;
sTmp = sTmp.Trim();
AppendPair("x_address", sTmp, 60);
AppendPair("x_city", _sBCity, 40);
AppendPair("x_state", _sBState, 40);
AppendPair("x_zip", _sBZip, 20);
AppendPair("x_country", _sBCountry, 60);
AppendPair("x_phone", _sBPhone, 60);

//Shipping address
AppendPair("x_ship_to_first_name", _sShFirst,50);
AppendPair("x_ship_to_last_name", _sShLast,50);
sTmp = _sShAddress1 + " " + _sShAddress2;
sTmp = sTmp.Trim();
AppendPair("x_ship_to_address", sTmp, 60);
AppendPair("x_ship_to_city", _sShCity, 40);
AppendPair("x_ship_to_state", _sShState, 40);
AppendPair("x_ship_to_zip", _sShZip, 20);
AppendPair("x_ship_to_country", _sShCountry, 60);

//transaction info
AppendPair("x_customer_ip", _sCustomersIp, 15);
AppendPair("x_cust_id", _sCustId, 20);
AppendPair("x_invoice_num", _sInvoiceNum, 20);
AppendPair("x_description", _sDescription, 255);



AppendPair("x_amount", _fAmount.ToString("0.00"), 15);
AppendPair("x_method", "CC", 2);
AppendPair("x_type", type.ToString(), 20);
if(( type == TRANS_TYPE.CREDIT ) || ( type == TRANS_TYPE.VOID) || (type
== TRANS_TYPE.PRIOR_AUTH_CAPTURE ))
AppendPair("x_trans_id", sTransactionId, 10);
if( type == TRANS_TYPE.CAPTURE_ONLY)
AppendPair("x_auth_code", sAutorizationCode, 10);
AppendPair("x_card_num", _sCardNum, 22);
string sExpDate = _iExpMonth.ToString("00") + "/" +
_iExpYear.ToString("0000");
AppendPair("x_exp_date", sExpDate, 10);
AppendPair("x_card_code", _sCardCode, 4);

HttpWebRequest rq = null;
WebResponse response = null;
Stream st = null;
try
{
string sPostData = _bld.ToString();
rq = (HttpWebRequest) WebRequest.Create(_sInterface);
rq.Timeout = 1000*60; //1 minute timeout
rq.MaximumAutomaticRedirections=3;
rq.AllowAutoRedirect=true;
rq.KeepAlive = false;
rq.ContentType = "application/x-www-form-urlencoded";
rq.ContentLength = sPostData.Length;
rq.Method = "POST";
byte [] byte1 = System.Text.ASCIIEncoding.ASCII.GetBytes(sPostData);
st = rq.GetRequestStream();
st.Write(byte1, 0, byte1.Length);
st.Close();
st = null;
response = rq.GetResponse();
st = response.GetResponseStream();
byte [] buf = new byte[3000];
int iIndex = 0, iRead;
while(true)
{
iRead = st.Read(buf, iIndex, 3000 - iIndex);
iIndex += iRead;
if( iRead == 0 )
break;
}
st.Close();
st = null;
string sResponse = System.Text.ASCIIEncoding.ASCII.GetString(buf);
string [] sR = sResponse.Split(',');
//sR[2] will be '1' if success.
string sCode = sR[2];
sReasonText = sR[3];
sAutorizationCode = sR[4];
string sAvsMatch = sR[5];
string sCvvMatch = "P";
if( sR.Length > 39 )
sCvvMatch = sR[38];
sTransactionId = sR[6];
switch (sAvsMatch)
{
case "A":
sReasonText += "<br>AVS: Street Matched, Zip does not";
break;
case "B":
sReasonText += "<br>AVS: No Info";
break;
case "E":
sReasonText += "<br>AVS: AVS Error";
break;
case "G":
sReasonText += "<br>AVS: Non-US card";
break;
case "N":
sReasonText += "<br>AVS: No Match on Address (Street) or ZIP";
break;
case "P":
sReasonText += "<br>AVS: AVS not applicable for this transaction";
break;
case "R":
sReasonText += "<br>AVS: Retry - System unavailable or timed out";
break;
case "S":
sReasonText += "<br>AVS: Service not supported by issuer";
break;
case "U":
sReasonText += "<br>AVS: Address information is unavailable";
break;
case "W":
sReasonText += "<br>AVS: 9 digit ZIP matches, Address (Street) does
not";
break;
case "X":
sReasonText += "<br>AVS: Address (Street) and 9 digit ZIP match";
break;
case "Y":
sReasonText += "<br>AVS: Address (Street) and 5 digit ZIP match";
break;
case "Z":
sReasonText += "<br>AVS: 5 digit ZIP matches, Address (Street) does
not";
break;
default:
sReasonText += "<br>AVS: code - " + sAvsMatch;
break;
}

switch (sCvvMatch)
{
case "M":
sReasonText += "<br>CVV:Match";
break;
case "N":
sReasonText += "<br>CVV:No Match";
break;
case "P":
sReasonText += "<br>CVV:Not Processed";
break;
case "S":
sReasonText += "<br>CVV:Should have been present";
break;
case "U":
sReasonText += "<br>CVV:Issuer unable to process request";
break;
default:
sReasonText += "<br>CVV: code - " + sCvvMatch;
break;
}
int iErrCode = Int32.Parse(sCode);
SaveCCTransactionHistory(type, Int32.Parse(_sInvoiceNum), iErrCode,
sReasonText, _fAmount, _sCardNum, _sCardCode, sExpDate);
return Int32.Parse(sCode);
}
catch(Exception e)
{
clsGlobal.SendEmail(e.ToString(), "CC ERR",
"(e-mail address removed)", null, null);
return 0;
}
finally
{
if( response != null )
response.Close();
if( st != null )
st.Close();
}
}

public static void SaveCCTransactionHistory(TRANS_TYPE type, int iOrderId,
int iError, string sMessage, decimal fAmount, string sCcNum, string sCvv,
string sExp )
{
if( type == TRANS_TYPE.CREDIT )
fAmount = -fAmount;
clsGlobal.ExecuteSql(String.Format("INSERT INTO
tblCCTransactions(OrderId, ErrCode, Reason, Amount, CCNum, Cvv, ExpDate)
VALUES({0}, {1}, '{2}', {3}, '{4}', '{5}', '{6}')", iOrderId, iError,
sMessage.Replace("'", "''"), fAmount, sCcNum, sCvv, sExp));
}





public string GetError( int iReasonSubcode)
{
string sError = "";
switch( iReasonSubcode )
{
case 4:
case 5:
case 6:
sError = "The credit card number is invalid";
break;
case 7:
sError = "The credit card expiration date is invalid";
break;
case 8:
sError = "The credit card expiration date is invalid";
break;
case 11:
sError = "Duplicate transaction has been submitted. Please wait 2
minutes before resubmit";
break;
case 37:
sError = "The credit card number is invalid";
break;
case 78:
sError = "The CVV code is invalid";
break;

default:
sError = "";//"Transaction declined - " + iReasonSubcode.ToString();
break;

}
return sError;

}
}
}
 
B

Bobby Edward

Thanks! Can you post your ASPX page and code that calls these classes?

George said:
Bobby Edward said:
Does anyone have any ASP.NET sample that they can sent me to integrated
an ASP.NET website with Authorize.NET using SIM? I cannot find any
online samples. I already have my gateway id, API Login ID & Transaction
Key.

Thanks!



Do not remmember what is SIM but here is my class to integrate with
Authorizenet
Password is your TransactionKey, Interface is the URL path to APIs.

using System;
using System.Net;
using System.IO;
using System.Text;
using XoopsNet.BLL;

namespace XoopsNet.BLL.RetailStore
{
public class clsAuthorizeNet
{
string _sLogin;
string _sPassword;
bool _bTest;
string _sInterface;

string _sBFirst, _sBLast, _sBAddress1, _sBAddress2, _sBCity, _sBState,
_sBZip, _sBCountry, _sBPhone;
string _sShFirst, _sShLast, _sShAddress1, _sShAddress2, _sShCity,
_sShState, _sShZip, _sShCountry;
string _sCustId, _sCustomersIp;
string _sInvoiceNum, _sDescription, _sCardNum, _sCardCode;

decimal _fAmount;
int _iExpMonth, _iExpYear;
System.Text.StringBuilder _bld;

public enum TRANS_TYPE { AUTH_CAPTURE, AUTH_ONLY, CAPTURE_ONLY, CREDIT,
VOID, PRIOR_AUTH_CAPTURE};
public clsAuthorizeNet(
string sBFirst,
string sBLast,
string sBAddress1,
string sBAddress2,
string sBCity,
string sBState,
string sBZip,
string sBCountry,
string sBPhone,
string sShFirst,
string sShLast,
string sShAddress1,
string sShAddress2,
string sShCity,
string sShState,
string sShZip,
string sShCountry,
string sCustId,
string sCustomersIp,
string sInvoiceNum,
string sDescription,
string sCardNum,
string sCardCode,
decimal fAmount,
int iExpMonth,
int iExpYear)
{
_sLogin = clsGlobal._sAuthorizeLogin;
_sPassword = clsGlobal._sAuthorizePassword;
_sInterface = clsGlobal._sAuthorizeInterface;
_bTest = clsGlobal._bAuthorizeTest;

_sBFirst = sBFirst;
_sBLast = sBLast;
_sBAddress1 = sBAddress1 ;
_sBAddress2 = sBAddress2 ;
_sBCity = sBCity ;
_sBState = sBState ;
_sBZip = sBZip ;
_sBCountry = sBCountry;
_sBPhone = sBPhone;
_sShFirst = sShFirst ;
_sShLast = sShLast;
_sShAddress1 = sShAddress1 ;
_sShAddress2 = sShAddress2 ;
_sShCity = sShCity ;
_sShState = sShState ;
_sShZip = sShZip;
_sShCountry = sShCountry;
_sCustId = sCustId;
_sCustomersIp = sCustomersIp;
_sInvoiceNum = sInvoiceNum ;
_sDescription = sDescription ;
_sCardNum = sCardNum ;
_sCardCode = sCardCode ;
_fAmount = fAmount;
_iExpMonth = iExpMonth;
_iExpYear = iExpYear ;
}

public void AppendPair(string sName, string sValue, int iMaxLen)
{
if( sValue.Length > iMaxLen)
sValue = sValue.Substring(0,iMaxLen -1 );
if( _bld.Length != 0 )
_bld.Append('&');
_bld.Append(sName);
_bld.Append("=");
_bld.Append(sValue);

}
public void AppendPair(string sName, bool bValue)
{
if( bValue)
AppendPair(sName, "TRUE",5);
else
AppendPair(sName, "FALSE", 5);
}

public int SendRequest(TRANS_TYPE type, ref string sAutorizationCode, ref
string sTransactionId, out string sReasonText)
{
sReasonText = "";
string sTmp;
_bld = new System.Text.StringBuilder();
AppendPair("x_login", _sLogin, 20);
AppendPair("x_password", _sPassword, 20);
AppendPair("x_test_request", _bTest);
AppendPair("x_delim_data", true);
AppendPair("x_delim_char", ",", 1);
AppendPair("x_encap_char", "", 1);
AppendPair("x_delim_data", true);
AppendPair("x_version", "3.1", 3);

//Billing address
AppendPair("x_first_name", _sBFirst,50);
AppendPair("x_last_name", _sBLast,50);
sTmp = _sBAddress1 + " " + _sBAddress2;
sTmp = sTmp.Trim();
AppendPair("x_address", sTmp, 60);
AppendPair("x_city", _sBCity, 40);
AppendPair("x_state", _sBState, 40);
AppendPair("x_zip", _sBZip, 20);
AppendPair("x_country", _sBCountry, 60);
AppendPair("x_phone", _sBPhone, 60);

//Shipping address
AppendPair("x_ship_to_first_name", _sShFirst,50);
AppendPair("x_ship_to_last_name", _sShLast,50);
sTmp = _sShAddress1 + " " + _sShAddress2;
sTmp = sTmp.Trim();
AppendPair("x_ship_to_address", sTmp, 60);
AppendPair("x_ship_to_city", _sShCity, 40);
AppendPair("x_ship_to_state", _sShState, 40);
AppendPair("x_ship_to_zip", _sShZip, 20);
AppendPair("x_ship_to_country", _sShCountry, 60);

//transaction info
AppendPair("x_customer_ip", _sCustomersIp, 15);
AppendPair("x_cust_id", _sCustId, 20);
AppendPair("x_invoice_num", _sInvoiceNum, 20);
AppendPair("x_description", _sDescription, 255);



AppendPair("x_amount", _fAmount.ToString("0.00"), 15);
AppendPair("x_method", "CC", 2);
AppendPair("x_type", type.ToString(), 20);
if(( type == TRANS_TYPE.CREDIT ) || ( type == TRANS_TYPE.VOID) || (type
== TRANS_TYPE.PRIOR_AUTH_CAPTURE ))
AppendPair("x_trans_id", sTransactionId, 10);
if( type == TRANS_TYPE.CAPTURE_ONLY)
AppendPair("x_auth_code", sAutorizationCode, 10);
AppendPair("x_card_num", _sCardNum, 22);
string sExpDate = _iExpMonth.ToString("00") + "/" +
_iExpYear.ToString("0000");
AppendPair("x_exp_date", sExpDate, 10);
AppendPair("x_card_code", _sCardCode, 4);

HttpWebRequest rq = null;
WebResponse response = null;
Stream st = null;
try
{
string sPostData = _bld.ToString();
rq = (HttpWebRequest) WebRequest.Create(_sInterface);
rq.Timeout = 1000*60; //1 minute timeout
rq.MaximumAutomaticRedirections=3;
rq.AllowAutoRedirect=true;
rq.KeepAlive = false;
rq.ContentType = "application/x-www-form-urlencoded";
rq.ContentLength = sPostData.Length;
rq.Method = "POST";
byte [] byte1 = System.Text.ASCIIEncoding.ASCII.GetBytes(sPostData);
st = rq.GetRequestStream();
st.Write(byte1, 0, byte1.Length);
st.Close();
st = null;
response = rq.GetResponse();
st = response.GetResponseStream();
byte [] buf = new byte[3000];
int iIndex = 0, iRead;
while(true)
{
iRead = st.Read(buf, iIndex, 3000 - iIndex);
iIndex += iRead;
if( iRead == 0 )
break;
}
st.Close();
st = null;
string sResponse = System.Text.ASCIIEncoding.ASCII.GetString(buf);
string [] sR = sResponse.Split(',');
//sR[2] will be '1' if success.
string sCode = sR[2];
sReasonText = sR[3];
sAutorizationCode = sR[4];
string sAvsMatch = sR[5];
string sCvvMatch = "P";
if( sR.Length > 39 )
sCvvMatch = sR[38];
sTransactionId = sR[6];
switch (sAvsMatch)
{
case "A":
sReasonText += "<br>AVS: Street Matched, Zip does not";
break;
case "B":
sReasonText += "<br>AVS: No Info";
break;
case "E":
sReasonText += "<br>AVS: AVS Error";
break;
case "G":
sReasonText += "<br>AVS: Non-US card";
break;
case "N":
sReasonText += "<br>AVS: No Match on Address (Street) or ZIP";
break;
case "P":
sReasonText += "<br>AVS: AVS not applicable for this transaction";
break;
case "R":
sReasonText += "<br>AVS: Retry - System unavailable or timed out";
break;
case "S":
sReasonText += "<br>AVS: Service not supported by issuer";
break;
case "U":
sReasonText += "<br>AVS: Address information is unavailable";
break;
case "W":
sReasonText += "<br>AVS: 9 digit ZIP matches, Address (Street) does
not";
break;
case "X":
sReasonText += "<br>AVS: Address (Street) and 9 digit ZIP match";
break;
case "Y":
sReasonText += "<br>AVS: Address (Street) and 5 digit ZIP match";
break;
case "Z":
sReasonText += "<br>AVS: 5 digit ZIP matches, Address (Street) does
not";
break;
default:
sReasonText += "<br>AVS: code - " + sAvsMatch;
break;
}

switch (sCvvMatch)
{
case "M":
sReasonText += "<br>CVV:Match";
break;
case "N":
sReasonText += "<br>CVV:No Match";
break;
case "P":
sReasonText += "<br>CVV:Not Processed";
break;
case "S":
sReasonText += "<br>CVV:Should have been present";
break;
case "U":
sReasonText += "<br>CVV:Issuer unable to process request";
break;
default:
sReasonText += "<br>CVV: code - " + sCvvMatch;
break;
}
int iErrCode = Int32.Parse(sCode);
SaveCCTransactionHistory(type, Int32.Parse(_sInvoiceNum), iErrCode,
sReasonText, _fAmount, _sCardNum, _sCardCode, sExpDate);
return Int32.Parse(sCode);
}
catch(Exception e)
{
clsGlobal.SendEmail(e.ToString(), "CC ERR",
"(e-mail address removed)", null, null);
return 0;
}
finally
{
if( response != null )
response.Close();
if( st != null )
st.Close();
}
}

public static void SaveCCTransactionHistory(TRANS_TYPE type, int
iOrderId, int iError, string sMessage, decimal fAmount, string sCcNum,
string sCvv, string sExp )
{
if( type == TRANS_TYPE.CREDIT )
fAmount = -fAmount;
clsGlobal.ExecuteSql(String.Format("INSERT INTO
tblCCTransactions(OrderId, ErrCode, Reason, Amount, CCNum, Cvv, ExpDate)
VALUES({0}, {1}, '{2}', {3}, '{4}', '{5}', '{6}')", iOrderId, iError,
sMessage.Replace("'", "''"), fAmount, sCcNum, sCvv, sExp));
}





public string GetError( int iReasonSubcode)
{
string sError = "";
switch( iReasonSubcode )
{
case 4:
case 5:
case 6:
sError = "The credit card number is invalid";
break;
case 7:
sError = "The credit card expiration date is invalid";
break;
case 8:
sError = "The credit card expiration date is invalid";
break;
case 11:
sError = "Duplicate transaction has been submitted. Please wait 2
minutes before resubmit";
break;
case 37:
sError = "The credit card number is invalid";
break;
case 78:
sError = "The CVV code is invalid";
break;

default:
sError = "";//"Transaction declined - " + iReasonSubcode.ToString();
break;

}
return sError;

}
}
}
 
G

George

Here is the code i use to call this class
crt is my Shopping cart object. all parameter pretty much speak for themself


clsAuthorizeNet objAuthorize = new clsAuthorizeNet(
crt.BFirst, crt.BLast, crt.BLine1, crt.BLine2, crt.BCity, crt.BState,
crt.BZip, crt.BCountry, crt.BPhone,
crt.ShFirst, crt.ShLast, crt.ShLine1, crt.ShLine2, crt.ShCity,
crt.ShState, crt.ShZip, crt.ShCountry,
crt.UserId.ToString(), Request.UserHostAddress, iOrderId.ToString(),
"Order #: " + iOrderId.ToString(),
crt.CCNum, crt.Cvv, fOrderTotal, crt.ExpMonth, crt.ExpYear);


string sRefCode = null, sTransactionId = null, sReasonCode;
int iError =
objAuthorize.SendRequest(clsAuthorizeNet.TRANS_TYPE.AUTH_CAPTURE, ref
sRefCode, ref sTransactionId, out sReasonCode);
switch( iError )
{
case 0:
//we could not communicate to Authorize.net we will place an order
into pending status
.....
case 1:
//everything is fine order is placed
clsOrder.PayForOrder(iOrderId, clsOrder.PAYMENT_TYPE.CC_CARD,
fOrderTotal, "CC Card charged",crt.CCNum, crt.ExpDate, crt.Cvv, sRefCode,
sTransactionId);
clsOrder.SetOrderStatus(iOrderId, clsOrder.STATUS.PAID);
clsOrder.ClearShoppingCart(iShpId);
.......
default:
//we got an error
string sError = objAuthorize.GetError( iError);
if( sError.Length == 0 )
//Process order and set status to PAYMENT VERIFICATION. Error
is not a critical and transaction might be resubmited later.
else
{
clsOrder.RemoveOrder(iOrderId);
CustomValidator1.ErrorMessage = "<h3>We are sorry,
but there is a problem with your credit card: " + sError + ".<br>Please go
<a href='/Shopping/BillingInfo.aspx'><u>back</u></a> and fix it.</h3>";
CustomValidator1.IsValid = false;
return;
}
}


George.


Bobby Edward said:
Thanks! Can you post your ASPX page and code that calls these classes?

George said:
Bobby Edward said:
Does anyone have any ASP.NET sample that they can sent me to integrated
an ASP.NET website with Authorize.NET using SIM? I cannot find any
online samples. I already have my gateway id, API Login ID &
Transaction Key.

Thanks!



Do not remmember what is SIM but here is my class to integrate with
Authorizenet
Password is your TransactionKey, Interface is the URL path to APIs.

using System;
using System.Net;
using System.IO;
using System.Text;
using XoopsNet.BLL;

namespace XoopsNet.BLL.RetailStore
{
public class clsAuthorizeNet
{
string _sLogin;
string _sPassword;
bool _bTest;
string _sInterface;

string _sBFirst, _sBLast, _sBAddress1, _sBAddress2, _sBCity, _sBState,
_sBZip, _sBCountry, _sBPhone;
string _sShFirst, _sShLast, _sShAddress1, _sShAddress2, _sShCity,
_sShState, _sShZip, _sShCountry;
string _sCustId, _sCustomersIp;
string _sInvoiceNum, _sDescription, _sCardNum, _sCardCode;

decimal _fAmount;
int _iExpMonth, _iExpYear;
System.Text.StringBuilder _bld;

public enum TRANS_TYPE { AUTH_CAPTURE, AUTH_ONLY, CAPTURE_ONLY, CREDIT,
VOID, PRIOR_AUTH_CAPTURE};
public clsAuthorizeNet(
string sBFirst,
string sBLast,
string sBAddress1,
string sBAddress2,
string sBCity,
string sBState,
string sBZip,
string sBCountry,
string sBPhone,
string sShFirst,
string sShLast,
string sShAddress1,
string sShAddress2,
string sShCity,
string sShState,
string sShZip,
string sShCountry,
string sCustId,
string sCustomersIp,
string sInvoiceNum,
string sDescription,
string sCardNum,
string sCardCode,
decimal fAmount,
int iExpMonth,
int iExpYear)
{
_sLogin = clsGlobal._sAuthorizeLogin;
_sPassword = clsGlobal._sAuthorizePassword;
_sInterface = clsGlobal._sAuthorizeInterface;
_bTest = clsGlobal._bAuthorizeTest;

_sBFirst = sBFirst;
_sBLast = sBLast;
_sBAddress1 = sBAddress1 ;
_sBAddress2 = sBAddress2 ;
_sBCity = sBCity ;
_sBState = sBState ;
_sBZip = sBZip ;
_sBCountry = sBCountry;
_sBPhone = sBPhone;
_sShFirst = sShFirst ;
_sShLast = sShLast;
_sShAddress1 = sShAddress1 ;
_sShAddress2 = sShAddress2 ;
_sShCity = sShCity ;
_sShState = sShState ;
_sShZip = sShZip;
_sShCountry = sShCountry;
_sCustId = sCustId;
_sCustomersIp = sCustomersIp;
_sInvoiceNum = sInvoiceNum ;
_sDescription = sDescription ;
_sCardNum = sCardNum ;
_sCardCode = sCardCode ;
_fAmount = fAmount;
_iExpMonth = iExpMonth;
_iExpYear = iExpYear ;
}

public void AppendPair(string sName, string sValue, int iMaxLen)
{
if( sValue.Length > iMaxLen)
sValue = sValue.Substring(0,iMaxLen -1 );
if( _bld.Length != 0 )
_bld.Append('&');
_bld.Append(sName);
_bld.Append("=");
_bld.Append(sValue);

}
public void AppendPair(string sName, bool bValue)
{
if( bValue)
AppendPair(sName, "TRUE",5);
else
AppendPair(sName, "FALSE", 5);
}

public int SendRequest(TRANS_TYPE type, ref string sAutorizationCode,
ref string sTransactionId, out string sReasonText)
{
sReasonText = "";
string sTmp;
_bld = new System.Text.StringBuilder();
AppendPair("x_login", _sLogin, 20);
AppendPair("x_password", _sPassword, 20);
AppendPair("x_test_request", _bTest);
AppendPair("x_delim_data", true);
AppendPair("x_delim_char", ",", 1);
AppendPair("x_encap_char", "", 1);
AppendPair("x_delim_data", true);
AppendPair("x_version", "3.1", 3);

//Billing address
AppendPair("x_first_name", _sBFirst,50);
AppendPair("x_last_name", _sBLast,50);
sTmp = _sBAddress1 + " " + _sBAddress2;
sTmp = sTmp.Trim();
AppendPair("x_address", sTmp, 60);
AppendPair("x_city", _sBCity, 40);
AppendPair("x_state", _sBState, 40);
AppendPair("x_zip", _sBZip, 20);
AppendPair("x_country", _sBCountry, 60);
AppendPair("x_phone", _sBPhone, 60);

//Shipping address
AppendPair("x_ship_to_first_name", _sShFirst,50);
AppendPair("x_ship_to_last_name", _sShLast,50);
sTmp = _sShAddress1 + " " + _sShAddress2;
sTmp = sTmp.Trim();
AppendPair("x_ship_to_address", sTmp, 60);
AppendPair("x_ship_to_city", _sShCity, 40);
AppendPair("x_ship_to_state", _sShState, 40);
AppendPair("x_ship_to_zip", _sShZip, 20);
AppendPair("x_ship_to_country", _sShCountry, 60);

//transaction info
AppendPair("x_customer_ip", _sCustomersIp, 15);
AppendPair("x_cust_id", _sCustId, 20);
AppendPair("x_invoice_num", _sInvoiceNum, 20);
AppendPair("x_description", _sDescription, 255);



AppendPair("x_amount", _fAmount.ToString("0.00"), 15);
AppendPair("x_method", "CC", 2);
AppendPair("x_type", type.ToString(), 20);
if(( type == TRANS_TYPE.CREDIT ) || ( type == TRANS_TYPE.VOID) ||
(type == TRANS_TYPE.PRIOR_AUTH_CAPTURE ))
AppendPair("x_trans_id", sTransactionId, 10);
if( type == TRANS_TYPE.CAPTURE_ONLY)
AppendPair("x_auth_code", sAutorizationCode, 10);
AppendPair("x_card_num", _sCardNum, 22);
string sExpDate = _iExpMonth.ToString("00") + "/" +
_iExpYear.ToString("0000");
AppendPair("x_exp_date", sExpDate, 10);
AppendPair("x_card_code", _sCardCode, 4);

HttpWebRequest rq = null;
WebResponse response = null;
Stream st = null;
try
{
string sPostData = _bld.ToString();
rq = (HttpWebRequest) WebRequest.Create(_sInterface);
rq.Timeout = 1000*60; //1 minute timeout
rq.MaximumAutomaticRedirections=3;
rq.AllowAutoRedirect=true;
rq.KeepAlive = false;
rq.ContentType = "application/x-www-form-urlencoded";
rq.ContentLength = sPostData.Length;
rq.Method = "POST";
byte [] byte1 = System.Text.ASCIIEncoding.ASCII.GetBytes(sPostData);
st = rq.GetRequestStream();
st.Write(byte1, 0, byte1.Length);
st.Close();
st = null;
response = rq.GetResponse();
st = response.GetResponseStream();
byte [] buf = new byte[3000];
int iIndex = 0, iRead;
while(true)
{
iRead = st.Read(buf, iIndex, 3000 - iIndex);
iIndex += iRead;
if( iRead == 0 )
break;
}
st.Close();
st = null;
string sResponse = System.Text.ASCIIEncoding.ASCII.GetString(buf);
string [] sR = sResponse.Split(',');
//sR[2] will be '1' if success.
string sCode = sR[2];
sReasonText = sR[3];
sAutorizationCode = sR[4];
string sAvsMatch = sR[5];
string sCvvMatch = "P";
if( sR.Length > 39 )
sCvvMatch = sR[38];
sTransactionId = sR[6];
switch (sAvsMatch)
{
case "A":
sReasonText += "<br>AVS: Street Matched, Zip does not";
break;
case "B":
sReasonText += "<br>AVS: No Info";
break;
case "E":
sReasonText += "<br>AVS: AVS Error";
break;
case "G":
sReasonText += "<br>AVS: Non-US card";
break;
case "N":
sReasonText += "<br>AVS: No Match on Address (Street) or ZIP";
break;
case "P":
sReasonText += "<br>AVS: AVS not applicable for this transaction";
break;
case "R":
sReasonText += "<br>AVS: Retry - System unavailable or timed out";
break;
case "S":
sReasonText += "<br>AVS: Service not supported by issuer";
break;
case "U":
sReasonText += "<br>AVS: Address information is unavailable";
break;
case "W":
sReasonText += "<br>AVS: 9 digit ZIP matches, Address (Street) does
not";
break;
case "X":
sReasonText += "<br>AVS: Address (Street) and 9 digit ZIP match";
break;
case "Y":
sReasonText += "<br>AVS: Address (Street) and 5 digit ZIP match";
break;
case "Z":
sReasonText += "<br>AVS: 5 digit ZIP matches, Address (Street) does
not";
break;
default:
sReasonText += "<br>AVS: code - " + sAvsMatch;
break;
}

switch (sCvvMatch)
{
case "M":
sReasonText += "<br>CVV:Match";
break;
case "N":
sReasonText += "<br>CVV:No Match";
break;
case "P":
sReasonText += "<br>CVV:Not Processed";
break;
case "S":
sReasonText += "<br>CVV:Should have been present";
break;
case "U":
sReasonText += "<br>CVV:Issuer unable to process request";
break;
default:
sReasonText += "<br>CVV: code - " + sCvvMatch;
break;
}
int iErrCode = Int32.Parse(sCode);
SaveCCTransactionHistory(type, Int32.Parse(_sInvoiceNum), iErrCode,
sReasonText, _fAmount, _sCardNum, _sCardCode, sExpDate);
return Int32.Parse(sCode);
}
catch(Exception e)
{
clsGlobal.SendEmail(e.ToString(), "CC ERR",
"(e-mail address removed)", null, null);
return 0;
}
finally
{
if( response != null )
response.Close();
if( st != null )
st.Close();
}
}

public static void SaveCCTransactionHistory(TRANS_TYPE type, int
iOrderId, int iError, string sMessage, decimal fAmount, string sCcNum,
string sCvv, string sExp )
{
if( type == TRANS_TYPE.CREDIT )
fAmount = -fAmount;
clsGlobal.ExecuteSql(String.Format("INSERT INTO
tblCCTransactions(OrderId, ErrCode, Reason, Amount, CCNum, Cvv, ExpDate)
VALUES({0}, {1}, '{2}', {3}, '{4}', '{5}', '{6}')", iOrderId, iError,
sMessage.Replace("'", "''"), fAmount, sCcNum, sCvv, sExp));
}





public string GetError( int iReasonSubcode)
{
string sError = "";
switch( iReasonSubcode )
{
case 4:
case 5:
case 6:
sError = "The credit card number is invalid";
break;
case 7:
sError = "The credit card expiration date is invalid";
break;
case 8:
sError = "The credit card expiration date is invalid";
break;
case 11:
sError = "Duplicate transaction has been submitted. Please wait 2
minutes before resubmit";
break;
case 37:
sError = "The credit card number is invalid";
break;
case 78:
sError = "The CVV code is invalid";
break;

default:
sError = "";//"Transaction declined - " + iReasonSubcode.ToString();
break;

}
return sError;

}
}
}
 
B

Bobby Edward

Thanks alot George. On our server we don't have an SSL cert, so I'd rather
NOT collect the cc info on our server. Any ideas on how to overcome this?
Thanks...
 
G

George

Another way Authorizenet is offering is to do it through their site.

Then you create a form with bunch of hidden fields like TransactionAmount,
order #, ... and an action of the form points to their secure URL.
Person clicks the button (like Checkout) and ends up on authorizenet site.
Enters all CC info and the authorizenet redirects person back to your URL
(that was in one of the hidden fields)

George.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top