credit card payment


B

BillE

Hi -

I am looking for some documentation about integrating credit card payments
with dotNet web applications.

I have found tons of information about setting up on line credit card
payments, but I would like to find some more specific information relating
to dotNet to make sure I'm doing it the best way.

Please let me know of any good sources of information for this.

Thanks
Bill
 
Ad

Advertisements

G

George Ter-Saakov

This is specific to who you have merchant account with....

Most common is authorizenet.com. It's actually a gateway that you supported
by a lot of merchants. So you talk to gateway and they communicate to the
merchant.

their documentation is here
http://developer.authorize.net/

George.
 
B

BillE

Thanks, that's good info.
Bill

George Ter-Saakov said:
This is specific to who you have merchant account with....

Most common is authorizenet.com. It's actually a gateway that you
supported by a lot of merchants. So you talk to gateway and they
communicate to the merchant.

their documentation is here
http://developer.authorize.net/

George.
 
G

George Ter-Saakov

Yea, I forgot that i have the code for authroizenet already written.
took about 2 hours to do

here it is
1st you create object then use SendRequest to actually send that request to
authorize



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.Read(buf, 0, 1000);

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(......);

return 0;

}

finally

{

if( response != null )

response.Close();

if( st != null )

st.Close();

}

}



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;

}

}

}
 
C

Cowboy \(Gregory A. Beamer\)

This is a huge topic and I am not sure there is a "how to" guide anywhere on
the web that is not sponsored by someone with a stake in the business.

In general, you need a payment processor. On the simplest level, you can use
PayPal. They are fairly easy to use if you pass people off to them.
n/Software makes a payment component that works with .NET and will work with
a variety of payment processors. I would consider this option if you want
something that is easy to fold into your application and allows you the
greatest flexibility on payment processors. If you know what processor you
are going to use, they may

There are other components out there, as well. One place to look for
components is Componentsource.com. I would also get familiar with sites like
SharpToolbox.com, as it has a variety of .NET software, both free and paid.
If you want open source, you can go to codeplex.com or sourceforge.net and
search.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
 
B

BillE

George -
Thanks a lot for the source code - that's a big help.
Bill
George Ter-Saakov said:
Yea, I forgot that i have the code for authroizenet already written.
took about 2 hours to do

here it is
1st you create object then use SendRequest to actually send that request
to authorize



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.Read(buf, 0, 1000);

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(......);

return 0;

}

finally

{

if( response != null )

response.Close();

if( st != null )

st.Close();

}

}



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;

}

}

}




BillE said:
Thanks, that's good info.
Bill
 
Ad

Advertisements

B

BillE

Thanks for the response. It doesn't seem particularly difficult, but there
are so many alternatives that it is hard to determine the best option. I'll
follow up on your leads.
Bill
 

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

Top