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