CreditCardProcessor

Program to add new credit card accounts, process charges and credits against them, and display summary information.

Usage

In the credit_card_processor repository run:

gem install credit_card_processor

Then run:

bundle install

to get dependencies.

Then run the executable from bin:

credit_card_processor -f path_to_myfile.txt

Design Decisions

This was written in ruby 1.9.3. I decided to use sqlite with sequel in order to load the accounts into a database structure for processing. This can be easily transitioned from a sqlite db to a real db if needed. Although it's outside the scope of this assignment it would probably be useful to store all charges and credits in a ledger table, along with the transaction date and time. This is money so it's good to have a paper trail.

I'm using trollop as a command line parser here, which may be overkill considering there is only one option. But it's easy to implement and includes a nice help screen.

The code first creates a table called accounts. It then parses an input file and takes any "Add" lines and inserts them into the account table along with the credit limit (called credit_available) and a balance of $0. It strips the dollar signs for integer processing and later math. If the credit card number does not pass luhn validation, it is inserted as "error". I used an existing gem for luhn validation rather than write one myself.

When it encounters a "Charge" line, it first checks that it does not exceed the credit available for that name. If not, it increases the balance and decreases the credit available. A charge is not subject to credit available check, but when processed increases the credit available and decreases the balance. Both charge and credit lines only processed if the name listed exists in the accounts table.

After processing all lines, it outputs either "name: $balance" or "name: error" depending on whether or not the credit card number can be validated. This does not prevent charge/credit processing; it just displays the error at the end.

Finally I didn't push this to rubygems because I wasn't sure Braintree wanted this code out in the wild. Therefore it cannot be installed as a gem, although bundle install can be used to get dependencies.