batch refactor continued
[freeside.git] / httemplate / edit / process / cust_refund.cgi
1                         %
2 %
3 %$cgi->param('custnum') =~ /^(\d*)$/ or die "Illegal custnum!";
4 %my $custnum = $1;
5 %my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
6 %  or die "unknown custnum $custnum";
7 %
8 %my $error = '';
9 %if ( $cgi->param('payby') =~ /^(CARD|CHEK)$/ ) { 
10 %  my $bop = FS::payby::$payby2bop{$1};
11 %  $cgi->param('refund') =~ /^(\d*)(\.\d{2})?$/
12 %    or die "illegal refund amount ". $cgi->param('refund');
13 %  my $refund = "$1$2";
14 %  $cgi->param('paynum') =~ /^(\d*)$/ or die "Illegal paynum!";
15 %  my $paynum = $1;
16 %  my $reason = $cgi->param('reason');
17 %  $error = $cust_main->realtime_refund_bop( $bop, 'amount' => $refund,
18 %                                                  'paynum' => $paynum,
19 %                                                  'reason' => $reason, );
20 %} else {
21 %  die 'unimplemented';
22 %  #my $new = new FS::cust_refund ( {
23 %  #  map {
24 %  #    $_, scalar($cgi->param($_));
25 %  #  } ( fields('cust_refund'), 'paynum' )
26 %  #} );
27 %  #$error = $new->insert;
28 %}
29 %
30 %
31 %if ( $error ) {
32 %  $cgi->param('error', $error);
33 %  print $cgi->redirect(popurl(2). "cust_refund.cgi?". $cgi->query_string );
34 %} else {
35 %  print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");
36 %}
37 %
38 %
39