ASP.NET - Payment Gateway - Asked By Naresh Kumar on 22-Aug-11 02:31 AM

Hi All,

I have got requirement to integrate Payment Gateway to one of the website. I need to use Authorize.net service provider for Integration. Can any one have any idea how to proceed please advise.

Appreciate your help.
Ravi S replied to Naresh Kumar on 22-Aug-11 02:34 AM
HI

A payment gateway is an e-commerce application service provider service that authorizes payments for online transactions. It is the equivalent of a physical point of sale terminal located in most retail outlets. Payment gateways encrypt sensitive information, such as credit card numbers, to ensure that information passes securely between the customer and the merchant.
 
To read about how payment gateways work, check this - http://en.wikipedia.org/wiki/Payment_gateway#How_payment_gateways_work
 
The following are some of the popular payment gateways -
Paypal
Authorize.net
Cybersource
VeriSign

refer
http://www.eggheadcafe.com/community/aspnet/17/10343432/payment-gateway.aspx
http://www.eggheadcafe.com/community/aspnet/17/10084850/payment-gateway.aspx
Jitendra Faye replied to Naresh Kumar on 22-Aug-11 02:34 AM
Do you want to intergrate PayPal in your shopping cart or web site? Here are some free source code samples to help you get started. The ASP.Net integration code below is coded using the 2.0 runtime environment.
  • http://www.spiderweblogic.com/content/DOCS/public/share/PayPalCSharp.zip (.zip file)

While we always encourage you to go to https://www.paypal.com/us/mrb/pal=PS6NF85QCPM9L for their official documentation, this sample code will help to jump-start your development efforts as you build PayPal features into your shopping cart. PayPal does offer several ways to integrate with them. This is just a quick starter kit - with no warrantees of any kind. Only download the source code if you agree to these terms.


Feel free to http://www.pdncommunity.com/pdn/board/message?message.uid=15059#U15059. I am willing to update this project modestly if the changes would be beneficial to everybody. If you want a custom implementation of this or technical support, give me a call.  We can do so for a reasonable price.


Features included:

  • Home page with a "Product List" that have links to add to cart
  • "View Cart" Page
  • "PayPal Checkout" Page with a link to checkout
  • One "master page" you can edit to get a desired look and feel across the website. 

These are designed for an ASP.Net developer.  If you are not an ASP.Net developer/coder, then this starter kit/sample code would be of no use to you.


Basic Steps
  1. Sign up for a https://www.paypal.com/us/mrb/pal=PS6NF85QCPM9L account. They have personal, premier, and business accounts. You will need to upgrade to a premier or business account to accept credit cards.  PayPal is always happy to let you upgrade.
  2. Download the source code above
  3. Put in your PayPal email address in the SendPayPal.aspx page
  4. Tailor the Master Page to have the look desired
  5. Add your products to the xml file
  6. Add your pictures to the pictures folder

Follow this link also-

http://www.spiderweblogic.com/Paypal-Integration-Code.aspx

Naresh Kumar replied to Jitendra Faye on 22-Aug-11 02:39 AM
Thanks for your quick reply.

I must use Authorize.NET service provider for integration , not paypal.
Jitendra Faye replied to Naresh Kumar on 22-Aug-11 02:42 AM
Authorize.net


Authorize.Net is one of the leading providers of Internet-based transaction services, with millions of customers around the globe.
Our programmers have wide knowledge on the working of http://authorize.net/ works including recurring billing and we can deliver integration with Authorize.Net.

Authorize.Net provides excellent solution for the integration of your website with Authorize.net. We also achieve custom integration based on your specifications.

Follow this link-
http://www.adorntechnologies.com/payment-gateway-integrations
Hope this will help you.
Web Star replied to Naresh Kumar on 22-Aug-11 02:42 AM

To understand how payment gateway use credit card processes have a look at following steps:

Step 1:  The merchant submits a credit card transaction to the Authorize.Net Payment Gateway on behalf of a customer via secure connection from a Web site, at retail, from a MOTO center or a wireless device.

Step 2:  Authorize.Net receives the secure transaction information and passes it via a secure connection to the Merchant Bank's Processor.

Step 3:  The Merchant Bank's Processor submits the transaction to the Credit Card Interchange (a network of financial entities that communicate to manage the processing, clearing, and settlement of credit card transactions). 

Step 4:  The Credit Card Interchange routes the transaction to the customer's Credit Card Issuer. 

Step 5:  The Credit Card Issuer approves or declines the transaction based on the customer's available funds and passes the transaction results, and if approved, the appropriate funds, back through the Credit Card Interchange. 

Step 6:  The Credit Card Interchange relays the transaction results to the Merchant Bank's Processor. 

Step 7:  The Merchant Bank's Processor relays the transaction results to Authorize.Net

Go through this link:

http://www.vbdotnetheaven.com/UploadFile/munnamax/PaymentGateway02152006022631AM/PaymentGateway.aspx

TSN ... replied to Naresh Kumar on 22-Aug-11 02:44 AM
hi..

hi..

try like this..
http://chiragrdarji.files.wordpress.com/2008/02/windowslivewriterauthorizenetintegrationusingaspnet-f013image017.pnghttp://chiragrdarji.wordpress.com/2008/02/25/authorizenet-integration-using-aspnet/
   Now look in to the piece of code. I have used three classes to generate framework for integration. 
   1: #region Namespaces
   2: using System;
   3: using System.Data;
   4: using System.Configuration;
   5: using System.Web;
   6: using System.Web.Security;
   7: using System.Web.UI;
   8: using System.Web.UI.WebControls;
   9: using System.Web.UI.WebControls.WebParts;
  10: using System.Web.UI.HtmlControls;
  11: using System.Text;
  12: using System.Net;
  13: using System.IO; 
  14: #endregion
  15:  
  16:  
  17:  
  18: /// <summary>
  19: /// Summary description for AuthorizeNet
  20: /// </summary>
  21: public static class AuthorizeNet
  22: {
  23:     #region Private Member(s)
  24:     private static string UNEXPECTED_ERROR = "Unexpected error";
  25:     private static string AUTHORIZENET_TEST_URL = "https://test.authorize.net/gateway/transact.dll";
  26:     private static string AUTHORIZENET_LIVE_URL = "https://authorize.net/gateway/transact.dll"; 
  27:     #endregion
  28:  
  29:  
  30:     #region Transaction Type Enum(s)
  31:  
  32:     // Transaction Type
  33:     public enum TransactionType
  34:     {
  35:         AUTH_CAPTURE = 0,
  36:         AUTH_ONLY,
  37:         PRIOR_AUTH_CAPTURE,
  38:         CREDIT,
  39:         VOID
  40:     }
  41:  
  42:     // Get string for Enum
  43:     public static string GetSringForEnum(TransactionType TransType)
  44:     {
  45:         switch (TransType)
  46:         {
  47:             case TransactionType.AUTH_CAPTURE:
  48:                 return "AUTH_CAPTURE";
  49:                 break;
  50:             case TransactionType.AUTH_ONLY:
  51:                 return "AUTH_ONLY";
  52:                 break;
  53:             case TransactionType.PRIOR_AUTH_CAPTURE:
  54:                 return "PRIOR_AUTH_CAPTURE";
  55:                 break;
  56:             case TransactionType.CREDIT:
  57:                 return "CREDIT";
  58:                 break;
  59:             case TransactionType.VOID:
  60:                 return "VOID";
  61:                 break;
  62:             default:
  63:                 return string.Empty;
  64:                 break;
  65:         }
  66:     } 
  67:  
  68:     #endregion
  69:  
  70:  
  71:     /// <summary>
  72:     /// Generate Rququest string
  73:     /// </summary>
  74:     /// <param name="objAuthorizeNetRequest"></param>
  75:     /// <returns></returns>
  76:     private static string GetRequestString(AuthorizeNetRequest objAuthorizeNetRequest,TransactionType TransType)
  77:     {
  78:         StringBuilder stbRequest = new StringBuilder(string.Empty);
  79:  
  80:         stbRequest.Append("x_login=");
  81:         stbRequest.Append(objAuthorizeNetRequest.Login);
  82:         stbRequest.Append("&x_type=");
  83:         stbRequest.Append(GetSringForEnum(TransType));
  84:         stbRequest.Append("&x_amount=");
  85:         stbRequest.Append(objAuthorizeNetRequest.Amount);
  86:         stbRequest.Append("&x_card_num=");
  87:         stbRequest.Append(objAuthorizeNetRequest.CardNumber);
  88:         stbRequest.Append("&x_exp_date=");
  89:         stbRequest.Append(objAuthorizeNetRequest.CardExpirationDate);
  90:         stbRequest.Append("&x_tran_key=");
  91:         stbRequest.Append(objAuthorizeNetRequest.TransactionKey);
  92:         stbRequest.Append("&x_relay_response=FALSE");
  93:         stbRequest.Append("&x_delim_data=TRUE");
  94:         stbRequest.Append("&x_delim_char=|");
  95:         stbRequest.Append("&x_email=chiragrdarji@yahoo.co.in");
  96:         // If x_test_request = FALSE, TransactionId is generated.
  97:         stbRequest.Append("&x_test_request=FALSE");
  98:  
  99:         // First name and Last will be displayed in Transaction report. (LastName,FirstName)
 100:         stbRequest.Append("&x_first_name=Chirag");
 101:         stbRequest.Append("&x_last_name=Darji");
 102:         stbRequest.Append("&x_company=XO Limited");
 103:  
 104:         
 105:  
 106:         if (TransType == TransactionType.CREDIT || TransType == TransactionType.PRIOR_AUTH_CAPTURE || TransType == TransactionType.VOID)
 107:         {
 108:             stbRequest.Append("&x_trans_id=");
 109:             stbRequest.Append(objAuthorizeNetRequest.TransactionId);
 110:         }        
 111:  
 112:         return stbRequest.ToString();
 113:     }
 114:  
 115:     
 116:     /// <summary>
 117:     /// Authorize the merchant detail and if merchant is valid process the credit card.
 118:     /// </summary>
 119:     /// <param name="objAuthorizeNetRequest"></param>
 120:     /// <returns></returns>
 121:     public static AuthorizeNetResponse CallAuthorizeNetMethod(AuthorizeNetRequest objAuthorizeNetRequest)
 122:     {
 123:         AuthorizeNetResponse objAuthorizeNetResponse = new AuthorizeNetResponse();
 124:         string strRequest = GetRequestString(objAuthorizeNetRequest, objAuthorizeNetRequest.TransactionType);
 125:         string strResponse = string.Empty;
 126:  
 127:         WebRequest objWebRequest = WebRequest.Create(AUTHORIZENET_TEST_URL);
 128:         objWebRequest.Method = "POST";
 129:         objWebRequest.ContentLength = strRequest.Length;
 130:         objWebRequest.ContentType = "application/x-www-form-urlencoded";
 131:  
 132:         // Add request parameters to memory stream before sending the web request.
 133:         using (StreamWriter objStreamWriter = new StreamWriter(objWebRequest.GetRequestStream()))
 134:         {
 135:             objStreamWriter.Write(strRequest);
 136:             objStreamWriter.Close();
 137:         }
 138:  
 139:  
 140:         // Get Response back.
 141:         WebResponse objWebResponse = objWebRequest.GetResponse();
 142:  
 143:         // Retrieve result parameter.
 144:         using (StreamReader objStreamReader = new StreamReader(objWebResponse.GetResponseStream()))
 145:         {
 146:             strResponse = objStreamReader.ReadToEnd();
 147:             objStreamReader.Close();
 148:         }
 149:  
 150:         HandleResponse(strResponse, objAuthorizeNetResponse);
 151:  
 152:         return objAuthorizeNetResponse;
 153:     }
 154:  
 155:  
 156:     /// <summary>
 157:     /// Set Response to indicate failure
 158:     /// </summary>
 159:     /// <param name="objAuthorizeNetResponse"></param>
 160:     /// <param name="ErrorMessage"></param>
 161:     private static void HandleError(AuthorizeNetResponse objAuthorizeNetResponse,string ErrorMessage)
 162:     {
 163:         objAuthorizeNetResponse.IsSuccess = false;
 164:         objAuthorizeNetResponse.Errors = ErrorMessage;
 165:     }
 166:  
 167:  
 168:     /// <summary>
 169:     /// Check the response and identify the result of the request.
 170:     /// </summary>
 171:     /// <param name="strResponse"></param>
 172:     /// <param name="objAuthorizeNetResponse"></param>
 173:     private static void HandleResponse(string strResponse, AuthorizeNetResponse objAuthorizeNetResponse)
 174:     {
 175:         /**********************************************************************************************************************************************************************************************************
 176:          * We will get the response srting as shown below, this is a sample string
 177:          * 
 178:          * 1|1|1|This transaction has been approved.|RmFjFi|Y|508252758|||100.00|CC|auth_capture||||||||||||chiragrdarji@yahoo.co.in||||||||||||||AAD0537178B11C0F1105614FD1774773||2||||||||||||||||||||||||||||
 179:          * 
 180:          * The first value before the first pipe(|) symbol indicates the result.
 181:          * Below is teh link that represents the different Response code
 182:          * http://www.authorize.net/support/Merchant/Transaction_Response/Response_Reason_Codes_and_Response_Reason_Text.htm
 183:          **********************************************************************************************************************************************************************************************************/
 184:         string[] strWebResponse = strResponse.Split(new char[] { '|' }, StringSplitOptions.None);
 185:  
 186:         if (strResponse != null)
 187:         {
 188:             // Check the response
 189:             if (strWebResponse[0] == "1")
 190:             {
 191:                 objAuthorizeNetResponse.IsSuccess = true;
 192:                 if (strWebResponse.Length > 3)
 193:                     objAuthorizeNetResponse.SuccessMessage = strWebResponse[3];
 194:                 // If x_test_request = FALSE, we will get transaction id else Transaction id = 0
 195:                 if (strWebResponse.Length > 6)
 196:                     objAuthorizeNetResponse.TransactionId = strWebResponse[6];
 197:             }
 198:             else
 199:             {
 200:                 if (strWebResponse.Length > 3)
 201:                     HandleError(objAuthorizeNetResponse, strWebResponse[3]);
 202:                 else
 203:                     HandleError(objAuthorizeNetResponse, UNEXPECTED_ERROR);
 204:             }
 205:         }
 206:         else
 207:         {
 208:             HandleError(objAuthorizeNetResponse, UNEXPECTED_ERROR);
 209:         }
 210:     }
 211: }

  Fig (1) AuthorizeNet.cs implements actual logic of integration.

   1: using System;
   2: using System.Data;
   3: using System.Configuration;
   4: using System.Web;
   5: using System.Web.Security;
   6: using System.Web.UI;
   7: using System.Web.UI.WebControls;
   8: using System.Web.UI.WebControls.WebParts;
   9: using System.Web.UI.HtmlControls;
  10:  
  11: /// <summary>
  12: /// Summary description for AuthorizeNetRequest
  13: /// </summary>
  14: public class AuthorizeNetRequest
  15: {
  16:     public AuthorizeNetRequest()
  17:     {
  18:         //
  19:         // TODO: Add constructor logic here
  20:         //
  21:     }
  22:  
  23:     #region Private Member(s)
  24:     private string mstrLogin;
  25:     private double mdblAmount;
  26:     private string mstrTransactionKey;    
  27:     private string mstrCardNumber;
  28:     private string mstrCardExpirationDate;
  29:     private AuthorizeNet.TransactionType enmTransactionType;    
  30:     private string mstrTransactionId; 
  31:     #endregion
  32:  
  33:     #region Public Propertie(s)
  34:     public string TransactionId
  35:     {
  36:         get { return mstrTransactionId; }
  37:         set { mstrTransactionId = value; }
  38:     }
  39:  
  40:  
  41:     public string CardNumber
  42:     {
  43:         get { return mstrCardNumber; }
  44:         set { mstrCardNumber = value; }
  45:     }
  46:  
  47:  
  48:     public double Amount
  49:     {
  50:         get { return mdblAmount; }
  51:         set { mdblAmount = value; }
  52:     }
  53:  
  54:  
  55:     public string Login
  56:     {
  57:         get { return mstrLogin; }
  58:         set { mstrLogin = value; }
  59:     }
  60:  
  61:     public string CardExpirationDate
  62:     {
  63:         get { return mstrCardExpirationDate; }
  64:         set { mstrCardExpirationDate = value; }
  65:     }
  66:  
  67:     public string TransactionKey
  68:     {
  69:         get { return mstrTransactionKey; }
  70:         set { mstrTransactionKey = value; }
  71:     }
  72:  
  73:     public AuthorizeNet.TransactionType TransactionType
  74:     {
  75:         get { return enmTransactionType; }
  76:         set { enmTransactionType = value; }
  77:     }
  78:     #endregion
  79:     
  80: }

Fig (2) AuthorizeNetRequest.cs implements Request class.

   1: using System;
   2: using System.Data;
   3: using System.Configuration;
   4: using System.Web;
   5: using System.Web.Security;
   6: using System.Web.UI;
   7: using System.Web.UI.WebControls;
   8: using System.Web.UI.WebControls.WebParts;
   9: using System.Web.UI.HtmlControls;
  10: using System.Collections.Generic;
  11:  
  12: /// <summary>
  13: /// Summary description for AuthorizeNetResponse
  14: /// </summary>
  15: public class AuthorizeNetResponse
  16: {
  17:     public AuthorizeNetResponse()
  18:     {
  19:         //
  20:         // TODO: Add constructor logic here
  21:         //
  22:     }
  23:  
  24:     private string mstrTransactionId;
  25:     private string mlstErrors;
  26:     private string mlstSuccessMessage;
  27:  
  28:     public string SuccessMessage
  29:     {
  30:         get { return mlstSuccessMessage; }
  31:         set { mlstSuccessMessage = value; }
  32:     }
  33:     
  34:     private bool mblnIsSuccess;
  35:  
  36:     public bool IsSuccess
  37:     {
  38:         get { return mblnIsSuccess; }
  39:         set { mblnIsSuccess = value; }
  40:     }
  41:  
  42:  
  43:     public string Errors
  44:     {
  45:         get { return mlstErrors; }
  46:         set { mlstErrors = value; }
  47:     }
  48:  
  49:  
  50:     public string TransactionId
  51:     {
  52:         get { return mstrTransactionId; }
  53:         set { mstrTransactionId = value; }
  54:     }
  55:     
  56: }

Fig (3) AuthorizeNetRespose.cs implements Response class.


Finally Default.aspx.cs page which call Authorize.Net method.

   
   1: public partial class _Default : System.Web.UI.Page 
   2: {
   3:     private const string TRANSACTION_KEY = "Transaction Key";
   4:     private const string CREDITCARD_NUMBER = "Card number";
   5:     private const string LOGINID = "Login id";
   6:     private const string CARD_EXPIRATION_DATE = "MM-YY";
   7:  
   8:     private string TransationID
   9:     {
  10:         get
  11:         {
  12:             if (ViewState["TransationID"] == null)
  13:                 ViewState["TransationID"] = string.Empty;
  14:  
  15:             return (string)ViewState["TransationID"];
  16:         }
  17:         set
  18:         {
  19:             ViewState["TransationID"] = value;
  20:         }
  21:     }
  22:  
  23:     protected void Page_Load(object sender, EventArgs e)
  24:     {
  25:         lblMessage.Text = string.Empty;
  26:         lblTransType.Text = string.Empty;
  27:     }
  28:  
  29:     private void DoAuthorizationAndPayment()
  30:     {
  31:         AuthorizeNetRequest objAuthorizeNetRequest = new AuthorizeNetRequest();
  32:         
  33:         // This is the account information for merchant account given by Authorize.Net people in email
  34:         // I can see transaction history here.
  35:         objAuthorizeNetRequest.Login = LOGINID; 
  36:         objAuthorizeNetRequest.Amount = 10.00;
  37:         objAuthorizeNetRequest.CardNumber = CREDITCARD_NUMBER; 
  38:         objAuthorizeNetRequest.CardExpirationDate = CARD_EXPIRATION_DATE;
  39:         objAuthorizeNetRequest.TransactionType = AuthorizeNet.TransactionType.AUTH_CAPTURE;
  40:         
  41:         // Below is the API created by me by registering for test account.
  42:         
  43:         objAuthorizeNetRequest.TransactionKey = TRANSACTION_KEY;
  44:  
  45:         AuthorizeNetResponse objAuthorizeNetResponse = AuthorizeNet.CallAuthorizeNetMethod(objAuthorizeNetRequest);
  46:  
  47:         lblTransType.Text = "Authorize And Capture";
  48:  
  49:         if (objAuthorizeNetResponse.IsSuccess)
  50:         {
  51:             TransationID = objAuthorizeNetResponse.TransactionId;            
  52:             lblMessage.Text =  "Success. Transaction ID : " + objAuthorizeNetResponse.TransactionId;
  53:         }
  54:         else
  55:         {
  56:             lblMessage.Text =  "Error : " + objAuthorizeNetResponse.Errors;
  57:         }
  58:  
  59:     }
  60: }
http://chiragrdarji.wordpress.com/2008/02/25/authorizenet-integration-using-aspnet/
Radhika roy replied to Naresh Kumar on 22-Aug-11 09:42 AM

You'll have to use https://www.paypal.com/ipn for that. My site runs with Perl, but the way it basically works is as follows:

  1. Customer fills out an order form at my site with their name, address, email.
  2. Customer is being redirected to Paypal
  3. Upon successful payment via Paypal, Paypal calls my IPN-compliant script
  4. My script sends me an e-mail notifying me about the completed order

If the customer does not pay within 30 minutes or so, my database also sends him a reminder with a Paypal payment link for the respective order. 

Follow these links also-

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_download_sdkshttp://www.spiderweblogic.com/Paypal-Integration-Code.aspx



Hope this will help you.