RT# 74435 - fixed errors in posting a echeck refund when no account is listed.
[freeside.git] / httemplate / elements / cust_payby_new.html
1 % my $auto = 0;
2 % if ( $payby eq 'CARD' ) {
3 %
4 %   my( $payinfo, $paycvv, $month, $year ) = ( '', '', '', '' );
5 %   my $payname = $cust_main->first. ' '. $cust_main->getfield('last');
6 %   my $location = $cust_main->bill_location;
7
8     <TR>
9       <TH ALIGN="right"><% mt('Card number') |h %></TH>
10       <TD COLSPAN=7>
11         <TABLE>
12           <TR>
13             <TD>
14               <INPUT TYPE="text" NAME="payinfo" SIZE=20 MAXLENGTH=19 VALUE="<%$payinfo%>"> </TD>
15             <TH><% mt('Exp.') |h %></TH>
16             <TD>
17               <SELECT NAME="month">
18 % for ( ( map "0$_", 1 .. 9 ), 10 .. 12 ) { 
19
20                   <OPTION<% $_ == $month ? ' SELECTED' : '' %>><% $_ %>
21 % } 
22
23               </SELECT>
24             </TD>
25             <TD> / </TD>
26             <TD>
27               <SELECT NAME="year">
28 % my @a = localtime; for ( $a[5]+1900 .. $a[5]+1915 ) { 
29
30                   <OPTION<% $_ == $year ? ' SELECTED' : '' %>><% $_ %>
31 % } 
32
33               </SELECT>
34             </TD>
35           </TR>
36         </TABLE>
37       </TD>
38     </TR>
39     <TR>
40       <TH ALIGN="right"><% mt('CVV2') |h %></TH>
41       <TD><INPUT TYPE="text" NAME="paycvv" VALUE="<% $paycvv %>" SIZE=4 MAXLENGTH=4>
42           (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/cvv2.html', 480, 352, 'cvv2_popup' ), CAPTION, 'CVV2 Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;"><% mt('help') |h %></A>)
43       </TD>
44     </TR>
45     <TR>
46       <TH ALIGN="right"><% mt('Exact name on card') |h %></TH>
47       <TD><INPUT TYPE="text" SIZE=32 MAXLENGTH=80 NAME="payname" VALUE="<%$payname%>"></TD>
48     </TR>
49
50     <& /elements/location.html,
51                   'object'         => $location,
52                   'no_asterisks'   => 1,
53                   'address1_label' => emt('Card billing address'),
54     &>
55
56 % } elsif ( $payby eq 'CHEK' ) {
57 %
58 %   my( $account, $aba, $branch, $payname, $ss, $paytype, $paystate,
59 %       $stateid, $stateid_state )
60 %     = ( '', '', '', '', '', '', '', '', '' );
61 %
62 %  #false laziness w/{edit,view}/cust_main/billing.html
63 %  my $routing_label = $conf->config('echeck-country') eq 'US'
64 %                        ? 'ABA/Routing number'
65 %                        : 'Routing number';
66 %  my $routing_size      = $conf->config('echeck-country') eq 'CA' ? 4 : 10;
67 %  my $routing_maxlength = $conf->config('echeck-country') eq 'CA' ? 3 : 9;
68
69     <INPUT TYPE="hidden" NAME="month" VALUE="12">
70     <INPUT TYPE="hidden" NAME="year" VALUE="2037">
71     <TR>
72       <TD ALIGN="right"><% mt('Account number') |h %></TD>
73       <TD><INPUT TYPE="text" SIZE=10 NAME="payinfo1" VALUE="<%$account%>"></TD>
74       <TD ALIGN="right"><% mt('Type') |h %></TD>
75       <TD><SELECT NAME="paytype"><% join('', map { qq!<OPTION VALUE="$_" !.($paytype eq $_ ? 'SELECTED' : '').">$_</OPTION>" } FS::cust_payby->paytypes) %></SELECT></TD>
76     </TR>
77     <TR>
78       <TD ALIGN="right"><% mt($routing_label) |h %></TD>
79       <TD>
80         <INPUT TYPE="text" SIZE="<% $routing_size %>" MAXLENGTH="<% $routing_maxlength %>" NAME="payinfo2" VALUE="<%$aba%>">
81         (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/ach.html', 380, 240, 'ach_popup' ), CAPTION, 'ACH Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;"><% mt('help') |h %></A>)
82       </TD>
83     </TR>
84 %   if ( $conf->config('echeck-country') eq 'CA' ) {
85       <TR>
86         <TD ALIGN="right"><% mt('Branch number') |h %></TD>
87         <TD>
88           <INPUT TYPE="text" NAME="payinfo3" VALUE="<%$branch%>" SIZE=6 MAXLENGTH=5>
89         </TD>
90       </TR>
91 %   }
92     <TR>
93       <TD ALIGN="right"><% mt('Bank name') |h %></TD>
94       <TD><INPUT TYPE="text" NAME="payname" VALUE="<%$payname%>"></TD>
95     </TR>
96
97 %   if ( $conf->exists('show_bankstate') ) {
98       <TR>
99         <TD ALIGN="right"><% mt('Bank state') |h %></TD>
100         <TD><& /elements/select-state.html,
101                          'disable_empty' => 0,
102                          'empty_label'   => emt('(choose)'),
103                          'state'         => $paystate,
104                          'country'       => $cust_main->country,
105                          'prefix'        => 'pay',
106             &>
107         </TD>
108       </TR>
109 %   } else {
110       <INPUT TYPE="hidden" NAME="paystate" VALUE="<% $paystate %>">
111 %   }
112
113 %   if ( $conf->exists('show_ss') ) {
114       <TR>
115         <TD ALIGN="right">
116           <% mt('Account holder') |h %><BR>
117           <% mt('Social security or tax ID #') |h %> 
118         </TD>
119         <TD><INPUT TYPE="text" NAME="ss" VALUE="<% $ss %>"></TD>
120       </TR>
121 %   } else {
122       <INPUT TYPE="hidden" NAME="ss" VALUE="<% $ss %>"></TD>
123 %   }
124
125 %   if ( $conf->exists('show_stateid') ) {
126       <TR>
127         <TD ALIGN="right">
128           <% mt('Account holder') |h %><BR>
129           <% mt("Driver's license or state ID #") |h %> 
130         </TD>
131         <TD><INPUT TYPE="text" NAME="stateid" VALUE="<% $stateid %>"></TD>
132         <TD ALIGN="right"><% mt('State') |h %></TD>
133         <TD><& /elements/select-state.html,
134                          'disable_empty' => 0,
135                          'empty_label'   => emt('(choose)'),
136                          'state'         => $stateid_state,
137                          'country'       => $cust_main->country,
138                          'prefix'        => 'stateid_',
139             &>
140         </TD>
141       </TR>
142 %   } else {
143       <INPUT TYPE="hidden" NAME="stateid" VALUE="<% $stateid %>">
144       <INPUT TYPE="hidden" NAME="stateid_state" VALUE="<% $stateid_state %>">
145 %   }
146
147 % } #end CARD/CHEK-specific section
148
149
150 <TR>
151   <TD COLSPAN=8>
152     <INPUT TYPE="checkbox" CHECKED NAME="save" VALUE="1">
153     <% mt('Remember this information') |h %>
154   </TD>
155 </TR>
156
157 <TR>
158   <TD COLSPAN=8>
159     <INPUT TYPE="checkbox"<% $auto ? ' CHECKED' : '' %> NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }">
160     <% mt("Charge future payments to this [_1] automatically",$type{$payby}) |h %> 
161 % if ( @cust_payby ) {
162     <% mt('as') |h %>
163     <SELECT NAME="weight">
164 %     for ( 1 .. 1+scalar(grep { $_->payby =~ /^(CARD|CHEK)$/ } @cust_payby) ) {
165         <OPTION VALUE="<%$_%>"><% mt( $weight{$_} ) |h %>
166 %     }
167     </SELECT>
168 % } else {
169     <INPUT TYPE="hidden" NAME="weight" VALUE="1">
170 % }
171   </TD>
172 </TR>
173
174 <%once>
175
176 my %weight = (
177   1 => 'Primary',
178   2 => 'Secondary',
179   3 => 'Tertiary',
180   4 => 'Fourth',
181   5 => 'Fifth',
182   6 => 'Sixth',
183   7 => 'Seventh',
184 );
185
186 </%once>
187
188 <%init>
189
190 my %opt = @_;
191
192 my @cust_payby = @{$opt{cust_payby}};
193
194 my %type = ( 'CARD' => 'credit card',
195              'CHEK' => 'electronic check (ACH)',
196            );
197
198 $cgi->param('payby') =~ /^(CARD|CHEK)$/
199   or die "unknown payby ". $cgi->param('payby');
200 my $payby = $1;
201
202 $cgi->param('custnum') =~ /^(\d+)$/
203   or die "illegal custnum ". $cgi->param('custnum');
204 my $custnum = $1;
205
206 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
207 die "unknown custnum $custnum" unless $cust_main;
208
209 my $balance = $cust_main->balance;
210
211 my $payinfo = '';
212
213 my $conf = new FS::Conf;
214
215 #false laziness w/selfservice make_payment.html shortcut for one-country
216 my %states = map { $_->state => 1 }
217                qsearch('cust_main_county', {
218                  'country' => $conf->config('countrydefault') || 'US'
219                } );
220 my @states = sort { $a cmp $b } keys %states;
221
222 </%init>