I tell you, we are here on Earth to fart around, and don't let anybody tell you different -- Kurt Vonnegut

CSE3WE Web Engineering - Assignment 2

Payment Processing Addendum

If you want to implement payment processing as part of your assignment, you may make use of the following pseudo-payment processing system. The Bank of WE provides a payment processing system which is accessible via the following URL:

http://ironbark.bendigo.latrobe.edu.au/subjects/WE/cgi/payment.cgi

In order to process a transaction you need to pass the following name/value pairs as part of the HTTP request:

cardno
A 16-digit credit card number.
cardtype
The type of credit card - 1 = VISA, 2 = Mastercard and 3 = AMEX.
cardexp
The expiry of the credit card in MM/YY format.
cardname
The name that is on the credit card.
amount
The amount that is to be charged to the card in dollars.

The payment processing response is provided as plain text, which will consist of a three digit status code, followed by a hyphen and a textual description. Possible return values include:

200 - Approved XXX
Transaction has been approved and the approval number is XXX.
300 - Timeout processing transaction
The transaction could not be processed within the required timeframe.
400 - Invalid card number
The credit card number supplied is invalid.
401 - Invalid card type
The credit card type supplied is invalid.
402 - Invalid card name
The credit card name supplied is invalid.
403 - Invalid card expiry
The credit card expiry supplied is invalid.
404 - Invalid amount
The amount supplied is invalid.
500 - Transaction declined
The transaction has been declined for an unspecified reason.
501 - Transaction declined due to insufficient funds
The transaction has been declined due to the credit card having insufficient funds.
502 - Transaction declined due to card limit
The transaction has been declined due to the amount exceeding the card limit.

The following code, which you may make use of in your assignment, demonstrates the use of the payment.cgi using LWP::UserAgent:

#!/usr/bin/perl

use LWP::UserAgent;

$ua = LWP::UserAgent->new;

print "Content-type: text/html\n\n";

$cardno = '4444333322221111';
$cardtype = '1'; 	# (1 = VISA, 2 = Mastercard, 3 = AMEX);
$cardexp = '05/11'; 	# (MM/YY)
$cardname = 'Fred Smith';
$amount = '115.95';

$url = "http://ironbark.bendigo.latrobe.edu.au/subjects/WE/cgi/payment.cgi?" . 
    "cardno=$cardno&cardtype=$cardtype&cardexp=$cardexp" . 
    "&cardname=$cardname&amount=$amount";

$rrr = $ua->request(HTTP::Request->new(GET => $url));

if ($rrr->is_success) {
    $response = $rrr->content;

    if ($response =~ /^200 - Approved (\d+)/) {
        $rcptno = $1;
        print "Transaction approved. Your receipt number is $rcptno\n";
    } else {
        print "Transaction failed: $response\n";
    }
} else {
    print "Error: " . $rrr->status_line . "\n";
}

The output from the above code is accessible here:

http://ironbark.bendigo.latrobe.edu.au/subjects/WE/cgi/paytest.cgi