summaryrefslogtreecommitdiff
path: root/faker/UpayTransactionStatus.ashx
blob: a563cee4e2391bdf2f2b96614d160d6257086214 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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;