NetCharge Documentation

This contains all the information you need to use NetCharge. We intend to update this as new features are added. We also would like to know how to make the documentation clearer. If you have any suggestions let us know!
suggestion box

Installing

NOTE: You can run the supplied Install.sh program (as root) to quickly install everything except the cgi and utils programs. CGI programmers copy the cgi/c_test executable in their cgi-bin dir. The utils directory programs can be copied wherever you wish (/usr/local/bin is a good place).

NetCharge Requirements

Linux 1.2.x will not work. Shared MMAP is required. Please use a 1.3.x version (at least) of -ELF capable - Linux. A stable 2.0.x version of Linux - ELF capable - is recommended.

libg++-2.7.1.4 is required. The bins are available at tsx-11.mit.edu. Your distribution may already include these. You can check for them in /usr/lib. Please read the libg++ release for the libg++ requirements. They state (among other things) that libc 5.3.9 or greater is required.

Where to Install the netcharge executable

To be Linux file-system compliant, you need to install the netcharge executable in /usr/local/sbin.

Where to Install netcharge.conf

You need to copy netcharge.conf.dist to /etc and rename it to netcharge.conf.

Where to Install netcharge.num

You don't have to install this file, but you should be aware of it. NetCharge needs a unique transaction identifier to correspond SQL entries to file logs. This file saves the last unique number NetCharge generated before it shut down. If for some reason NetCharge dies (power failure, etc..) and this file isn't updated, (and you are using SQL logging) you must do a dump (select * from success) of the database to determine the last unique number in the keynum field. Increment this by one and place that - in ascii - in the netcharge.num file.

What to Change in /etc/services

You must place the line

netcharge	895/tcp	#BCSI's NetCharge

in your /etc/services file as NetCharge uses TCP/IP. We picked 895 as an example. You can pick any port you like under 1024. We recommend ports under 1024 so only the root user can start NetCharge. NetCharge is not a program that just any user should be able to run. NetCharge drops its privileges to your USER/GROUP settings in netcharge.conf almost instantly after starting.

Where to Install the Libraries

As usual, all dynamic shared libraries should go in /usr/local/lib. Copy the libraries (lib*.so.*), make symbolic links, and as root do a 'ldconfig -v'. You may find it much easier to run the Install.sh program.

Where to Install the CGI Demos

c_test is a working test CGI program (C source included of course) that you can use to see how easy it is to interface NetCharge to the web. Install the binary in your cgi-bin/ directory and use the included index.html file. Just fill out the form with any forms-capable browser and test away! We do recommend that you get the /utils/sale command line program working first as this will be easier to use when you are configuring netcharge.conf for the first time.

NetCharge SQL Support

NetCharge supports two Linux SQL databases: mSQL and Empress. When iODBC becomes better supported we will include that as well. iODBC will enable NetCharge to talk to any SQL database that has a Linux iODBC driver.

Note that Empress support increases the size of the executable by 1MB! If you are not logging to an Empress SQL database Linux won't page in all that unused code so NetCharge's real memory usage would be about 700K.

Since NetCharge logs to databases by clearing house protocol several merchants may wind up in the same database. Since this is an SQL database this is not a problem ie:

select * from success where merchant="bcsi";
*Please Note* that NetCharge gives each transaction a unique ID and stores this ID in the SQL database. The maximum value of this ID is 2147483647. You can not process more than 2147483647 (2^31) transactions in a row without backing up the SQL database. We're quite sure this won't be a problem:-)

mSQL

If you configure NetCharge to log to a mSQL database you must first create the mSQL database using the msqladmin command. Each protocol you are using will require its own database. ie:
msqladmin create mdi
After creating the mSQL database you should - although it's not *required* - add something like this to your msql.acl file to make it more secure:
(remember, substitute protocol with the protocol you're using)
database = protocol
read=*
write=*
host=your.host.com
access=local
mSQL is simple to use and configure. The mSQL API allows us to add tables so when NetCharge starts up and senses that the 'success' or 'fail' tables aren't there it simply creates them. The process is a lot different with Empress.

Empress

With Empress, you must create the database and the tables. Database creation:
empmkdb nabanco
Table creation:
empsql nabanco
Next cut and paste the following two SQL commands into the empsql program and type exit:
CREATE TABLE success (
authorization CHAR(7),
merchant CHAR(32),
date CHAR(12),
time CHAR(12),
product_code int,
keynum LONGINTEGER,
amount CHAR(9),
transaction_code CHAR(3),
transaction_number CHAR(5),
description_code CHAR(5),
card_number CHAR(17),
expiry CHAR(5),
ritid CHAR(16),
ltd CHAR(7),
rrn CHAR(13),
raci CHAR(1),
authsc CHAR(1),
rcc CHAR(3),
vcc CHAR(5),
tsn CHAR(5)
);


CREATE TABLE fail (
merchant CHAR(32),
card_number CHAR(17),
transaction_code CHAR(3),
amount CHAR(9),
expiry CHAR(5),
response CHAR(128),
date CHAR(7),
time CHAR(7),
description_code CHAR(5)
);

Starting NetCharge

NetCharge must be run as root. It will change to the configured user/group IDs as soon as it can. Make sure you have configured NetCharge BEFORE trying to run it! Note that this includes creating any necessary databases and making sure those databases have the proper permissions. If NetCharge fails to start check the syslog file.

Stopping NetCharge

As root - or the user NetCharge is running under - type:
kill <pid>
The is the process id of NetCharge. You find this by doing 'ps ax | grep netcharge'. You will notice more than one netcharge process. Kill the one (sounds nasty, doesn't it?) that has the lowest pid. Do not kill the other ones as the main process - the first process that starts - will signal all of the other netcharge processes to stop.

Files to configure

You have two files to configure: netcharge.conf and syslog.conf. Both are in /etc.

syslog.conf

This one requires only one line to be present and it may already be there. NetCharge logs all output to syslogd, facility LOG_DAEMON, level LOG_ERR. In order for you to examine NetCharge's error messages you must ensure that syslogd is configured properly with the line:

daemon.*          /var/log/daemon

You may already be logging daemon.* or daemon.err. If so, you can leave things as they are.

If you did add this line to your syslog.conf file, you (as root) must send a HUP signal to your syslogd so it re-reads the config file. ie:

#> ps ax | grep syslogd
  47  ?  S     0:00 /usr/sbin/syslogd
2683   1 S     0:00 grep syslogd
#> kill -HUP 47

netcharge.conf

This file contains three sections: global, device, and merchant. Any text after the '#' character is ignored (comments). While there can only be one global section, the number of device and merchant sections can be infinite.

<Global> Section

The options are case INsensitive. The values are case sensitive.

Working Dir

All logging is done in this directory. All SQL databases must reside here (except mSQL databases). The <merchant>.<procotol>.{success,error,totals} files, settlement directories, and settlement logs are all stored here.

<protocol>.database

True or False. If True all transactions are logged to an SQL database the next one or two options are required.

<protocol>.database.type

Defines which SQL database NetCharge shall use to log failed and successful transactions. See the database section for supported databases and rules concerning specific SQL databases.

If you are logging to an SQL database, you need to define this.

<protocol>.database.machine

Only required for mSQL databases. With mSQL, it is possible to log your transactions to a different machine over the network. If you do this, you should send it to a machine behind your corporate firewall or at least to a trusted network in your building.

User

Which user ID NetCharge shall run under. Make sure this user can write to the working dir!

Group

Which group ID NetCharge shall run under.

The <Merchant xxxx> Section

The options are case INsensitive. The values are case sensitive. The xxxx string shall be changed to the merchant name you wish to represent. ie:

<Merchant yourcompany>

The mandatory options are: Input Method, Clearing Protocol, and Merchant Number

AuthOnly Merchant Number

Used by MDI/GPS only. You will use this when you want to pre-authorize a sale, but not finalize the sale. If you don't finalize the sale, nothing will show up on the card-owner's statement. You do this by initiating an AUTHONLY, and you finalize it with a PREAUTH.

Category Code

NaBANCO/First Data only. They require that certain packets sent to their mainframes contain this code to determine what category the merchant is in.

Clearing Protocol

In Canada you have one option (tdsi) and in the U.S. you have two (nabanco and mdi). TDSI was bought out by SNS, but the protocol is still the TDSI protocol so we have kept that name. NaBANCO has been bought out by First Data, but First Data has their own protocol so to make sure they know how to set you up, we have kept the NaBANCO protocol name. MDI has been bought out by GPS. To keep things clear we still use the MDI protocol name.

Country Code

Required by NaBANCO only. They will give you this code.

Input Method

Right now, the only option is tcp. However, SSL will become available.

Language

Used by TDSI only. Choices are English and French.

Local Netcharge Number

Unused right now. Future protocols may use this.

MDI Number

MDI only. Usually a 4 character value determined by GPS.

Merchant Number

You will be given a merchant number by your clearing house. This is how the clearing house knows which transactions belong to your company.

Qual Code

NaBANCO only. First Data will give you this value.

SE.amex

NaBANCO only. If you want to process American Express cards, you will have to apply to Amex for a merchant number. Once you have this number, you must inform First Data and set this value to your Amex number.

SNS and GPS note: You need to apply to Amex as well, but you don't have to configure netcharge any differently; you just have to tell the respective clearing house your new merchant number and they'll take care of things for you.

SE.diners

Same as SE.amex, but you apply through diners.

SE.discover

Same as SE.amex, but you apply through discover. Note that SNS does not process discover cards.

SE.jcb

Same as SE.amex, but you apply through jcb.

Serial Number

NaBANCO only. Values you can use are 1-99. Designates more than one device per location.

State Code

NaBANCO only.

Store Number

MDI only. Different stores in a chain may want to use this.

ZIP/Postal Code

Standard ZIP/Postal Code.

<Device xxxx> Section

The options are case sensitive. The values are case INsensitive. The xxxx string shall be changed to the device name you wish to represent. ie:

<device ttyS0>

Connect Time

How long to wait for the modem CONNECT string.

Init

Your modem's INIT string. eg: ATZ

NOTE: This is probably the most important setting! This can cause you lots of frustration when starting up for the first time. NO clearing house supports any error correction, compression, or speed above 2400bps/baud. Don't even think about using a high speed modem without disabling ALL of the mentioned bad features.

Number

Phone number of the clearing house's modems.

Protocol

Which clearing protocol will this modem handle. You may want to dedicate three modems to one clearing house and two modems to another. You will want to do this if you set up shop as a mall and need to support multiple clearing houses simultaneously.

Redial

How many times shall NetCharge redial before giving up on the transaction.

Speed

What speed should your modem be set to. ie: 2400

What Is Settlement?

When we say 'settle' we mean two things: 1) when you tell the clearing house that a certain transaction is finalized and 2) the step that a clearing house takes to finalize the processing of the card. At approximately 3:00AM any given clearing house will take all of your settled transactions and start corresponding monetary transactions from the credit card companies into your merchant account. Transactions that haven't been settled will be ignored. Essentially, you settle your credit card transactions with your clearing house and that clearing house settles all of its transactions with the major credit card company.

Some protocols (NaBANCO, TDSI) require settling all of your transactions at once at the end of the day before those clearing houses start the monetary transactions. Other protocols (MDI) settle the transaction the instant you do a SALE or PREAUTH.

In any case, remember that if you are settling as soon as the SALE goes through or at the end of the day, monetary transfers won't occur until early next day. In some cases your bank or clearing house may prepare tapes that get sent to the bank to be processed which will delay your deposit. Also, different clearing houses and credit card institutions hold your money for different periods of time.

MDI Required <Merchant> Settings

In addition to the Standard <Merchant> Settings

Authonly Merchant Number

Store Number

MDI Number

MDI Commands

If you are using the MDI protocol you must reference only this section as other protocols can work slightly different.

AUTHONLY

Authorize a sale, but don't settle it. This allows you to authorize all day long and settle the transactions in one batch using PREAUTH at the end of your day. Dials out to complete transaction.

AVSSTREET

Process a sale and include street address AVS information. MDI settles the transaction immediately upon completion. Dials out to complete transaction.

AVSZIP

Process a sale and include ZIP/Postal code AVS information. MDI settles the transaction immediately upon completion. Dials out to complete transaction.

AVSZIPSTREET

Process a sale and include ZIP/Postal code and street address AVS information. MDI settles the transaction immediately upon completion. Dials out to complete transaction.

HOSTTOTALS

Displays the total sales for a particular card (VISA, MC, etc..) for the current day. Dials out to complete transaction.

PREAUTH

The counter-part to AUTHONLY. PREAUTH forces the settlement of the AUTHONLY transaction. Dials out to complete transaction.

REFUND

Negate a SALE. It is not possible for you to give money to a customer. It is possible to REFUND a previous SALE. Dials out to complete transaction.

SALE

Authorize a SALE and settle it. Dials out to complete transaction.

SETTLE

For MDI, this just cleans and backs up the current log files. Dials out to complete transaction.

NaBANCO Required <Merchant> Settings

In addition to the Standard <Merchant> Settings

Qual Code

State Code

Country Code

Category Code

Serial Number

Zip/Postal Code

NaBANCO Commands

If you are using the NaBANCO protocol you must reference only this section as other protocols can work slightly different.

REFUND

Refund money to a customer. No settlement. Does not dial out.

SALE

Authorize a SALE but not settle it. Dials out to complete transaction.

SETTLE

Talks to the clearing house and settles every single transaction since the last time you settled. Then if all goes well, the log files will be zeroed and backed up. Dials out to complete transaction.

VOID

VOID a transaction. It doesn't matter if the transaction was a REFUND or a SALE, this will ensure this particular transaction is not settled. Does not dial out.

TDSI Commands

If you are using the TDSI protocol you must reference only this section as other protocols can work slightly different.

REFUND

Negate a SALE. It is not possible for you to give money to a customer. It is possible to REFUND a previous SALE. No settlement is done.

SALE

Authorize a SALE but not settle it.

SETTLE

Talks to the clearing house and settles every single transaction since the last time you settled. Then if all goes well, the log files will be zeroed and backed up.

C Application Programming Interface

The interface to the NetCharge API is simple. You only have three function calls! To do a job, you fill out the proper fields in the transaction structure (defined in netc.h) and call netcConnect(), netcTransmit() and netcQuery. After defining these functions and the netc.h structure we will give you a couple of examples to get you started. Keep in mind that full source code has been distributed that shows how to use almost every command (in the utils dir).

int netcConnect(char *host)

SYNOPSIS: Connects to the NetCharge server(host).

If the server is NULL it connects to the local machine using UNIX domain sockets.

If the server is an IP address ie: "207.134.16.1" or a fully qualified domain name ie: "borg.bugless.com" it will use TCP/IP to connect to a NetCharge server on a different machine. People incorporating NetCharge support into their own programs will use this feature. See the Free NetCharge Library Implementation Example for more details on using this remote connectivity feature.

RETURNS: -1 on error and a NetCharge handle upon success.

response netcTransmit(int, transaction *)

SYNOPSIS: Transmits properly filled transaction structure to NetCharge server.

This routine validates all of the structure members it can before sending the data out to the NetCharge server.

NOTE: If the application has already connected to a non-NULL NetCharge server (a NetCharge server on another box) then this routine also connects to BCSI headquarters and logs the transaction attempt. See the Free NetCharge Library Implementation Example for more details on using this remote connectivity feature.

RETURNS: A response structure. This structure is defined in netc.h. The 'response' member tells us if we've succeeded, failed, or if we've received an Estimated Time of Arrival (ETA) response. The 'data' member gives us a text string reason why we've failed or the (ASCII) time in seconds that the server thinks it will take to process the transaction.

response netcQuery(int)

SYNOPSIS: Gets the NetCharge server's response to your query. This is a BLOCKING call. It will wait until either the server sends you a response or the user exits. A user can exit the process by simply clicking the Netscape 'STOP' button or leaving the site by selecting another URL to visit or quit the browser.

RETURNS: A response structure. Again, defined in netc.h. The 'response' member tells us if we've succeeded or failed. The 'data' member contains a text string explaining why we failed or an approval code upon success.

Example SALE transaction code

Remember, there are a lot more examples in the utils/ directory!
// gcc saletest.c -I../ -L../lib -lnetcharge -lg++
#include "netc.h"
#include 
#include 

int main()
{
	transaction t;
	response r;
	int s;
	
	// Fill in the transaction structure.
	strcpy(t.merchant, "test");
	strcpy(t.cardnum, "1234567890123");
	strcpy(t.expiry, "1299");
	strcpy(t.amount, "1.00");
	t.command = SALE;

	// Connects to local NetCharge server
	s = netcConnect(NULL);
	if (s == -1)
		return (-1);

	// Transmits the structure
	r = netcTransmit(s, &t);
	if (r.response == -1) {
		printf("\nError: %s\n",r.data);
		return (-1);
	}

	// Wait for the result
	r = netcQuery(s);
	if (r.response == 0) {
		printf("\n%s\n",r.data);
		return (0);
	}
	printf("\n%s\n",r.data);
	return (-1);
}

NetCharge Transaction Structure

typedef struct transaction {
	char merchant[MERCHANTSIZE];    /* which merchant are we processing? */
	char command;                   /* SALE, REFUND, etc.. */
	char protocol;                  /* NETCTEXT, NETCSCRAMBLE, NETCSSL */
	char cardnum[CARDSIZE];
	char expiry[EXPIRYSIZE];        /* forced MMYY */
	char amount[AMOUNTSIZE];        /* 999.50, 0.50, .50, .05 */
	/* Note, Library removes '.' internally */
	char auth[AUTHSIZE];            /* The saved authorization number */
	char operator_id[OPERATORSIZE]; /* For multiple terminals/merchant */
	char terminal_id[TERMINALSIZE]; /* Merchant # or Terminal # Internal use */
	int product_code;               /*Associates product code with transaction*/
	char ctype;                     /* Credit card type. Internal use only */
	char referencenum[REFERENCESIZE]; /* For TDSI */
	char st_address[ST_ADDRESSSIZE];/* address verification */
	char zip[ZIPSIZE];              /* address verification */
	char avsop[7];                      /* How to handle AVS return codes */
	char position[POSITIONSIZE];    /* Position in the success log */
	char host_total_level;          /* For MDI HOST TOTALS (settlement) */
	char from_date[7];              /* MMDDYY for HOST TOTALS */         
};

NetCharge Response Structure

typedef struct response {
	char response;  // 0,1,2 = Succeded, Failed, ETA response
	char data[128];
};                                        

Free NetCharge Library Implementation Example

Let's say you (corporation A) are developing an application and you distribute the shareware (limited) version for free over the Internet. When a person (B) wishes to register the software B runs a program (or choses an option) to register the software. A's program will ask B for his card information, place it in a transaction structure and make the three NetCharge library calls. We will assume B has TCP/IP working. The netcConnect() call will connect to A's NetCharge server. The netcTransmit() call will connect and register the transaction with BCSI headquarters so we know to invoice A for an extra 50 cents at the end of the month. Don't worry, all we do is send a large number representing the proper merchant(A), the destination IP address (A's NetCharge server address), the product code, and the command (we only bill A on successful SALE transactions). No confidential information about who the client is, what is being sold for how much, or even card info is sent to us. We just need to know who to bill (A, not B)! Once that is done, the entire transaction structure is sent to A's NetCharge server. A would pre-configure that address into A's application. A's program then calls netcQuery() to get the result. If the result is a successful sale transaction then the libraries contact BCSI headquarters and tell them the transaction was a successful sale. Only when all of this happens successfully do we add 50 cents to A's monthly bill.

Since the above happened successfully, A has B's money, we know to bill A for the use of the library, and B has a registered version of the software. It is now registered because A's software wrote a special key to B's disk that enabled the registered features.

Remember, this system is only used when the libraries to talk to remote NetCharge servers. This should never happen unless you are incorporating NetCharge functionality into custom applications.

Increased Sales

Since the user has an easy method of registering the software package, more user's will register. Who want's to take the time out of their day to write a cheque, find an envelope and stamp, and mail the registration? Besides, this doesn't work on an International level because a cheque isn't guaranteed funds. ie: The Canadian Royal Bank may not cash an Australian cheque! Someone from Australia may not even be able to register a Canadian application with an Australian cheque! That is... until NetCharge came along.

More people will register the game than copy it from a friend. If you make it easy to register, people will register! When people want something they want it now. They would register the application/service rather than wait for someone they know to bring the application over so they can copy it.

They would also like to register the application and use the registered features immediately instead of waiting for snail mail delivery of the registered version.

suggestion box