internationalization/localization, RT12515
[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     <TR>
158       <TD ALIGN="right"><% mt('ABA/Routing number') |h %></TD>
159       <TD>
160         <INPUT TYPE="text" SIZE=10 MAXLENGTH=9 NAME="payinfo2" VALUE="<%$payinfo2%>">
161         (<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>)
162       </TD>
163     </TR>
164     <TR>
165       <TD ALIGN="right"><% mt('Bank name') |h %></TD>
166       <TD><INPUT TYPE="text" NAME="payname" VALUE="<%$payname%>"></TD>
167     </TR>
168
169 %   if ( $conf->exists('show_bankstate') ) {
170       <TR>
171         <TD ALIGN="right"><% mt('Bank state') |h %></TD>
172         <TD><& /elements/select-state.html,
173                          'disable_empty' => 0,
174                          'empty_label'   => emt('(choose)'),
175                          'state'         => $paystate,
176                          'country'       => $cust_main->country,
177                          'prefix'        => 'pay',
178             &>
179         </TD>
180       </TR>
181 %   } else {
182       <INPUT TYPE="hidden" NAME="paystate" VALUE="<% $paystate %>">
183 %   }
184
185 %   if ( $conf->exists('show_ss') ) {
186       <TR>
187         <TD ALIGN="right">
188           <% mt('Account holder') |h %><BR>
189           <% mt('Social security or tax ID #') |h %> 
190         </TD>
191         <TD><INPUT TYPE="text" NAME="ss" VALUE="<% $ss %>"></TD>
192       </TR>
193 %   } else {
194       <INPUT TYPE="hidden" NAME="ss" VALUE="<% $ss %>"></TD>
195 %   }
196
197 %   if ( $conf->exists('show_stateid') ) {
198       <TR>
199         <TD ALIGN="right">
200           <% mt('Account holder') |h %><BR>
201           <% mt("Driver's license or state ID #") |h %> 
202         </TD>
203         <TD><INPUT TYPE="text" NAME="stateid" VALUE="<% $stateid %>"></TD>
204         <TD ALIGN="right"><% mt('State') |h %></TD>
205         <TD><& /elements/select-state.html,
206                          'disable_empty' => 0,
207                          'empty_label'   => emt('(choose)'),
208                          'state'         => $stateid_state,
209                          'country'       => $cust_main->country,
210                          'prefix'        => 'stateid_',
211             &>
212         </TD>
213       </TR>
214 %   } else {
215       <INPUT TYPE="hidden" NAME="stateid" VALUE="<% $stateid %>">
216       <INPUT TYPE="hidden" NAME="stateid_state" VALUE="<% $stateid_state %>">
217 %   }
218
219 % } #end CARD/CHEK-specific section
220
221
222 <TR>
223   <TD COLSPAN=2>
224     <INPUT TYPE="checkbox" CHECKED NAME="save" VALUE="1">
225     <% mt('Remember this information') |h %>
226   </TD>
227 </TR>
228
229 % if ( $conf->exists("batch-enable")
230 %      || grep $payby eq $_, $conf->config('batch-enable_payby')
231 %    ) {
232 %
233 %     if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
234
235           <INPUT TYPE="hidden" NAME="batch" VALUE="1">
236
237 %     } else {
238
239           <TR>
240             <TD COLSPAN=2>
241               <INPUT TYPE="checkbox" NAME="batch" VALUE="1">
242               <% mt('Add to current batch') |h %> 
243             </TD>
244           </TR>
245
246 %     }
247 % }
248
249 <TR>
250   <TD COLSPAN=2>
251     <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; }">
252     <% mt("Charge future payments to this [_1] automatically",$type{$payby}) |h %> 
253   </TD>
254 </TR>
255
256 </TABLE>
257
258 <BR>
259 <INPUT TYPE="submit" NAME="process" VALUE="<% mt('Process payment') |h %>">
260 </FORM>
261
262 <& /elements/footer.html &>
263 <%init>
264
265 die "access denied"
266   unless $FS::CurrentUser::CurrentUser->access_right('Process payment');
267
268 my %type = ( 'CARD' => 'credit card',
269              'CHEK' => 'electronic check (ACH)',
270            );
271
272 $cgi->param('payby') =~ /^(CARD|CHEK)$/
273   or die "unknown payby ". $cgi->param('payby');
274 my $payby = $1;
275
276 $cgi->param('custnum') =~ /^(\d+)$/
277   or die "illegal custnum ". $cgi->param('custnum');
278 my $custnum = $1;
279
280 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
281 die "unknown custnum $custnum" unless $cust_main;
282
283 my $balance = $cust_main->balance;
284
285 my $payinfo = '';
286
287 my $conf = new FS::Conf;
288
289 my $money_char = $conf->config('money_char') || '$';
290
291 #false laziness w/selfservice make_payment.html shortcut for one-country
292 my %states = map { $_->state => 1 }
293                qsearch('cust_main_county', {
294                  'country' => $conf->config('countrydefault') || 'US'
295                } );
296 my @states = sort { $a cmp $b } keys %states;
297
298 my $fee = '';
299 my $fee_pkg = '';
300 my $fee_display = '';
301 my $fee_op = '';
302 my $num_payments = scalar($cust_main->cust_pay);
303 #handle old cust_main.pm (remove...)
304 $num_payments = scalar( @{ [ $cust_main->cust_pay ] } )
305   unless defined $num_payments;
306 if ( $conf->config('manual_process-pkgpart')
307      and ! $conf->exists('manual_process-skip_first') || $num_payments
308    )
309 {
310
311   $fee_display = $conf->config('manual_process-display') || 'add';
312   $fee_op = $fee_display eq 'add' ? '+' : '-';
313
314   $fee_pkg =
315     qsearchs('part_pkg', { pkgpart=>$conf->config('manual_process-pkgpart') } );
316
317   #well ->unit_setup or ->calc_setup both call for a $cust_pkg
318   # (though ->unit_setup doesn't use it...)
319   $fee = $fee_pkg->option('setup_fee')
320     if $fee_pkg; #in case.. better than dying with a perl traceback
321
322 }
323
324 my $amount = '';
325 if ( $balance > 0 ) {
326   $amount = $balance;
327   $amount += $fee
328     if $fee && $fee_display eq 'subtract';
329
330   my $cc_surcharge_pct = $conf->config('credit-card-surcharge-percentage');
331   $amount += $amount * $cc_surcharge_pct/100 if $cc_surcharge_pct > 0;
332
333   $amount = sprintf("%.2f", $amount);
334 }
335
336 my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32;
337
338 </%init>