allow country selection on credit card entry, RT#4997
[freeside.git] / httemplate / misc / payment.cgi
1 <% include( '/elements/header.html', "Process $type{$payby} payment" ) %>
2 <% include( '/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 <% include('/elements/init_overlib.html') %>
10
11 % #include( '/elements/table.html', '#cccccc' ) 
12
13 <% ntable('#cccccc') %>
14   <TR>
15     <TH ALIGN="right">Payment amount</TH>
16     <TD>
17       <TABLE><TR><TD BGCOLOR="#ffffff">
18         $<INPUT TYPE="text" NAME="amount" SIZE=8 VALUE="<% $balance > 0 ? sprintf("%.2f", $balance) : '' %>">
19       </TD></TR></TABLE>
20     </TD>
21   </TR>
22
23 % if ( $payby eq 'CARD' ) {
24 %
25 %   my( $payinfo, $paycvv, $month, $year ) = ( '', '', '', '' );
26 %   my $payname = $cust_main->first. ' '. $cust_main->getfield('last');
27 %   if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) {
28 %     $payinfo = $cust_main->paymask;
29 %     $paycvv = $cust_main->paycvv;
30 %     ( $month, $year ) = $cust_main->paydate_monthyear;
31 %     $payname = $cust_main->payname if $cust_main->payname;
32 %   }
33
34     <TR>
35       <TH ALIGN="right">Card&nbsp;number</TH>
36       <TD COLSPAN=7>
37         <TABLE>
38           <TR>
39             <TD>
40               <INPUT TYPE="text" NAME="payinfo" SIZE=20 MAXLENGTH=19 VALUE="<%$payinfo%>"> </TD>
41             <TH>Exp.</TH>
42             <TD>
43               <SELECT NAME="month">
44 % for ( ( map "0$_", 1 .. 9 ), 10 .. 12 ) { 
45
46                   <OPTION<% $_ == $month ? ' SELECTED' : '' %>><% $_ %>
47 % } 
48
49               </SELECT>
50             </TD>
51             <TD> / </TD>
52             <TD>
53               <SELECT NAME="year">
54 % my @a = localtime; for ( $a[5]+1900 .. $a[5]+1915 ) { 
55
56                   <OPTION<% $_ == $year ? ' SELECTED' : '' %>><% $_ %>
57 % } 
58
59               </SELECT>
60             </TD>
61           </TR>
62         </TABLE>
63       </TD>
64     </TR>
65     <TR>
66       <TH ALIGN="right">CVV2</TH>
67       <TD><INPUT TYPE="text" NAME="paycvv" VALUE="<% $paycvv %>" SIZE=4 MAXLENGTH=4>
68           (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/cvv2.html', 480, 352, 'cvv2_popup' ), CAPTION, 'CVV2 Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;">help</A>)
69       </TD>
70     </TR>
71     <TR>
72       <TH ALIGN="right">Exact&nbsp;name&nbsp;on&nbsp;card</TH>
73       <TD><INPUT TYPE="text" SIZE=32 MAXLENGTH=80 NAME="payname" VALUE="<%$payname%>"></TD>
74     </TR>
75
76     <% include( '/elements/location.html',
77                   'object'         => $cust_main, #XXX errors???
78                   'no_asterisks'   => 1,
79                   'address1_label' => 'Card billing address',
80               )
81     %>
82
83 % } elsif ( $payby eq 'CHEK' ) {
84 %
85 %   my( $payinfo1, $payinfo2, $payname, $ss, $paytype, $paystate,
86 %       $stateid, $stateid_state )
87 %     = ( '', '', '', '', '', '', '', '' );
88 %   if ( $cust_main->payby =~ /^(CHEK|DCHK)$/ ) {
89 %     $cust_main->paymask =~ /^([\dx]+)\@([\dx]+)$/i
90 %       or die "unparsable payinfo ". $cust_main->payinfo;
91 %     ($payinfo1, $payinfo2) = ($1, $2);
92 %     $payname = $cust_main->payname;
93 %     $ss = $cust_main->ss;
94 %     $paytype = $cust_main->getfield('paytype');
95 %     $paystate = $cust_main->getfield('paystate');
96 %     $stateid = $cust_main->getfield('stateid');
97 %     $stateid_state = $cust_main->getfield('stateid_state');
98 %   }
99
100     <INPUT TYPE="hidden" NAME="month" VALUE="12">
101     <INPUT TYPE="hidden" NAME="year" VALUE="2037">
102     <TR>
103       <TD ALIGN="right">Account&nbsp;number</TD>
104       <TD><INPUT TYPE="text" SIZE=10 NAME="payinfo1" VALUE="<%$payinfo1%>"></TD>
105       <TD ALIGN="right">Type</TD>
106       <TD><SELECT NAME="paytype"><% join('', map { qq!<OPTION VALUE="$_" !.($paytype eq $_ ? 'SELECTED' : '').">$_</OPTION>" } @FS::cust_main::paytypes) %></SELECT></TD>
107     </TR>
108     <TR>
109       <TD ALIGN="right">ABA/Routing&nbsp;number</TD>
110       <TD>
111         <INPUT TYPE="text" SIZE=10 MAXLENGTH=9 NAME="payinfo2" VALUE="<%$payinfo2%>">
112         (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/ach.html', 380, 240, 'ach_popup' ), CAPTION, 'ACH Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;">help</A>)
113       </TD>
114     </TR>
115     <TR>
116       <TD ALIGN="right">Bank&nbsp;name</TD>
117       <TD><INPUT TYPE="text" NAME="payname" VALUE="<%$payname%>"></TD>
118     </TR>
119
120 %   if ( $conf->exists('show_bankstate') ) {
121       <TR>
122         <TD ALIGN="right">Bank&nbsp;state</TD>
123         <TD><% include('/elements/select-state.html',
124                          'disable_empty' => 0,
125                          'empty_label'   => '(choose)',
126                          'state'         => $paystate,
127                          'country'       => $cust_main->country,
128                          'prefix'        => 'pay',
129                       )
130             %>
131         </TD>
132       </TR>
133 %   } else {
134       <INPUT TYPE="hidden" NAME="paystate" VALUE="<% $paystate %>">
135 %   }
136
137 %   if ( $conf->exists('show_ss') ) {
138       <TR>
139         <TD ALIGN="right">
140           Account&nbsp;holder<BR>
141           Social&nbsp;security&nbsp;or&nbsp;tax&nbsp;ID&nbsp;#
142         </TD>
143         <TD><INPUT TYPE="text" NAME="ss" VALUE="<% $ss %>"></TD>
144       </TR>
145 %   } else {
146       <INPUT TYPE="hidden" NAME="ss" VALUE="<% $ss %>"></TD>
147 %   }
148
149 %   if ( $conf->exists('show_stateid') ) {
150       <TR>
151         <TD ALIGN="right">
152           Account&nbsp;holder<BR>
153           Driver&rsquo;s&nbsp;license&nbsp;or&nbsp;state&nbsp;ID&nbsp;#
154         </TD>
155         <TD><INPUT TYPE="text" NAME="stateid" VALUE="<% $stateid %>"></TD>
156         <TD ALIGN="right">State</TD>
157         <TD><% include('/elements/select-state.html',
158                          'disable_empty' => 0,
159                          'empty_label'   => '(choose)',
160                          'state'         => $stateid_state,
161                          'country'       => $cust_main->country,
162                          'prefix'        => 'stateid_',
163                       )
164             %>
165         </TD>
166       </TR>
167 %   } else {
168       <INPUT TYPE="hidden" NAME="stateid" VALUE="<% $stateid %>">
169       <INPUT TYPE="hidden" NAME="stateid_state" VALUE="<% $stateid_state %>">
170 %   }
171
172 % } #end CARD/CHEK-specific section
173
174
175 <TR>
176   <TD COLSPAN=2>
177     <INPUT TYPE="checkbox" CHECKED NAME="save" VALUE="1">
178     Remember this information
179   </TD>
180 </TR>
181
182 % if ( $conf->exists("batch-enable")
183 %      || grep $payby eq $_, $conf->config('batch-enable_payby')
184 %    ) {
185 %
186 %     if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
187
188           <INPUT TYPE="hidden" NAME="batch" VALUE="1">
189
190 %     } else {
191
192           <TR>
193             <TD COLSPAN=2>
194               <INPUT TYPE="checkbox" NAME="batch" VALUE="1">
195               Add to current batch
196             </TD>
197           </TR>
198
199 %     }
200 % }
201
202 <TR>
203   <TD COLSPAN=2>
204     <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; }">
205     Charge future payments to this <% $type{$payby} %> automatically
206   </TD>
207 </TR>
208
209 </TABLE>
210
211 <BR>
212 <INPUT TYPE="submit" NAME="process" VALUE="Process payment">
213 </FORM>
214
215 <% include('/elements/footer.html') %>
216 <%init>
217
218 die "access denied"
219   unless $FS::CurrentUser::CurrentUser->access_right('Process payment');
220
221 my %type = ( 'CARD' => 'credit card',
222              'CHEK' => 'electronic check (ACH)',
223            );
224
225 $cgi->param('payby') =~ /^(CARD|CHEK)$/
226   or die "unknown payby ". $cgi->param('payby');
227 my $payby = $1;
228
229 $cgi->param('custnum') =~ /^(\d+)$/
230   or die "illegal custnum ". $cgi->param('custnum');
231 my $custnum = $1;
232
233 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
234 die "unknown custnum $custnum" unless $cust_main;
235
236 my $balance = $cust_main->balance;
237
238 my $payinfo = '';
239
240 #false laziness w/selfservice make_payment.html shortcut for one-country
241 my $conf = new FS::Conf;
242 my %states = map { $_->state => 1 }
243                qsearch('cust_main_county', {
244                  'country' => $conf->config('countrydefault') || 'US'
245                } );
246 my @states = sort { $a cmp $b } keys %states;
247
248 my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32;
249
250 </%init>
251
252