summaryrefslogtreecommitdiff
path: root/faker/ConfirmPayment.cgi
blob: d4be35355fc935ca99efa5fe651179a4a6f2745d (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
#!/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);