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