Browse DevX
Sign up for e-mail newsletters from DevX


Credit Card Processing

This solution demonstrates how to process credit cards with a popular processing service called CyberCash—using CyberCash's COM component CyberCashMCK.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

f you haven't done electronic credit card processing yet, you may be asked to do it soon. Don't sweat, it's not as difficult as it sounds—actually it's quite simple. In this Solution, I will demonstrate how to process credit cards with a popular processing service called CyberCash—using CyberCash's COM component CyberCashMCK.

First the big picture. There are four players involved in an online credit card transaction:

  • The card holder making the purchase
  • The online store offering the product or service, aka the merchant
  • A financial institution such as a bank that handles the financial transaction between the card holder and the merchant
  • An online credit card processing service such as CyberCash that mediates the transaction between the merchant and the financial institution by asking the financial institution to execute the transaction and informing the merchant as to whether the transaction was successful.
The first step in setting up an online credit card processing system is to set up a merchant account with a bank. Once you have your merchant account, you can become a CyberCash merchant at www.cybercash.com. The next step is to download and install the Merchant Connection Kit (MCK) that contains the CyberCashMCK component and configuration file. You cannot download the MCK from Cybercash without registering first, however, documentation is available to everyone at www.cybercash.com/support.

The CyberCashMCK component is a COM component and can be used either in a VB component or in an ASP script. CyberCashMCK has two objects, MessageBlock and Socket. MessageBlock is similar to a Dictionary object and is used to store information about the transaction such as credit card number, and price. The Socket object is used to execute the transaction by communicating with CyberCash's central processing service called CashRegister.

There are four steps you have to take to execute a transaction:

1. Populate a Dictionary object with CyberCash configuration information
The MCK setup configures a configuration file called Merchant_Conf that contains parameters you will need to execute a CyberCash transaction, such as your CyberCash ID. The MCK comes with a file called CCMckLib.inc that includes a VBScript function called InitConfig that initializes a Dictionary object with all the configuration information. You should incorporate the function into your component or script.

2. Populate the MessageBlock object with configuration and payment information
The MessageBlock requires two blocks of information. The cpi block that contains card information, and the mo block that contains configuration and price information. Each block is made up of a string containing several parameters. Each parameter is prefixed with the block identifier, mo or cpi. The parameters are concatenated with ampersands. An example of these blocks would be:

mo.cybercash-id=123&mo.version= _ order-id=123&mo.price=usd12 cpi.card-number=411111111111&cpi.card-exp=6/00&cpi.card-name=visa&cpi. _ card-address=123 Main Street&cpi.card-city=NY&cpi.card-state=NY&cpi. _ card-zip=11230&cpi.card-country=usa

The MessageBlock object has an Add method that takes name value pairs. Use the Add method to add each block as shown in the sample code below.

3. Call Socket's SendCCServer to execute the transaction
To actually execute the transaction, call the Socket objects SendCCServer method. It takes three parameters (sPaymentURL, sConfigLoc, pArgs).

  • sPaymentURL is the CashRegister URL that is supplied to you by CyberCash and found in your configuration file.
  • sConfigLoc is the file path and name of the CyberCash configuration file Merchant_Conf.
  • pArgs is MessageBlock object populated with configuration and payment information.
4. Check the MessageBlock object returned by the SendCCServer
The SendCCServer method returns a MessageBlock object that contains information about the transaction that was just executed. The pop.status key contains either "success" or "fail".

Cybercash has a merchant administration Web site in which you can view all your transactions. Cybercash also allows you to operate in test mode so that you can execute transactions during development. Transactions executed in test mode are not relayed to the bank but are visible on the administration site. That way you can check whether your code is working.

Sample Code
Here is what your code should look like:

'*************************************************** Function ExecutePayment() ' as CyberCashMCK.MessageBlock Dim objSock 'As CyberCashMCK.socket Dim objResult 'As CyberCashMCK.MessageBlock Dim objMsgBlock 'As CyberCashMCK.MessageBlock 'initialize global dictionary object gDictConfig with configuration info nStatus = InitConfig() Set objMsgBlock = CreateObject("CyberCashMCK.MessageBlock") 'retrieve CashRegister url from gDictConfig sPaymentURL = gDictConfig.Item("CCPS_HOST") & "directcardpayment.cgi" 'populate MessageBlock objMsgBlock.Add "MO", BuildString("mo") objMsgBlock.Add "CPI", BuildString("cpi") 'create Socket and execute transaction Set SockObj = Server.CreateObject("CyberCashMCK.socket.1") Set objResult = SockObj.SendCCServer(sPaymentURL, sConfigLoc, Args) Set ExecutePayment = objResult End Function '********************************************************* 'BuildString- encapsulates the creation of cpi and mo blocks 'this procedure assumes the payment and credit card information 'was posted to this page in an html form 'with the form elements having the name required by the MessageBlock Function BuildString(SType) Select Case LCase(SType) Case "mo" BuildString = "" & _ Server.urlencode("mo.cybercash-id") & "=" & _ Server.urlencode(gDictConfig.Item("CYBERCASH_ID")) & "&" & _ Server.urlencode("mo.version") & "=" & Server.urlencode _ ("") & "&" & _ Server.urlencode("mo.signed-cpi") & "=" & Server.urlencode _ ("no") & "&" & _ Server.urlencode("mo.order-id") & "=" & Server.urlencode _ (request("mo.order-id")) & "&" & _ Server.urlencode("mo.price") & "=" & Server.urlencode _ ("usd " & request("mo.price")) Case "cpi" BuildString = "" & _ Server.urlencode("cpi.card-number") & "=" & Server.urlencode _ (request("cpi.card-number")) & "&" & _ Server.urlencode("cpi.card-exp") & "=" & Server.urlencode _ (request("cpi.card-exp")) & "&" & _ Server.urlencode("cpi.card-name") & "=" & Server.urlencode _ (request("cpi.card-name")) & "&" & _ Server.urlencode("cpi.card-address") & "=" & Server.urlencode _ (request("cpi.card-address")) & "&" & _ Server.urlencode("cpi.card-city") & "=" & Server.urlencode _ (request("cpi.card-city")) & "&" & _ Server.urlencode("cpi.card-state") & "=" & Server.urlencode _ (request("cpi.card-state")) & "&" & _ Server.urlencode("cpi.card-zip") & "=" & Server.urlencode _ (request("cpi.card-zip")) & "&" & _ Server.urlencode("cpi.card-country") & "=" & Server.urlencode _ (request("cpi.card-country")) End Select End Function

I hope this Solution gave you an introduction to online credit card processing and a concise explanation of how to use CyberCash's component The CyberCash development kit comes with extensive sample code, but the code is complex and takes a lot of sifting through to figure out exactly how the component works.

Michael Gellis works at Flash Creative Management (a Microsoft Partner) as a Visual Basic developer. He is a Microsoft Certified Professional in VB5 and VB6 and is co-writing a book for Sybex on VB 6.0 and distributed applications. You can reach him here.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date