This commit was generated by cvs2svn to compensate for changes in r3874,
[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 %payby2bop = (
11   'CARD' => 'CC',
12   'CHEK' => 'ECHECK',
13   );
14   my $bop = $payby2bop{$1};
15   $cgi->param('refund') =~ /^(\d*)(\.\d{2})?$/
16     or die "illegal refund amount ". $cgi->param('refund');
17   my $refund = "$1$2";
18   $cgi->param('paynum') =~ /^(\d*)$/ or die "Illegal paynum!";
19   my $paynum = $1;
20   my $reason = $cgi->param('reason');
21   $error = $cust_main->realtime_refund_bop( $bop, 'amount' => $refund,
22                                                   'paynum' => $paynum,
23                                                   'reason' => $reason, );
24 } else {
25   die 'unimplemented';
26   #my $new = new FS::cust_refund ( {
27   #  map {
28   #    $_, scalar($cgi->param($_));
29   #  } ( fields('cust_refund'), 'paynum' )
30   #} );
31   #$error = $new->insert;
32 }
33
34
35 if ( $error ) {
36   $cgi->param('error', $error);
37   print $cgi->redirect(popurl(2). "cust_refund.cgi?". $cgi->query_string );
38 } else {
39   print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");
40 }
41
42 %>