diff options
author | Mark Wells <mark@freeside.biz> | 2013-06-28 16:36:47 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2013-06-28 16:36:47 -0700 |
commit | 472f07098c2e10ac025b132df098f4b51c14adb1 (patch) | |
tree | fb6f5bb33ff55b658b298f3cd00316c054225b82 /faker/UpayTransactionStatus.ashx |
start
Diffstat (limited to 'faker/UpayTransactionStatus.ashx')
-rwxr-xr-x | faker/UpayTransactionStatus.ashx | 55 |
1 files changed, 55 insertions, 0 deletions
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; |