RT# 81616 Mask CVV on Process Card Payment page
[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
13   <& /elements/tr-amount_fee.html,
14        'amount'             => $amount,
15        'process-pkgpart'    => 
16           scalar($conf->config('manual_process-pkgpart', $cust_main->agentnum)),
17        'process-display'    => scalar($conf->config('manual_process-display')),
18        'process-skip_first' => $conf->exists('manual_process-skip_first'),
19        'num_payments'       => scalar($cust_main->cust_pay), 
20        'surcharge_percentage' =>
21          ( $payby eq 'CARD'
22              ? scalar($conf->config('credit-card-surcharge-percentage', $cust_main->agentnum))
23              : 0
24          ),
25        'surcharge_flatfee' =>
26          ( $payby eq 'CARD'
27              ? scalar($conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum))
28              : 0
29          ),
30   &>
31
32 % if ( $conf->exists('part_pkg-term_discounts') ) {
33     <& /elements/tr-select-discount_term.html,
34          'custnum'   => $custnum,
35          'amount_id' => 'amount',
36     &>
37 % }
38
39 % if ( $payby eq 'CARD' ) {
40 %
41 %   my( $payinfo, $paycvv, $month, $year ) = ( '', '', '', '' );
42 %   my $payname = $cust_main->first. ' '. $cust_main->getfield('last');
43 %   if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) {
44 %     $payinfo = $cust_main->paymask;
45 %     ( $paycvv = $cust_main->paycvv ) =~ s/./*/g;
46 %     ( $month, $year ) = $cust_main->paydate_monthyear;
47 %     $payname = $cust_main->payname if $cust_main->payname;
48 %   } elsif ($disable_payauto_default) {
49 %     $auto = 0;
50 %   }
51
52     <TR>
53       <TH ALIGN="right"><% mt('Card number') |h %></TH>
54       <TD COLSPAN=7>
55         <TABLE>
56           <TR>
57             <TD>
58               <INPUT TYPE="text" NAME="payinfo" SIZE=20 MAXLENGTH=19 VALUE="<%$payinfo%>"<% ($auto && $disable_payauto_default) ? $possibly_uncheck_auto : '' %>> </TD>
59             <TH><% mt('Exp.') |h %></TH>
60             <TD>
61               <SELECT NAME="month">
62 % for ( map{ sprintf('%02d',$_) } (1..12) ) {
63                   <OPTION VALUE="<% $_ %>"<% $_ == $month ? ' SELECTED' : '' %>><% $_ %></OPTION>
64 % } 
65
66               </SELECT>
67             </TD>
68             <TD> / </TD>
69             <TD>
70               <SELECT NAME="year">
71 % my @a = localtime; for ( $a[5]+1900 .. $a[5]+1915 ) { 
72                   <OPTION VALUE="<% $_ %>"<% $_ == $year ? ' SELECTED' : '' %>><% $_ %></OPTION>
73 % } 
74
75               </SELECT>
76             </TD>
77           </TR>
78         </TABLE>
79       </TD>
80     </TR>
81     <TR>
82       <TH ALIGN="right"><% mt('CVV2') |h %></TH>
83       <TD><INPUT TYPE="text" NAME="paycvv" VALUE="<% $paycvv %>" SIZE=4 MAXLENGTH=4>
84           (<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>)
85       </TD>
86     </TR>
87     <TR>
88       <TH ALIGN="right"><% mt('Exact name on card') |h %></TH>
89       <TD><INPUT TYPE="text" SIZE=32 MAXLENGTH=80 NAME="payname" VALUE="<%$payname%>"></TD>
90     </TR>
91
92     <& /elements/location.html,
93                   'object'         => $cust_main->bill_location,
94                   'no_asterisks'   => 1,
95                   'address1_label' => emt('Card billing address'),
96     &>
97
98 % } elsif ( $payby eq 'CHEK' ) {
99 %
100 %   my( $account, $aba, $branch, $payname, $ss, $paytype, $paystate,
101 %       $stateid, $stateid_state )
102 %     = ( '', '', '', '', '', '', '', '', '' );
103 %   if ( $cust_main->payby =~ /^(CHEK|DCHK)$/ ) {
104 %     $cust_main->paymask =~ /^([\dx]+)\@([\d\.x]*)$/i
105 %       or die "unparsable payinfo ". $cust_main->payinfo;
106 %     ($account, $aba) = ($1, $2);
107 %     ($branch,$aba) = split('\.',$aba)
108 %       if $conf->config('echeck-country') eq 'CA';
109 %     $payname = $cust_main->payname;
110 %     $ss = $cust_main->ss;
111 %     $paytype = $cust_main->getfield('paytype');
112 %     $paystate = $cust_main->getfield('paystate');
113 %     $stateid = $cust_main->getfield('stateid');
114 %     $stateid_state = $cust_main->getfield('stateid_state');
115 %   } elsif ($disable_payauto_default) {
116 %     $auto = 0;
117 %   }
118 %
119 %  #false laziness w/{edit,view}/cust_main/billing.html
120 %  my $routing_label = $conf->config('echeck-country') eq 'US'
121 %                        ? 'ABA/Routing number'
122 %                        : 'Routing number';
123 %  my $routing_size      = $conf->config('echeck-country') eq 'CA' ? 4 : 10;
124 %  my $routing_maxlength = $conf->config('echeck-country') eq 'CA' ? 3 : 9;
125
126     <INPUT TYPE="hidden" NAME="month" VALUE="12">
127     <INPUT TYPE="hidden" NAME="year" VALUE="2037">
128     <TR>
129       <TD ALIGN="right"><% mt('Account number') |h %></TD>
130       <TD><INPUT TYPE="text" SIZE=10 NAME="payinfo1" VALUE="<%$account%>"<% ($auto && $disable_payauto_default) ? $possibly_uncheck_auto : '' %>></TD>
131       <TD ALIGN="right"><% mt('Type') |h %></TD>
132       <TD><SELECT NAME="paytype"><% join('', map { qq!<OPTION VALUE="$_" !.($paytype eq $_ ? 'SELECTED' : '').">$_</OPTION>" } @FS::cust_main::paytypes) %></SELECT></TD>
133     </TR>
134     <TR>
135       <TD ALIGN="right"><% mt($routing_label) |h %></TD>
136       <TD>
137         <INPUT TYPE="text" SIZE="<% $routing_size %>" MAXLENGTH="<% $routing_maxlength %>" NAME="payinfo2" VALUE="<%$aba%>"<% ($auto && $disable_payauto_default) ? $possibly_uncheck_auto : '' %>>
138         (<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>)
139       </TD>
140     </TR>
141 %   if ( $conf->config('echeck-country') eq 'CA' ) {
142       <TR>
143         <TD ALIGN="right"><% mt('Branch number') |h %></TD>
144         <TD>
145           <INPUT TYPE="text" NAME="payinfo3" VALUE="<%$branch%>" SIZE=6 MAXLENGTH=5<% ($auto && $disable_payauto_default) ? $possibly_uncheck_auto : '' %>>
146         </TD>
147       </TR>
148 %   }
149     <TR>
150       <TD ALIGN="right"><% mt('Bank name') |h %></TD>
151       <TD><INPUT TYPE="text" NAME="payname" VALUE="<%$payname%>"></TD>
152     </TR>
153
154 %   if ( $conf->exists('show_bankstate') ) {
155       <TR>
156         <TD ALIGN="right"><% mt('Bank state') |h %></TD>
157         <TD><& /elements/select-state.html,
158                          'disable_empty' => 0,
159                          'empty_label'   => emt('(choose)'),
160                          'state'         => $paystate,
161                          'country'       => $cust_main->country,
162                          'prefix'        => 'pay',
163             &>
164         </TD>
165       </TR>
166 %   } else {
167       <INPUT TYPE="hidden" NAME="paystate" VALUE="<% $paystate %>">
168 %   }
169
170 %   if ( $conf->exists('show_ss') ) {
171       <TR>
172         <TD ALIGN="right">
173           <% mt('Account holder') |h %><BR>
174           <% mt('Social security or tax ID #') |h %> 
175         </TD>
176         <TD><INPUT TYPE="text" NAME="ss" VALUE="<% $ss %>"></TD>
177       </TR>
178 %   } else {
179       <INPUT TYPE="hidden" NAME="ss" VALUE="<% $ss %>"></TD>
180 %   }
181
182 %   if ( $conf->exists('show_stateid') ) {
183       <TR>
184         <TD ALIGN="right">
185           <% mt('Account holder') |h %><BR>
186           <% mt("Driver's license or state ID #") |h %> 
187         </TD>
188         <TD><INPUT TYPE="text" NAME="stateid" VALUE="<% $stateid %>"></TD>
189         <TD ALIGN="right"><% mt('State') |h %></TD>
190         <TD><& /elements/select-state.html,
191                          'disable_empty' => 0,
192                          'empty_label'   => emt('(choose)'),
193                          'state'         => $stateid_state,
194                          'country'       => $cust_main->country,
195                          'prefix'        => 'stateid_',
196             &>
197         </TD>
198       </TR>
199 %   } else {
200       <INPUT TYPE="hidden" NAME="stateid" VALUE="<% $stateid %>">
201       <INPUT TYPE="hidden" NAME="stateid_state" VALUE="<% $stateid_state %>">
202 %   }
203
204 % } #end CARD/CHEK-specific section
205
206
207 <TR>
208   <TD COLSPAN=2>
209     <INPUT TYPE="checkbox" CHECKED NAME="save" VALUE="1">
210     <% mt('Remember this information') |h %>
211   </TD>
212 </TR>
213
214 % my $disallow_no_auto_apply = 0;
215 % if ( $conf->exists("batch-enable")
216 %      || grep $payby eq $_, $conf->config('batch-enable_payby')
217 %    ) {
218 %
219 %     if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
220 %       $disallow_no_auto_apply = 1;
221
222           <INPUT TYPE="hidden" NAME="batch" VALUE="1">
223
224 %     } else {
225
226           <TR>
227             <TD COLSPAN=2>
228               <INPUT TYPE="checkbox" NAME="batch" VALUE="1" ID="batch_checkbox" ONCHANGE="change_batch_checkbox()">
229               <% mt('Add to current batch') |h %> 
230             </TD>
231           </TR>
232
233 %     }
234 % }
235
236 <TR>
237   <TD COLSPAN=2>
238     <INPUT ID="auto_checkbox" TYPE="checkbox"<% $auto ? ' CHECKED' : '' %> NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }">
239     <% mt("Charge future payments to this [_1] automatically",$type{$payby}) |h %> 
240   </TD>
241 </TR>
242
243 % unless ($disallow_no_auto_apply) {
244 %   # false laziness with edit/cust_pay.cgi
245
246 <TR ID="apply_box_row">
247   <TD COLSPAN=2>
248     <% mt('Auto-apply to invoices') |h %>
249     <SELECT NAME="apply" ID="apply_box">
250       <OPTION VALUE="yes" SELECTED><% mt('yes') |h %></OPTION> 
251       <OPTION VALUE=""><% mt('not now') |h %></OPTION>
252       <OPTION VALUE="never"><% mt('never') |h %></OPTION>
253     </SELECT>
254   </TD>
255 </TR>
256
257 % # this can go away if no_auto_apply handling gets added to batch payment processing
258 <SCRIPT>
259 function change_batch_checkbox () {
260   if (document.getElementById('batch_checkbox').checked) {
261     document.getElementById('apply_box').disabled = true;
262     document.getElementById('apply_box_row').style.display = 'none';
263   } else {
264     document.getElementById('apply_box').disabled = false;
265     document.getElementById('apply_box_row').style.display = '';
266   }
267 }
268 </SCRIPT>
269
270 % }
271
272 % if ($auto && $disable_payauto_default) {
273 <SCRIPT>
274 var unchecked_auto = false;
275 function possibly_uncheck_auto () {
276   if (!unchecked_auto) {
277     unchecked_auto = true;
278     document.getElementById('auto_checkbox').checked = false;
279   }
280 }
281 </SCRIPT>
282 % }
283
284 </TABLE>
285
286 <BR>
287 <INPUT TYPE="submit" NAME="process" VALUE="<% mt('Process payment') |h %>">
288 </FORM>
289
290 <& /elements/footer.html &>
291 <%init>
292
293 die "access denied"
294   unless $FS::CurrentUser::CurrentUser->access_right('Process payment');
295
296 my %type = ( 'CARD' => 'credit card',
297              'CHEK' => 'electronic check (ACH)',
298            );
299
300 $cgi->param('payby') =~ /^(CARD|CHEK)$/
301   or die "unknown payby ". $cgi->param('payby');
302 my $payby = $1;
303
304 $cgi->param('custnum') =~ /^(\d+)$/
305   or die "illegal custnum ". $cgi->param('custnum');
306 my $custnum = $1;
307
308 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
309 die "unknown custnum $custnum" unless $cust_main;
310
311 my $location = $cust_main->bill_location;
312 # no proper error handling on this anyway, but when we have it,
313 # remember to repopulate fields in $location
314
315 my $balance = $cust_main->balance;
316
317 my $payinfo = '';
318
319 my $conf = new FS::Conf;
320
321 my $auto = ( ( $payby eq 'CARD' && $cust_main->payby ne 'DCRD' ) || ( $payby eq 'CHEK' && $cust_main->payby eq 'CHEK' ) ) ? 1 : 0;
322 my $disable_payauto_default = $conf->exists('disable_payauto_default');
323 my $possibly_uncheck_auto = ' ONCHANGE="possibly_uncheck_auto()"';
324
325 #false laziness w/selfservice make_payment.html shortcut for one-country
326 my %states = map { $_->state => 1 }
327                qsearch('cust_main_county', {
328                  'country' => $conf->config('countrydefault') || 'US'
329                } );
330 my @states = sort { $a cmp $b } keys %states;
331
332 my $amount = '';
333 if ( $balance > 0 ) {
334   # when configured to do so, amount will only auto-fill with balance
335   # if balance represents a single invoice
336   $amount = $balance
337     unless $conf->exists('manual_process-single_invoice_amount')
338       && ($cust_main->open_cust_bill != 1);
339 }
340
341 my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32;
342
343 </%init>