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