start
[Business-OnlineThirdPartyPayment-FCMB.git] / faker / ConfirmPayment.cgi
1 #!/usr/bin/perl -T
2
3 my $LANDING_URL =
4   "http://localhost:2080/selfservice.cgi?action=finish_thirdparty_payment";
5
6 use CGI;
7 use URI;
8 use Date::Format 'time2str';
9 use Cache::FileCache;
10 use strict;
11
12 my $cache = Cache::FileCache->new(
13   { cache_root => '/tmp', namespace => 'FCMB-Faker' }
14 );
15
16 my $landing = URI->new($LANDING_URL);
17
18 my $cgi = CGI->new;
19 my $reference = $cgi->param('reference');
20 my $txn = $cache->get($reference);
21
22 if ( $cgi->param('submit') eq 'Cancel' ) {
23   $txn->{status} = 3; #canceled
24   $landing->query_form(_cancel => 1);
25 } else {
26
27   # some information captured from the customer
28   # (in Real Life this would also be their credit card/bank account number)
29   $txn->{first} = $cgi->param('first');
30   $txn->{last}  = $cgi->param('last');
31   # set status = the last digit of cents
32   # (0 = success)
33   my $cents = ($txn->{amt} - int($txn->{amt})) * 100;
34   $txn->{status} = $cents % 10;
35   $txn->{date} = time2str('%Y-%m-%d', time);
36
37   $landing->query_form(
38     $landing->query_form,
39     'OrderID' => $txn->{orderId},
40     'TransactionReference' => $reference
41   );
42 }
43 # update the cache
44 $cache->set($reference => $txn);
45 print $cgi->redirect($landing);