manual echeck payment type, RT#26995
[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 %
6 %  if ( $link eq 'popup' ) {
7 %
8 <% header('Refund entered') %>
9     <SCRIPT TYPE="text/javascript">
10       window.top.location.reload();
11     </SCRIPT>
12
13     </BODY></HTML>
14 %  } else {
15 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %>
16 %  }
17 %}
18 <%init>
19
20 die "access denied"
21   unless $FS::CurrentUser::CurrentUser->access_right('Refund payment')
22       || $FS::CurrentUser::CurrentUser->access_right('Post refund');
23
24 $cgi->param('custnum') =~ /^(\d*)$/ or die "Illegal custnum!";
25 my $custnum = $1;
26 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
27   or die "unknown custnum $custnum";
28
29 my $link    = $cgi->param('popup') ? 'popup' : '';
30
31 my $payby = $cgi->param('payby');
32
33 my @rights = ();
34 push @rights, 'Post refund'                if $payby =~ /^(BILL|CASH|MCRD|MCHK)$/;
35 push @rights, 'Post check refund'          if $payby eq 'BILL';
36 push @rights, 'Post cash refund '          if $payby eq 'CASH';
37 push @rights, 'Refund payment'             if $payby =~ /^(CARD|CHEK)$/;
38 push @rights, 'Refund credit card payment' if $payby eq 'CARD';
39 push @rights, 'Refund Echeck payment'      if $payby eq 'CHEK';
40
41 die "access denied"
42   unless $FS::CurrentUser::CurrentUser->access_right(\@rights);
43
44 $cgi->param('reasonnum') =~ /^(-?\d+)$/ or die "Illegal reasonnum";
45 my ($reasonnum, $error) = $m->comp('/misc/process/elements/reason');
46 $cgi->param('reasonnum', $reasonnum) unless $error;
47
48 if ( $error ) {
49   # do nothing
50 } elsif ( $payby =~ /^(CARD|CHEK)$/ ) { 
51   my %options = ();
52   my $bop = $FS::payby::payby2bop{$1};
53   $cgi->param('refund') =~ /^(\d*)(\.\d{2})?$/
54     or die "illegal refund amount ". $cgi->param('refund');
55   my $refund = "$1$2";
56   $cgi->param('paynum') =~ /^(\d*)$/ or die "Illegal paynum!";
57   my $paynum = $1;
58   my $reason = $cgi->param('reason');
59   my $paydate = $cgi->param('exp_year'). '-'. $cgi->param('exp_month'). '-01';
60   $options{'paydate'} = $paydate if $paydate =~ /^\d{2,4}-\d{1,2}-01$/;
61   $error = $cust_main->realtime_refund_bop( $bop, 'amount' => $refund,
62                                                   'paynum' => $paynum,
63                                                   'reason' => $reason,
64                                                   %options );
65 } else {
66   my $new = new FS::cust_refund ( {
67     map {
68       $_, scalar($cgi->param($_));
69     } fields('cust_refund') #huh? , 'paynum' )
70   } );
71   $error = $new->insert;
72 }
73
74 </%init>