Using the Credit Card Processing Classes

The process of charging cards is based on a few key tasks:

  • Set up the credit card request by setting properties
  • Call the ValidateCard() method
  • Check the result

Since the classes provide a very similar model you can very easily build a routine that handles credit card processing for multiple providers. The following example is taken from the busInvoice object and demonstrates generic usage of both the ccAccessPoint and ccPayFlowPro classes in a business object:

public bool ProcessCreditCard() 
{
	bool Result = false;

	DataRowContainers.wws_invoiceRow  Inv = this.GetTypedDataRow(); 
	DataRowContainers.wws_customersRow Cust = this.Customer.GetTypedDataRow();
	
	ccProcessing CC = null;
	ccProcessors CCType = App.Configuration.CCProcessor;

	try 
	{
		if (CCType == ccProcessors.AccessPoint)
		{
			CC = new ccAccessPoint();
		}
		else if (CCType == ccProcessors.PayFlowPro) 
		{
			CC = new ccPayFlowPro();
			CC.MerchantPassword = App.Configuration.CCMerchantPassword;
		}
		else if(CCType == ccProcessors.AuthorizeNet) 
		{
			CC = new ccAuthorizeNet();
			CC.MerchantPassword = App.Configuration.CCMerchantPassword;
		}

		//CC.UseTestTransaction = true;

		// *** Disable this for testing to get provider response
		CC.UseMod10Check = true;

		CC.Timeout = App.Configuration.CCConnectionTimeout;
		CC.HttpLink = App.Configuration.CCHostUrl;
		CC.MerchantId = App.Configuration.CCMerchantId;
		CC.LogFile = App.Configuration.CCLogFile;
		CC.ReferingUrl = App.Configuration.CCReferingOrderUrl;

		CC.OrderId = Inv.Invno.TrimEnd() + "_" + DateTime.Now.ToString();
		//CC.Name = Cust.Firstname.TrimEnd() + " " + Cust.Lastname.TrimEnd();
		CC.Firstname = Cust.Firstname.TrimEnd();
		CC.Lastname = Cust.Lastname.TrimEnd();

		CC.Company = Cust.Company.TrimEnd();
		CC.Address = Cust.Address.TrimEnd();
		CC.State = Cust.State.TrimEnd();
		CC.City = Cust.City.TrimEnd();
		CC.Zip = Cust.Zip.TrimEnd();
		CC.Country = Cust.Country.TrimEnd();
		CC.Phone = Cust.Phone.TrimEnd();
		CC.Email = Cust.Email.TrimEnd();

		CC.OrderAmount = Inv.Invtotal; 
		CC.TaxAmount = Inv.Tax;
		CC.CreditCardNumber = Inv.Cc.TrimEnd();
		CC.CreditCardExpiration = Inv.Ccexp.TrimEnd();

		CC.SecurityCode = Inv.Ccsecurity.TrimEnd();
	
		CC.Comment = "West Wind Technologies Order # " + Inv.Invno.TrimEnd();

		Result = CC.ValidateCard();
		
		Inv.Ccresult  = CC.ValidatedResult;
		if (!Result) 
		{
			this.ErrorMessage = CC.ValidatedMessage;
			Inv.Ccerror = this.ErrorMessage;
		}

		// *** Always write out the raw response
		if (wwUtils.Empty(CC.RawProcessorResult))
			Inv.Ccresultx = CC.ValidatedMessage; 
		else
			Inv.Ccresultx  = CC.RawProcessorResult; 
	}
	catch(Exception ex) 
	{
		this.SetError(ex.Message);
		Inv.Ccresult  = "FAILED";
		Inv.Ccresultx = "Processing Error: " + ex.Message;
		Inv.Ccerror = "Processing Error: " + ex.Message;
		return false;
	}

	return Result;
}

The properties for the processing are fairly straight forward. You provide name, address, credit card expiration date. The Expiration Date should always be provided in 12/2003 format of MM/YYYY. State codes are two letter codes, country values are 2 letter Country ISO codes.

The ValidateCard() method then takes all the input processes it and sets various result properties:

  • ValidatedResult
    This is a single message that says whether the card processing succeeded or not. It's either APPROVED, DECLINED, FAILED or FRAUD.

  • ValidatedMessage
    This is a parsed error message that contains just the error message from the provider or the hard connection error if a failure occurred at the API or network level.

  • RawProcessorResult
    The RawProcessorResult returns the full response from the server for reference. It's usually a good idea to store this value with any responses to insure you have all the reference numbers that go with transactions as well as see the true result if an unexpected error or error response occurs.

Logging

If you set LogFile property to a file name on disk you can cause the classes to automatically log each card process request result to a file. The filename must point at fully qualified OS path and the application must have rights to write to the file specified.


© West Wind Technologies, 1996-2018 • Updated: 01/29/16
Comment or report problem with topic