Payment Technology Blog

Explore our modern gateway designed to help you sell more, make more and keep more.

Sunday, May 30, 2010

How To: Credit Card and ACH (e-check) integration with ASP.NET / C#

This is the seventh part in a series of postings on how to integrate credit card and ACH/E-check transactions into various systems. This installment demonstrates code used for processing payments (credit card and/or ACH) within a .NET / C# application.

This was taken from the NELiX TransaX FleXport toolkit documentation. Credit card integration examples can be downloaded on the NELiX TransaX FleXport page.

Assumptions:
- Using NELiX TransaX Payment Gateway
- Communicating using NELiX TransaX Webservice

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void ContinueButton_Click(object sender, ImageClickEventArgs e)
{
RoXAPI_WebService.RoXAPI ws = new RoXAPI_WebService.RoXAPI();
RoXAPI_WebService.Params wsParams = new RoXAPI_WebService.Params();
RoXAPI_WebService.Responses wsResponse = new RoXAPI_WebService.Responses();

wsParams.TransactionType = TransactionType.SelectedValue;
wsParams.GatewayUserName = GatewayUserName.Text;
wsParams.GatewayPassword = GatewayPassword.Text;
wsParams.IPAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

wsParams.Merchant_Defined_Field_1 = Merchant_Defined_Field_1.Text;
wsParams.Merchant_Defined_Field_2 = Merchant_Defined_Field_2.Text;

if(TransactionType.SelectedValue == "void")
wsParams.TransactionID = TransactionID.Text;

if(TransactionType.SelectedValue == "refund")
{
wsParams.Amount = Amount.Text;
wsParams.TransactionID = TransactionID.Text;
}

if (TransactionType.SelectedValue == "capture" )
{
wsParams.Amount = Amount.Text;
wsParams.TransactionID = TransactionID.Text;
wsParams.OrderID = OrderID.Text;
wsParams.Tracking_Number = Tracking_Number.Text;
wsParams.Shipping_Carrier = Shipping_Carrier.Text;
}

if (TransactionType.SelectedValue == "update")
{
wsParams.TransactionID = TransactionID.Text;
wsParams.Tracking_Number = Tracking_Number.Text;
wsParams.Shipping_Carrier = Shipping_Carrier.Text;
}

if (Customer_Vault_Action.SelectedValue == "delete_customer")
{
wsParams.Customer_Vault_Action = Customer_Vault_Action.SelectedValue;
wsParams.Customer_Vault_ID = Customer_Vault_ID.Text;
}

if(TransactionType.SelectedValue == "sale" || TransactionType.SelectedValue == "auth" || Customer_Vault_Action.SelectedValue == "add_customer" || Customer_Vault_Action.SelectedValue == "update_customer" )
{
wsParams.PaymentType = PaymentType.SelectedValue;


if(Customer_Vault_Action.SelectedValue == "add_customer" || Customer_Vault_Action.SelectedValue == "update_customer" )
{
wsParams.Customer_Vault_Action = Customer_Vault_Action.SelectedValue;
}
wsParams.Customer_Vault_ID = Customer_Vault_ID.Text;

if (wsParams.PaymentType == "creditcard")
{
wsParams.CCNumber = CCNumber.Text;
wsParams.CCExpDate = CCExpDate.Text;
wsParams.CVV = CVV.Text;
}
if(wsParams.PaymentType == "check")
{
wsParams.CheckName = CheckName.Text;
wsParams.CheckABA = CheckABA.Text;
wsParams.CheckAccount = CheckAccount.Text;
wsParams.AccountHolderType = AccountHolderType.SelectedValue;
wsParams.AccountType = AccountType.SelectedValue;
wsParams.SecCode = SecCode.SelectedValue;
}

wsParams.Payment_Plan_SKU = Payment_Plan_SKU.Text;

wsParams.Amount = Amount.Text;
wsParams.Tax = Tax.Text;
wsParams.Shipping = Shipping.Text;
wsParams.OrderDescription = OrderDescription.Text;
wsParams.OrderID = OrderID.Text;
wsParams.PONumber = PONumber.Text;

wsParams.FirstName = FirstName.Text;
wsParams.LastName = LastName.Text;
wsParams.Company = Company.Text;
wsParams.Address1 = Address1.Text;
wsParams.Address2 = Address2.Text;
wsParams.City = City.Text;
wsParams.State = State.Text;
wsParams.Zip = Zip.Text;
wsParams.Country = Country.Text;
wsParams.Phone = Phone.Text;
wsParams.Fax = Fax.Text;
wsParams.EMail = EMail.Text;
wsParams.Website = Website.Text;

wsParams.ShippingFirstName = ShippingFirstName.Text;
wsParams.ShippingLastName = ShippingLastName.Text;
wsParams.ShippingCompany = ShippingCompany.Text;
wsParams.ShippingAddress1 = ShippingAddress1.Text;
wsParams.ShippingAddress2 = ShippingAddress2.Text;
wsParams.ShippingCity = ShippingCity.Text;
wsParams.ShippingState = ShippingState.Text;
wsParams.ShippingZip = ShippingZip.Text;
wsParams.ShippingCountry = ShippingCountry.Text;
wsParams.ShippingEmail = ShippingEmail.Text;

wsParams.ProcessorID = ProcessorID.Text;
wsParams.Descriptor = Descriptor.Text;
wsParams.DescriptorPhone = DescriptorPhone.Text;
}

wsResponse = ws.ProcessTransaction(wsParams);

MSG.Text = "STATUS_CODE: " + wsResponse.STATUS_CODE + "";
MSG.Text += "STATUS_MSG: " + wsResponse.STATUS_MSG + "";
MSG.Text += "TRANS_ID: " + wsResponse.TRANS_ID + "";
MSG.Text += "AUTH_CODE: " + wsResponse.AUTH_CODE + "";
MSG.Text += "AVS_CODE: " + wsResponse.AVS_CODE + "";
MSG.Text += "AVS_MSG: " + wsResponse.AVS_MSG + "";
MSG.Text += "CVV2_CODE: " + wsResponse.CVV2_CODE + "";
MSG.Text += "CVV2_MSG: " + wsResponse.CVV2_MSG + "";
MSG.Text += "ORDERID: " + wsResponse.ORDERID + "";
MSG.Text += "CUSTOMER_VAULT_ID: " + wsResponse.CUSTOMER_VAULT_ID + "";
MSG.Text += "FULLRESPONSE: " + wsResponse.FULLRESPONSE + "";
MSG.Text += "POSTSTRING: " + wsResponse.POSTSTRING + "";

if( wsResponse.STATUS_CODE == "1" )
{
MSG.Text = "SUCCESS!" + MSG.Text;
}
else
{
if( wsResponse.STATUS_CODE == "2")
MSG.Text = "DECLINE" + MSG.Text;
else
MSG.Text = "ERROR" + MSG.Text;

}


}
}


If you need any assistance with payment processing integration with your .NET system, we are here to help!

Download .NET /C# credit card and ACH (e-check) integration examples.



No comments:

The biggest advantage of our gateway comes from power that it puts in the hands of your developers. Easily integrate with your application and take advantage of features to enhance your system.

We invite you to a live demo and the opportunity to build a partnership. Our promise to partners is, through innovation, today's products will be relentlessly enhanced into tomorrow's solutions.

1921-A Rohlwing Road
Rolling Meadows IL 60008-4800
P) 866-513-1547
F) 866-513-1548
info@transaxgateway.com