From 472f07098c2e10ac025b132df098f4b51c14adb1 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 28 Jun 2013 16:36:47 -0700 Subject: start --- faker/ConfirmPayment.cgi | 45 ++++++++++++++++++++++++++++++++ faker/MakePayment.aspx | 43 +++++++++++++++++++++++++++++++ faker/UpayTransactionStatus.ashx | 55 ++++++++++++++++++++++++++++++++++++++++ faker/fcmb.conf | 35 +++++++++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100755 faker/ConfirmPayment.cgi create mode 100755 faker/MakePayment.aspx create mode 100755 faker/UpayTransactionStatus.ashx create mode 100644 faker/fcmb.conf (limited to 'faker') 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! + + Not FCMB Web Payment +

Confirm your payment

+
+ + + + + + +
Order #!.$transaction{orderId}.qq!
Product!.$transaction{prod}.qq!
Amount !.$transaction{amt}.qq!
First Name
Last Name

+ + + +
+ + +!; + +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 @@ + + + ServerAdmin webmaster@localhost + + DocumentRoot /var/www + + Options FollowSymLinks + AllowOverride None + + + Options Indexes FollowSymLinks MultiViews + AllowOverride None + Order allow,deny + allow from all + + + Options ExecCGI + AddHandler cgi-script .cgi .aspx .ashx + + + 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 + + + -- cgit v1.2.1