echeck options to hide routing number and add account owner name, RT#13885
[freeside.git] / httemplate / misc / payment.cgi
1 <& /elements/header.html, mt("Process [_1] payment",$type{$payby})  &>
2 <& /elements/small_custview.html, $cust_main, '', '', popurl(2) . "view/cust_main.cgi" &>
3 <FORM NAME="OneTrueForm" ACTION="process/payment.cgi" METHOD="POST" onSubmit="document.OneTrueForm.process.disabled=true">
4 <INPUT TYPE="hidden" NAME="custnum"   VALUE="<% $custnum %>">
5 <INPUT TYPE="hidden" NAME="payby"     VALUE="<% $payby %>">
6 <INPUT TYPE="hidden" NAME="payunique" VALUE="<% $payunique %>">
7 <INPUT TYPE="hidden" NAME="balance"   VALUE="<% $balance %>">
8
9 <& /elements/init_overlib.html &>
10
11 <% ntable('#cccccc') %>
12   <TR>
13     <TH ALIGN="right"><% mt('Payment amount') |h %></TH>
14     <TD COLSPAN=7>
15       <TABLE><TR><TD BGCOLOR="#ffffff">
16         <% $money_char %><INPUT NAME     = "amount"
17                                 TYPE     = "text"
18                                 VALUE    = "<% $amount %>"
19                                 SIZE     = 8
20                                 STYLE    = "text-align:right;"
21 %                               if ( $fee ) {
22                                   onChange   = "amount_changed(this)"
23                                   onKeyDown  = "amount_changed(this)"
24                                   onKeyUp    = "amount_changed(this)"
25                                   onKeyPress = "amount_changed(this)"
26 %                               }
27                          >
28       </TD><TD BGCOLOR="#cccccc">
29 %        if ( $fee ) {
30            <INPUT TYPE="hidden" NAME="fee_pkgpart" VALUE="<% $fee_pkg->pkgpart %>">
31            <INPUT TYPE="hidden" NAME="fee" VALUE="<% $fee_display eq 'add' ? $fee : '' %>">
32            <B><FONT SIZE='+1'><% $fee_op %></FONT>
33               <% $money_char . $fee %>
34            </B>
35            <% $fee_pkg->pkg |h %>
36            <B><FONT SIZE='+1'>=</FONT></B>
37       </TD><TD ID="ajax_total_cell" BGCOLOR="#dddddd" STYLE="border:1px solid blue">
38            <FONT SIZE="+1"><% length($amount) ? $money_char. sprintf('%.2f', ($fee_display eq 'add') ? $amount + $fee : $amount - $fee ) : '' %> <% $fee_display eq 'add' ? 'TOTAL' : 'AVAILABLE' %></FONT>
39   
40 %        }
41       </TD></TR></TABLE>
42     </TD>
43   </TR>
44
45 % if ( $fee ) {
46
47     <SCRIPT TYPE="text/javascript">
48
49       function amount_changed(what) {
50
51
52         var total = '';
53         if ( what.value.length ) {
54           total = parseFloat(what.value) <% $fee_op %> <% $fee %>;
55           /* total = Math.round(total*100)/100; */
56           total = '<% $money_char %>' + total.toFixed(2);
57         }
58
59         var total_cell = document.getElementById('ajax_total_cell');
60         total_cell.innerHTML = '<FONT SIZE="+1">' + total + ' <% $fee_display eq 'add' ? 'TOTAL' : 'AVAILABLE' %></FONT>';
61
62       }
63
64     </SCRIPT>
65
66 % }
67
68 <& /elements/tr-select-discount_term.html,
69              'custnum' => $custnum,
70              'cgi'     => $cgi
71 &>
72
73 % if ( $payby eq 'CARD' ) {
74 %
75 %   my( $payinfo, $paycvv, $month, $year ) = ( '', '', '', '' );
76 %   my $payname = $cust_main->first. ' '. $cust_main->getfield('last');
77 %   if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) {
78 %     $payinfo = $cust_main->paymask;
79 %     $paycvv = $cust_main->paycvv;
80 %     ( $month, $year ) = $cust_main->paydate_monthyear;
81 %     $payname = $cust_main->payname if $cust_main->payname;
82 %   }
83
84     <TR>
85       <TH ALIGN="right"><% mt('Card number') |h %></TH>
86       <TD COLSPAN=7>
87         <TABLE>
88           <TR>
89             <TD>
90               <INPUT TYPE="text" NAME="payinfo" SIZE=20 MAXLENGTH=19 VALUE="<%$payinfo%>"> </TD>
91             <TH><% mt('Exp.') |h %></TH>
92             <TD>
93               <SELECT NAME="month">
94 % for ( ( map "0$_", 1 .. 9 ), 10 .. 12 ) { 
95
96                   <OPTION<% $_ == $month ? ' SELECTED' : '' %>><% $_ %>
97 % } 
98
99               </SELECT>
100             </TD>
101             <TD> / </TD>
102             <TD>
103               <SELECT NAME="year">
104 % my @a = localtime; for ( $a[5]+1900 .. $a[5]+1915 ) { 
105
106                   <OPTION<% $_ == $year ? ' SELECTED' : '' %>><% $_ %>
107 % } 
108
109               </SELECT>
110             </TD>
111           </TR>
112         </TABLE>
113       </TD>
114     </TR>
115     <TR>
116       <TH ALIGN="right"><% mt('CVV2') |h %></TH>
117       <TD><INPUT TYPE="text" NAME="paycvv" VALUE="<% $paycvv %>" SIZE=4 MAXLENGTH=4>
118           (<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>)
119       </TD>
120     </TR>
121     <TR>
122       <TH ALIGN="right"><% mt('Exact name on card') |h %></TH>
123       <TD><INPUT TYPE="text" SIZE=32 MAXLENGTH=80 NAME="payname" VALUE="<%$payname%>"></TD>
124     </TR>
125
126     <& /elements/location.html,
127                   'object'         => $cust_main, #XXX errors???
128                   'no_asterisks'   => 1,
129                   'address1_label' => emt('Card billing address'),
130     &>
131
132 % } elsif ( $payby eq 'CHEK' ) {
133 %
134 %   my( $payinfo1, $payinfo2, $payname, $ss, $paytype, $paystate,
135 %       $stateid, $stateid_state )
136 %     = ( '', '', '', '', '', '', '', '' );
137 %   if ( $cust_main->payby =~ /^(CHEK|DCHK)$/ ) {
138 %     $cust_main->paymask =~ /^([\dx]+)\@([\dx]*)$/i
139 %       or die "unparsable payinfo ". $cust_main->payinfo;
140 %     ($payinfo1, $payinfo2) = ($1, $2);
141 %     $payname = $cust_main->payname;
142 %     $ss = $cust_main->ss;
143 %     $paytype = $cust_main->getfield('paytype');
144 %     $paystate = $cust_main->getfield('paystate');
145 %     $stateid = $cust_main->getfield('stateid');
146 %     $stateid_state = $cust_main->getfield('stateid_state');
147 %   }
148
149     <INPUT TYPE="hidden" NAME="month" VALUE="12">
150     <INPUT TYPE="hidden" NAME="year" VALUE="2037">
151     <TR>
152       <TD ALIGN="right"><% mt('Account number') |h %></TD>
153       <TD><INPUT TYPE="text" SIZE=10 NAME="payinfo1" VALUE="<%$payinfo1%>"></TD>
154       <TD ALIGN="right"><% mt('Type') |h %></TD>
155       <TD><SELECT NAME="paytype"><% join('', map { qq!<OPTION VALUE="$_" !.($paytype eq $_ ? 'SELECTED' : '').">$_</OPTION>" } @FS::cust_main::paytypes) %></SELECT></TD>
156     </TR>
157 %   if ( $conf->exists('echeck-no_routing') ) {
158       <INPUT TYPE="text" NAME="payinfo2" VALUE="<%$payinfo2%>">
159 %   } else {
160       <TR>
161         <TD ALIGN="right"><% mt('ABA/Routing number') |h %></TD>
162         <TD>
163           <INPUT TYPE="text" SIZE=10 MAXLENGTH=9 NAME="payinfo2" VALUE="<%$payinfo2%>">
164           (<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>)
165         </TD>
166       </TR>
167 %   }
168     <TR>
169       <TD ALIGN="right"><% mt('Bank name') |h %></TD>
170       <TD><INPUT TYPE="text" NAME="payname" VALUE="<%$payname%>"></TD>
171     </TR>
172
173 %   if ( $conf->exists('show_bankstate') ) {
174       <TR>
175         <TD ALIGN="right"><% mt('Bank state') |h %></TD>
176         <TD><& /elements/select-state.html,
177                          'disable_empty' => 0,
178                          'empty_label'   => emt('(choose)'),
179                          'state'         => $paystate,
180                          'country'       => $cust_main->country,
181                          'prefix'        => 'pay',
182             &>
183         </TD>
184       </TR>
185 %   } else {
186       <INPUT TYPE="hidden" NAME="paystate" VALUE="<% $paystate %>">
187 %   }
188
189 %   if ( $conf->exists('show_ss') ) {
190       <TR>
191         <TD ALIGN="right">
192           <% mt('Account holder') |h %><BR>
193           <% mt('Social security or tax ID #') |h %> 
194         </TD>
195         <TD><INPUT TYPE="text" NAME="ss" VALUE="<% $ss %>"></TD>
196       </TR>
197 %   } else {
198       <INPUT TYPE="hidden" NAME="ss" VALUE="<% $ss %>"></TD>
199 %   }
200
201 %   if ( $conf->exists('show_stateid') ) {
202       <TR>
203         <TD ALIGN="right">
204           <% mt('Account holder') |h %><BR>
205           <% mt("Driver's license or state ID #") |h %> 
206         </TD>
207         <TD><INPUT TYPE="text" NAME="stateid" VALUE="<% $stateid %>"></TD>
208         <TD ALIGN="right"><% mt('State') |h %></TD>
209         <TD><& /elements/select-state.html,
210                          'disable_empty' => 0,
211                          'empty_label'   => emt('(choose)'),
212                          'state'         => $stateid_state,
213                          'country'       => $cust_main->country,
214                          'prefix'        => 'stateid_',
215             &>
216         </TD>
217       </TR>
218 %   } else {
219       <INPUT TYPE="hidden" NAME="stateid" VALUE="<% $stateid %>">
220       <INPUT TYPE="hidden" NAME="stateid_state" VALUE="<% $stateid_state %>">
221 %   }
222
223 % } #end CARD/CHEK-specific section
224
225
226 <TR>
227   <TD COLSPAN=2>
228     <INPUT TYPE="checkbox" CHECKED NAME="save" VALUE="1">
229     <% mt('Remember this information') |h %>
230   </TD>
231 </TR>
232
233 % if ( $conf->exists("batch-enable")
234 %      || grep $payby eq $_, $conf->config('batch-enable_payby')
235 %    ) {
236 %
237 %     if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
238
239           <INPUT TYPE="hidden" NAME="batch" VALUE="1">
240
241 %     } else {
242
243           <TR>
244             <TD COLSPAN=2>
245               <INPUT TYPE="checkbox" NAME="batch" VALUE="1">
246               <% mt('Add to current batch') |h %> 
247             </TD>
248           </TR>
249
250 %     }
251 % }
252
253 <TR>
254   <TD COLSPAN=2>
255     <INPUT TYPE="checkbox"<% ( ( $payby eq 'CARD' && $cust_main->payby ne 'DCRD' ) || ( $payby eq 'CHEK' && $cust_main->payby eq 'CHEK' ) ) ? ' CHECKED' : '' %> NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }">
256     <% mt("Charge future payments to this [_1] automatically",$type{$payby}) |h %> 
257   </TD>
258 </TR>
259
260 </TABLE>
261
262 <BR>
263 <INPUT TYPE="submit" NAME="process" VALUE="<% mt('Process payment') |h %>">
264 </FORM>
265
266 <& /elements/footer.html &>
267 <%init>
268
269 die "access denied"
270   unless $FS::CurrentUser::CurrentUser->access_right('Process payment');
271
272 my %type = ( 'CARD' => 'credit card',
273              'CHEK' => 'electronic check (ACH)',
274            );
275
276 $cgi->param('payby') =~ /^(CARD|CHEK)$/
277   or die "unknown payby ". $cgi->param('payby');
278 my $payby = $1;
279
280 $cgi->param('custnum') =~ /^(\d+)$/
281   or die "illegal custnum ". $cgi->param('custnum');
282 my $custnum = $1;
283
284 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
285 die "unknown custnum $custnum" unless $cust_main;
286
287 my $balance = $cust_main->balance;
288
289 my $payinfo = '';
290
291 my $conf = new FS::Conf;
292
293 my $money_char = $conf->config('money_char') || '$';
294
295 #false laziness w/selfservice make_payment.html shortcut for one-country
296 my %states = map { $_->state => 1 }
297                qsearch('cust_main_county', {
298                  'country' => $conf->config('countrydefault') || 'US'
299                } );
300 my @states = sort { $a cmp $b } keys %states;
301
302 my $fee = '';
303 my $fee_pkg = '';
304 my $fee_display = '';
305 my $fee_op = '';
306 my $num_payments = scalar($cust_main->cust_pay);
307 #handle old cust_main.pm (remove...)
308 $num_payments = scalar( @{ [ $cust_main->cust_pay ] } )
309   unless defined $num_payments;
310 if ( $conf->config('manual_process-pkgpart')
311      and ! $conf->exists('manual_process-skip_first') || $num_payments
312    )
313 {
314
315   $fee_display = $conf->config('manual_process-display') || 'add';
316   $fee_op = $fee_display eq 'add' ? '+' : '-';
317
318   $fee_pkg =
319     qsearchs('part_pkg', { pkgpart=>$conf->config('manual_process-pkgpart') } );
320
321   #well ->unit_setup or ->calc_setup both call for a $cust_pkg
322   # (though ->unit_setup doesn't use it...)
323   $fee = $fee_pkg->option('setup_fee')
324     if $fee_pkg; #in case.. better than dying with a perl traceback
325
326 }
327
328 my $amount = '';
329 if ( $balance > 0 ) {
330   $amount = $balance;
331   $amount += $fee
332     if $fee && $fee_display eq 'subtract';
333
334   my $cc_surcharge_pct = $conf->config('credit-card-surcharge-percentage');
335   $amount += $amount * $cc_surcharge_pct/100 if $cc_surcharge_pct > 0;
336
337   $amount = sprintf("%.2f", $amount);
338 }
339
340 my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32;
341
342 </%init>