This commit was generated by cvs2svn to compensate for changes in r6252,
[freeside.git] / httemplate / edit / process / cust_refund.cgi
1 %if ( $error ) {
2 %  $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). "cust_refund.cgi?". $cgi->query_string ) %>
4 %} else {
5 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %>
6 %}
7 <%init>
8
9 die "access denied"
10   unless $FS::CurrentUser::CurrentUser->access_right('Refund payment');
11
12 $cgi->param('custnum') =~ /^(\d*)$/ or die "Illegal custnum!";
13 my $custnum = $1;
14 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
15   or die "unknown custnum $custnum";
16
17 my $error = '';
18 if ( $cgi->param('payby') =~ /^(CARD|CHEK)$/ ) { 
19   my %options = ();
20   my $bop = $FS::payby::payby2bop{$1};
21   $cgi->param('refund') =~ /^(\d*)(\.\d{2})?$/
22     or die "illegal refund amount ". $cgi->param('refund');
23   my $refund = "$1$2";
24   $cgi->param('paynum') =~ /^(\d*)$/ or die "Illegal paynum!";
25   my $paynum = $1;
26   my $reason = $cgi->param('reason');
27   my $paydate = $cgi->param('exp_year'). '-'. $cgi->param('exp_month'). '-01';
28   $options{'paydate'} = $paydate if $paydate =~ /^\d{2,4}-\d{1,2}-01$/;
29   $error = $cust_main->realtime_refund_bop( $bop, 'amount' => $refund,
30                                                   'paynum' => $paynum,
31                                                   'reason' => $reason,
32                                                   %options );
33 } else {
34   die 'unimplemented';
35   #my $new = new FS::cust_refund ( {
36   #  map {
37   #    $_, scalar($cgi->param($_));
38   #  } ( fields('cust_refund'), 'paynum' )
39   #} );
40   #$error = $new->insert;
41 }
42
43 </%init>