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