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