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