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 %>">
9 <& /elements/init_overlib.html &>
11 <% ntable('#cccccc') %>
13 <TH ALIGN="right"><% mt('Payment amount') |h %></TH>
15 <TABLE><TR><TD BGCOLOR="#ffffff">
16 <% $money_char %><INPUT NAME = "amount"
18 VALUE = "<% $amount %>"
20 STYLE = "text-align:right;"
22 onChange = "amount_changed(this)"
23 onKeyDown = "amount_changed(this)"
24 onKeyUp = "amount_changed(this)"
25 onKeyPress = "amount_changed(this)"
28 </TD><TD BGCOLOR="#cccccc">
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 %>
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>
47 <SCRIPT TYPE="text/javascript">
49 function amount_changed(what) {
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);
59 var total_cell = document.getElementById('ajax_total_cell');
60 total_cell.innerHTML = '<FONT SIZE="+1">' + total + ' <% $fee_display eq 'add' ? 'TOTAL' : 'AVAILABLE' %></FONT>';
68 <& /elements/tr-select-discount_term.html,
69 'custnum' => $custnum,
73 % if ( $payby eq 'CARD' ) {
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;
85 <TH ALIGN="right"><% mt('Card number') |h %></TH>
90 <INPUT TYPE="text" NAME="payinfo" SIZE=20 MAXLENGTH=19 VALUE="<%$payinfo%>"> </TD>
91 <TH><% mt('Exp.') |h %></TH>
94 % for ( ( map "0$_", 1 .. 9 ), 10 .. 12 ) {
96 <OPTION<% $_ == $month ? ' SELECTED' : '' %>><% $_ %>
104 % my @a = localtime; for ( $a[5]+1900 .. $a[5]+1915 ) {
106 <OPTION<% $_ == $year ? ' SELECTED' : '' %>><% $_ %>
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>)
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>
126 <& /elements/location.html,
127 'object' => $cust_main, #XXX errors???
129 'address1_label' => emt('Card billing address'),
132 % } elsif ( $payby eq 'CHEK' ) {
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');
149 <INPUT TYPE="hidden" NAME="month" VALUE="12">
150 <INPUT TYPE="hidden" NAME="year" VALUE="2037">
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>
158 <TD ALIGN="right"><% mt('ABA/Routing number') |h %></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>)
165 <TD ALIGN="right"><% mt('Bank name') |h %></TD>
166 <TD><INPUT TYPE="text" NAME="payname" VALUE="<%$payname%>"></TD>
169 % if ( $conf->exists('show_bankstate') ) {
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,
182 <INPUT TYPE="hidden" NAME="paystate" VALUE="<% $paystate %>">
185 % if ( $conf->exists('show_ss') ) {
188 <% mt('Account holder') |h %><BR>
189 <% mt('Social security or tax ID #') |h %>
191 <TD><INPUT TYPE="text" NAME="ss" VALUE="<% $ss %>"></TD>
194 <INPUT TYPE="hidden" NAME="ss" VALUE="<% $ss %>"></TD>
197 % if ( $conf->exists('show_stateid') ) {
200 <% mt('Account holder') |h %><BR>
201 <% mt("Driver's license or state ID #") |h %>
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_',
215 <INPUT TYPE="hidden" NAME="stateid" VALUE="<% $stateid %>">
216 <INPUT TYPE="hidden" NAME="stateid_state" VALUE="<% $stateid_state %>">
219 % } #end CARD/CHEK-specific section
224 <INPUT TYPE="checkbox" CHECKED NAME="save" VALUE="1">
225 <% mt('Remember this information') |h %>
229 % if ( $conf->exists("batch-enable")
230 % || grep $payby eq $_, $conf->config('batch-enable_payby')
233 % if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
235 <INPUT TYPE="hidden" NAME="batch" VALUE="1">
241 <INPUT TYPE="checkbox" NAME="batch" VALUE="1">
242 <% mt('Add to current batch') |h %>
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 %>
259 <INPUT TYPE="submit" NAME="process" VALUE="<% mt('Process payment') |h %>">
262 <& /elements/footer.html &>
266 unless $FS::CurrentUser::CurrentUser->access_right('Process payment');
268 my %type = ( 'CARD' => 'credit card',
269 'CHEK' => 'electronic check (ACH)',
272 $cgi->param('payby') =~ /^(CARD|CHEK)$/
273 or die "unknown payby ". $cgi->param('payby');
276 $cgi->param('custnum') =~ /^(\d+)$/
277 or die "illegal custnum ". $cgi->param('custnum');
280 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
281 die "unknown custnum $custnum" unless $cust_main;
283 my $balance = $cust_main->balance;
287 my $conf = new FS::Conf;
289 my $money_char = $conf->config('money_char') || '$';
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'
296 my @states = sort { $a cmp $b } keys %states;
300 my $fee_display = '';
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
311 $fee_display = $conf->config('manual_process-display') || 'add';
312 $fee_op = $fee_display eq 'add' ? '+' : '-';
315 qsearchs('part_pkg', { pkgpart=>$conf->config('manual_process-pkgpart') } );
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
325 if ( $balance > 0 ) {
328 if $fee && $fee_display eq 'subtract';
330 my $cc_surcharge_pct = $conf->config('credit-card-surcharge-percentage');
331 $amount += $amount * $cc_surcharge_pct/100 if $cc_surcharge_pct > 0;
333 $amount = sprintf("%.2f", $amount);
336 my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32;