summaryrefslogtreecommitdiff
path: root/faker
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2013-06-28 16:36:47 -0700
committerMark Wells <mark@freeside.biz>2013-06-28 16:36:47 -0700
commit472f07098c2e10ac025b132df098f4b51c14adb1 (patch)
treefb6f5bb33ff55b658b298f3cd00316c054225b82 /faker
start
Diffstat (limited to 'faker')
-rwxr-xr-xfaker/ConfirmPayment.cgi45
-rwxr-xr-xfaker/MakePayment.aspx43
-rwxr-xr-xfaker/UpayTransactionStatus.ashx55
-rw-r--r--faker/fcmb.conf35
4 files changed, 178 insertions, 0 deletions
diff --git a/faker/ConfirmPayment.cgi b/faker/ConfirmPayment.cgi
new file mode 100755
index 0000000..d4be353
--- /dev/null
+++ b/faker/ConfirmPayment.cgi
@@ -0,0 +1,45 @@
+#!/usr/bin/perl -T
+
+my $LANDING_URL =
+ "http://localhost:2080/selfservice.cgi?action=finish_thirdparty_payment";
+
+use CGI;
+use URI;
+use Date::Format 'time2str';
+use Cache::FileCache;
+use strict;
+
+my $cache = Cache::FileCache->new(
+ { cache_root => '/tmp', namespace => 'FCMB-Faker' }
+);
+
+my $landing = URI->new($LANDING_URL);
+
+my $cgi = CGI->new;
+my $reference = $cgi->param('reference');
+my $txn = $cache->get($reference);
+
+if ( $cgi->param('submit') eq 'Cancel' ) {
+ $txn->{status} = 3; #canceled
+ $landing->query_form(_cancel => 1);
+} else {
+
+ # some information captured from the customer
+ # (in Real Life this would also be their credit card/bank account number)
+ $txn->{first} = $cgi->param('first');
+ $txn->{last} = $cgi->param('last');
+ # set status = the last digit of cents
+ # (0 = success)
+ my $cents = ($txn->{amt} - int($txn->{amt})) * 100;
+ $txn->{status} = $cents % 10;
+ $txn->{date} = time2str('%Y-%m-%d', time);
+
+ $landing->query_form(
+ $landing->query_form,
+ 'OrderID' => $txn->{orderId},
+ 'TransactionReference' => $reference
+ );
+}
+# update the cache
+$cache->set($reference => $txn);
+print $cgi->redirect($landing);
diff --git a/faker/MakePayment.aspx b/faker/MakePayment.aspx
new file mode 100755
index 0000000..bd29a0d
--- /dev/null
+++ b/faker/MakePayment.aspx
@@ -0,0 +1,43 @@
+#!/usr/bin/perl -T
+
+use CGI;
+use Cache::FileCache;
+use strict;
+
+my $cache = Cache::FileCache->new(
+ { cache_root => '/tmp', namespace => 'FCMB-Faker' }
+);
+my $cgi = CGI->new;
+my %transaction = map { $_ => ($cgi->param($_) || '') }
+ qw( mercId currCode amt orderId prod email );
+
+my $reference = sprintf('%06d%04d', $transaction{mercId}, int(rand(10000)));
+$transaction{reference} = $reference;
+$transaction{status} = 2; #pending
+
+$cache->set($reference, \%transaction);
+
+my $content = qq!
+<HTML>
+ <HEAD><TITLE>Not FCMB Web Payment</TITLE></HEAD>
+ <BODY><H3>Confirm your payment</H3>
+ <FORM METHOD="POST" ACTION="ConfirmPayment.cgi">
+ <TABLE CELLSPACING=0 STYLE="border: 1px solid">
+ <TR><TD>Order #</TD><TD>!.$transaction{orderId}.qq!</TD></TR>
+ <TR><TD>Product</TD><TD>!.$transaction{prod}.qq!</TD></TR>
+ <TR><TD>Amount </TD><TD>!.$transaction{amt}.qq!</TD></TR>
+ <TR><TD>First Name</TD><TD><INPUT NAME="first"></TD></TR>
+ <TR><TD>Last Name</TD><TD><INPUT NAME="last"></TD></TR>
+ </TABLE><BR>
+ <INPUT TYPE="hidden" name="reference" value="!.$reference.qq!">
+ <INPUT TYPE="submit" name="submit" value="Pay Now">
+ <INPUT TYPE="submit" name="submit" value="Cancel">
+ </FORM>
+ </BODY>
+</HTML>
+!;
+
+print $cgi->header('text/html',
+ 'Content-Length' => length($content));
+print $content;
+
diff --git a/faker/UpayTransactionStatus.ashx b/faker/UpayTransactionStatus.ashx
new file mode 100755
index 0000000..a563cee
--- /dev/null
+++ b/faker/UpayTransactionStatus.ashx
@@ -0,0 +1,55 @@
+#!/usr/bin/perl -T
+
+use CGI;
+use Cache::FileCache;
+use strict;
+use XML::LibXML;
+
+my $cache = Cache::FileCache->new(
+ { cache_root => '/tmp', namespace => 'FCMB-Faker' }
+);
+
+my @status = (
+ 'Successful', 'Failed', 'Pending', 'Cancelled', 'Not Processed',
+ 'Invalid Merchant', 'Inactive Merchant', 'Inactive Order ID',
+ 'Duplicate Order ID', 'Invalid Amount'
+);
+
+my $cgi = CGI->new;
+my $oid = $cgi->param('ORDER_ID');
+
+# inefficient, but this is not production code, so who cares?
+my ($txn) = grep { $_->{orderId} eq $oid }
+ map { $cache->get($_) } $cache->get_keys;
+my @out;
+if ($txn) {
+ @out = (
+ MerchantID => $txn->{mercId},
+ OrderID => $txn->{orderId},
+ StatusCode => $txn->{status},
+ Status => $status[$txn->{status}],
+ Amount => sprintf('%.2f', $txn->{amt}),
+ Date => $txn->{date},
+ TransactionRef => $txn->{reference},
+ PaymentRef => sprintf('%06d', rand(1000000)),
+ ResponseCode => sprintf('%02d', rand(100)),
+ ResponseDescription => 'response description',
+ CurrencyCode => $txn->{currCode},
+ );
+} else {
+ @out = ( Status => 'Invalid Order ID', StatusCode => '07' );
+}
+my $doc = XML::LibXML::Document->new;
+my $root = $doc->createElement('UPay');
+$doc->setDocumentElement($root);
+while (@out) {
+ my $name = shift @out;
+ my $value = shift @out;
+ my $node = $doc->createElement($name);
+ $node->appendChild( XML::LibXML::Text->new($value) );
+ $root->appendChild($node);
+}
+
+my $content = $doc->toString;
+print $cgi->header('text/xml');
+print $content;
diff --git a/faker/fcmb.conf b/faker/fcmb.conf
new file mode 100644
index 0000000..f50dd8a
--- /dev/null
+++ b/faker/fcmb.conf
@@ -0,0 +1,35 @@
+<IfModule mod_ssl.c>
+<VirtualHost localhost:443>
+ ServerAdmin webmaster@localhost
+
+ DocumentRoot /var/www
+ <Directory />
+ Options FollowSymLinks
+ AllowOverride None
+ </Directory>
+ <Directory /var/www/>
+ Options Indexes FollowSymLinks MultiViews
+ AllowOverride None
+ Order allow,deny
+ allow from all
+ </Directory>
+ <Directory /var/www/customerportal>
+ Options ExecCGI
+ AddHandler cgi-script .cgi .aspx .ashx
+ </Directory>
+
+ ErrorLog ${APACHE_LOG_DIR}/fcmb_error.log
+
+ CustomLog ${APACHE_LOG_DIR}/fcmb_access.log combined
+
+ SSLEngine on
+ SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
+ SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
+
+ BrowserMatch "MSIE [2-6]" \
+ nokeepalive ssl-unclean-shutdown \
+ downgrade-1.0 force-response-1.0
+ BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
+
+</VirtualHost>
+</IfModule>