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