start
[Business-OnlineThirdPartyPayment-FCMB.git] / faker / UpayTransactionStatus.ashx
1 #!/usr/bin/perl -T
2
3 use CGI;
4 use Cache::FileCache;
5 use strict;
6 use XML::LibXML;
7
8 my $cache = Cache::FileCache->new(
9   { cache_root => '/tmp', namespace => 'FCMB-Faker' }
10 );
11
12 my @status = (
13   'Successful', 'Failed', 'Pending', 'Cancelled', 'Not Processed',
14   'Invalid Merchant', 'Inactive Merchant', 'Inactive Order ID',
15   'Duplicate Order ID', 'Invalid Amount'
16 );
17
18 my $cgi = CGI->new;
19 my $oid = $cgi->param('ORDER_ID');
20
21 # inefficient, but this is not production code, so who cares?
22 my ($txn) = grep { $_->{orderId} eq $oid }
23             map  { $cache->get($_) } $cache->get_keys;
24 my @out;
25 if ($txn) {
26   @out = (
27     MerchantID          => $txn->{mercId},
28     OrderID             => $txn->{orderId},
29     StatusCode          => $txn->{status},
30     Status              => $status[$txn->{status}],
31     Amount              => sprintf('%.2f', $txn->{amt}),
32     Date                => $txn->{date},
33     TransactionRef      => $txn->{reference},
34     PaymentRef          => sprintf('%06d', rand(1000000)),
35     ResponseCode        => sprintf('%02d', rand(100)),
36     ResponseDescription => 'response description',
37     CurrencyCode        => $txn->{currCode},
38   );
39 } else {
40   @out = ( Status => 'Invalid Order ID', StatusCode => '07' );
41 }
42 my $doc = XML::LibXML::Document->new;
43 my $root = $doc->createElement('UPay');
44 $doc->setDocumentElement($root);
45 while (@out) {
46   my $name = shift @out;
47   my $value = shift @out;
48   my $node = $doc->createElement($name);
49   $node->appendChild( XML::LibXML::Text->new($value) );
50   $root->appendChild($node);
51 }
52
53 my $content = $doc->toString;
54 print $cgi->header('text/xml');
55 print $content;