processing fee on credit card recharges, RT#5889
[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 % my $amount = $balance > 0 ? sprintf("%.2f", $balance) : '';
14
15 <% ntable('#cccccc') %>
16   <TR>
17     <TH ALIGN="right">Payment amount</TH>
18     <TD COLSPAN=7>
19       <TABLE><TR><TD BGCOLOR="#ffffff">
20         <% $money_char %><INPUT NAME     = "amount"
21                                 TYPE     = "text"
22                                 VALUE    = "<% $amount %>"
23                                 SIZE     = 8
24                                 STYLE    = "text-align:right;"
25 %                               if ( $fee ) {
26                                   onChange   = "amount_changed(this)"
27                                   onKeyDown  = "amount_changed(this)"
28                                   onKeyUp    = "amount_changed(this)"
29                                   onKeyPress = "amount_changed(this)"
30 %                               }
31                          >
32       </TD><TD BGCOLOR="#cccccc">
33 %        if ( $fee ) {
34            <INPUT TYPE="hidden" NAME="fee_pkgpart" VALUE="<% $fee_pkg->pkgpart %>">
35            <INPUT TYPE="hidden" NAME="fee" VALUE="<% $fee %>">
36            <B><FONT SIZE='+1'>+</FONT>
37               <% $money_char . $fee %>
38            </B>
39            <% $fee_pkg->pkg |h %>
40            <B><FONT SIZE='+1'>=</FONT></B>
41       </TD><TD ID="ajax_total_cell" BGCOLOR="#dddddd" STYLE="border:1px solid blue">
42            <FONT SIZE="+1"><% length($amount) ? $money_char. sprintf('%.2f', $amount + $fee ) : '' %> TOTAL</FONT>
43   
44 %        }
45       </TD></TR></TABLE>
46     </TD>
47   </TR>
48
49 % if ( $fee ) {
50
51     <SCRIPT TYPE="text/javascript">
52
53       function amount_changed(what) {
54
55
56         var total = '';
57         if ( what.value.length ) {
58           total = parseFloat(what.value) + <% $fee %>;
59           /* total = Math.round(total*100)/100; */
60           total = '<% $money_char %>' + total.toFixed(2);
61         }
62
63         var total_cell = document.getElementById('ajax_total_cell');
64         total_cell.innerHTML = '<FONT SIZE="+1">' + total + ' TOTAL</FONT>';
65
66       }
67
68     </SCRIPT>
69
70 % }
71
72
73 % if ( $payby eq 'CARD' ) {
74 %
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;
82 %   }
83
84     <TR>
85       <TH ALIGN="right">Card&nbsp;number</TH>
86       <TD COLSPAN=7>
87         <TABLE>
88           <TR>
89             <TD>
90               <INPUT TYPE="text" NAME="payinfo" SIZE=20 MAXLENGTH=19 VALUE="<%$payinfo%>"> </TD>
91             <TH>Exp.</TH>
92             <TD>
93               <SELECT NAME="month">
94 % for ( ( map "0$_", 1 .. 9 ), 10 .. 12 ) { 
95
96                   <OPTION<% $_ == $month ? ' SELECTED' : '' %>><% $_ %>
97 % } 
98
99               </SELECT>
100             </TD>
101             <TD> / </TD>
102             <TD>
103               <SELECT NAME="year">
104 % my @a = localtime; for ( $a[5]+1900 .. $a[5]+1915 ) { 
105
106                   <OPTION<% $_ == $year ? ' SELECTED' : '' %>><% $_ %>
107 % } 
108
109               </SELECT>
110             </TD>
111           </TR>
112         </TABLE>
113       </TD>
114     </TR>
115     <TR>
116       <TH ALIGN="right">CVV2</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;">help</A>)
119       </TD>
120     </TR>
121     <TR>
122       <TH ALIGN="right">Exact&nbsp;name&nbsp;on&nbsp;card</TH>
123       <TD><INPUT TYPE="text" SIZE=32 MAXLENGTH=80 NAME="payname" VALUE="<%$payname%>"></TD>
124     </TR>
125
126     <% include( '/elements/location.html',
127                   'object'         => $cust_main, #XXX errors???
128                   'no_asterisks'   => 1,
129                   'address1_label' => 'Card billing address',
130               )
131     %>
132
133 % } elsif ( $payby eq 'CHEK' ) {
134 %
135 %   my( $payinfo1, $payinfo2, $payname, $ss, $paytype, $paystate,
136 %       $stateid, $stateid_state )
137 %     = ( '', '', '', '', '', '', '', '' );
138 %   if ( $cust_main->payby =~ /^(CHEK|DCHK)$/ ) {
139 %     $cust_main->paymask =~ /^([\dx]+)\@([\dx]+)$/i
140 %       or die "unparsable payinfo ". $cust_main->payinfo;
141 %     ($payinfo1, $payinfo2) = ($1, $2);
142 %     $payname = $cust_main->payname;
143 %     $ss = $cust_main->ss;
144 %     $paytype = $cust_main->getfield('paytype');
145 %     $paystate = $cust_main->getfield('paystate');
146 %     $stateid = $cust_main->getfield('stateid');
147 %     $stateid_state = $cust_main->getfield('stateid_state');
148 %   }
149
150     <INPUT TYPE="hidden" NAME="month" VALUE="12">
151     <INPUT TYPE="hidden" NAME="year" VALUE="2037">
152     <TR>
153       <TD ALIGN="right">Account&nbsp;number</TD>
154       <TD><INPUT TYPE="text" SIZE=10 NAME="payinfo1" VALUE="<%$payinfo1%>"></TD>
155       <TD ALIGN="right">Type</TD>
156       <TD><SELECT NAME="paytype"><% join('', map { qq!<OPTION VALUE="$_" !.($paytype eq $_ ? 'SELECTED' : '').">$_</OPTION>" } @FS::cust_main::paytypes) %></SELECT></TD>
157     </TR>
158     <TR>
159       <TD ALIGN="right">ABA/Routing&nbsp;number</TD>
160       <TD>
161         <INPUT TYPE="text" SIZE=10 MAXLENGTH=9 NAME="payinfo2" VALUE="<%$payinfo2%>">
162         (<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>)
163       </TD>
164     </TR>
165     <TR>
166       <TD ALIGN="right">Bank&nbsp;name</TD>
167       <TD><INPUT TYPE="text" NAME="payname" VALUE="<%$payname%>"></TD>
168     </TR>
169
170 %   if ( $conf->exists('show_bankstate') ) {
171       <TR>
172         <TD ALIGN="right">Bank&nbsp;state</TD>
173         <TD><% include('/elements/select-state.html',
174                          'disable_empty' => 0,
175                          'empty_label'   => '(choose)',
176                          'state'         => $paystate,
177                          'country'       => $cust_main->country,
178                          'prefix'        => 'pay',
179                       )
180             %>
181         </TD>
182       </TR>
183 %   } else {
184       <INPUT TYPE="hidden" NAME="paystate" VALUE="<% $paystate %>">
185 %   }
186
187 %   if ( $conf->exists('show_ss') ) {
188       <TR>
189         <TD ALIGN="right">
190           Account&nbsp;holder<BR>
191           Social&nbsp;security&nbsp;or&nbsp;tax&nbsp;ID&nbsp;#
192         </TD>
193         <TD><INPUT TYPE="text" NAME="ss" VALUE="<% $ss %>"></TD>
194       </TR>
195 %   } else {
196       <INPUT TYPE="hidden" NAME="ss" VALUE="<% $ss %>"></TD>
197 %   }
198
199 %   if ( $conf->exists('show_stateid') ) {
200       <TR>
201         <TD ALIGN="right">
202           Account&nbsp;holder<BR>
203           Driver&rsquo;s&nbsp;license&nbsp;or&nbsp;state&nbsp;ID&nbsp;#
204         </TD>
205         <TD><INPUT TYPE="text" NAME="stateid" VALUE="<% $stateid %>"></TD>
206         <TD ALIGN="right">State</TD>
207         <TD><% include('/elements/select-state.html',
208                          'disable_empty' => 0,
209                          'empty_label'   => '(choose)',
210                          'state'         => $stateid_state,
211                          'country'       => $cust_main->country,
212                          'prefix'        => 'stateid_',
213                       )
214             %>
215         </TD>
216       </TR>
217 %   } else {
218       <INPUT TYPE="hidden" NAME="stateid" VALUE="<% $stateid %>">
219       <INPUT TYPE="hidden" NAME="stateid_state" VALUE="<% $stateid_state %>">
220 %   }
221
222 % } #end CARD/CHEK-specific section
223
224
225 <TR>
226   <TD COLSPAN=2>
227     <INPUT TYPE="checkbox" CHECKED NAME="save" VALUE="1">
228     Remember this information
229   </TD>
230 </TR>
231
232 % if ( $conf->exists("batch-enable")
233 %      || grep $payby eq $_, $conf->config('batch-enable_payby')
234 %    ) {
235 %
236 %     if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
237
238           <INPUT TYPE="hidden" NAME="batch" VALUE="1">
239
240 %     } else {
241
242           <TR>
243             <TD COLSPAN=2>
244               <INPUT TYPE="checkbox" NAME="batch" VALUE="1">
245               Add to current batch
246             </TD>
247           </TR>
248
249 %     }
250 % }
251
252 <TR>
253   <TD COLSPAN=2>
254     <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; }">
255     Charge future payments to this <% $type{$payby} %> automatically
256   </TD>
257 </TR>
258
259 </TABLE>
260
261 <BR>
262 <INPUT TYPE="submit" NAME="process" VALUE="Process payment">
263 </FORM>
264
265 <% include('/elements/footer.html') %>
266 <%init>
267
268 die "access denied"
269   unless $FS::CurrentUser::CurrentUser->access_right('Process payment');
270
271 my %type = ( 'CARD' => 'credit card',
272              'CHEK' => 'electronic check (ACH)',
273            );
274
275 $cgi->param('payby') =~ /^(CARD|CHEK)$/
276   or die "unknown payby ". $cgi->param('payby');
277 my $payby = $1;
278
279 $cgi->param('custnum') =~ /^(\d+)$/
280   or die "illegal custnum ". $cgi->param('custnum');
281 my $custnum = $1;
282
283 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
284 die "unknown custnum $custnum" unless $cust_main;
285
286 my $balance = $cust_main->balance;
287
288 my $payinfo = '';
289
290 my $conf = new FS::Conf;
291
292 my $money_char = $conf->config('money_char') || '$';
293
294 #false laziness w/selfservice make_payment.html shortcut for one-country
295 my %states = map { $_->state => 1 }
296                qsearch('cust_main_county', {
297                  'country' => $conf->config('countrydefault') || 'US'
298                } );
299 my @states = sort { $a cmp $b } keys %states;
300
301 my $fee = '';
302 my $fee_pkg = '';
303 if ( $conf->config('manual_process-pkgpart') ) {
304   $fee_pkg =
305     qsearchs('part_pkg', { pkgpart=>$conf->config('manual_process-pkgpart') } );
306
307   #well ->unit_setup or ->calc_setup both call for a $cust_pkg
308   # (though ->unit_setup doesn't use it...)
309   $fee = $fee_pkg->option('setup_fee')
310     if $fee_pkg; #in case.. better than dying with a perl traceback
311 }
312
313 my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32;
314
315 </%init>