summaryrefslogtreecommitdiff
path: root/httemplate/misc/payment.cgi
blob: 7911a5dd9073ec18e6ed13cd3b65cc60b74f0272 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<& /elements/header-cust_main.html, view=>'payment_history', cust_main=>$cust_main &>

<h2><% emt("Process [_1] payment",$type{$payby}) %></h2>

<FORM NAME="OneTrueForm" ACTION="process/payment.cgi" METHOD="POST" onSubmit="document.OneTrueForm.process.disabled=true">
<INPUT TYPE="hidden" NAME="custnum"   VALUE="<% $custnum %>">
<INPUT TYPE="hidden" NAME="payby"     VALUE="<% $payby %>">
<INPUT TYPE="hidden" NAME="payunique" VALUE="<% $payunique %>">
<INPUT TYPE="hidden" NAME="balance"   VALUE="<% $balance %>">

<& /elements/init_overlib.html &>

<TABLE class="fsinnerbox">

  <& /elements/tr-select-payment_options.html,
       'cust_main'          => $cust_main,
       'process-pkgpart'    => 
          scalar($conf->config('manual_process-pkgpart', $cust_main->agentnum)),
       'process-display'    => scalar($conf->config('manual_process-display')),
       'process-skip_first' => $conf->exists('manual_process-skip_first'),
       'num_payments'       => scalar($cust_main->cust_pay), 
       'surcharge_percentage' =>
         ( $payby eq 'CARD'
             ? scalar($conf->config('credit-card-surcharge-percentage', $cust_main->agentnum))
             : 0
         ),
       'surcharge_flatfee' =>
         ( $payby eq 'CARD'
             ? scalar($conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum))
             : 0
         ),
         'processing_fee' => scalar($conf->config('processing-fee', $cust_main->agentnum)),
  &>

% if ( $conf->exists('part_pkg-term_discounts') ) {
    <& /elements/tr-select-discount_term.html,
         'custnum'   => $custnum,
         'amount_id' => 'amount',
    &>
% }

% my $disallow_no_auto_apply = 0;
% if ( $conf->exists("batch-enable")
%      || grep $payby eq $_, $conf->config('batch-enable_payby')
%    ) {
%
%     if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
%       $disallow_no_auto_apply = 1;

          <INPUT TYPE="hidden" NAME="batch" VALUE="1">

%     } else {

          <TR>
            <TH ALIGN="right">&nbsp;&nbsp;&nbsp;<% mt('Add to current batch') |h %></TH>
            <TD>
              <INPUT TYPE="checkbox" NAME="batch" VALUE="1" ID="batch_checkbox" ONCHANGE="change_batch_checkbox()">
            </TD>
          </TR>

%     }
% }

% unless ($disallow_no_auto_apply) {
%   # false laziness with edit/cust_pay.cgi

<TR ID="apply_box_row">
  <TH ALIGN="right"><% mt('Auto-apply to invoices') |h %></TH>
  <TD>
    <SELECT NAME="apply" ID="apply_box">
      <OPTION VALUE="yes" SELECTED><% mt('yes') |h %></OPTION> 
      <OPTION VALUE=""><% mt('not now') |h %></OPTION>
      <OPTION VALUE="never"><% mt('never') |h %></OPTION>
    </SELECT>
  </TD>
</TR>

% # this can go away if no_auto_apply handling gets added to batch payment processing
<SCRIPT>
function change_batch_checkbox () {
  if (document.getElementById('batch_checkbox').checked) {
    document.getElementById('apply_box').disabled = true;
    document.getElementById('apply_box_row').style.display = 'none';
  } else {
    document.getElementById('apply_box').disabled = false;
    document.getElementById('apply_box_row').style.display = '';
  }
}
</SCRIPT>

% }

<SCRIPT TYPE="text/javascript">
  function cust_payby_changed (what) {
    var custpaybynum = what.options[what.selectedIndex].value
    if ( custpaybynum == '' || custpaybynum == '0' ) {
       //what.form.payinfo.disabled = false;
       $('#cust_payby').slideDown();
    } else {
       //what.form.payinfo.value = '';
       //what.form.payinfo.disabled = true;
       $('#cust_payby').slideUp();
    }
  }

  function enableAmountField() {
    document.getElementById('amount').disabled = false;
  }

</SCRIPT>

% #can't quite handle CARD/CHEK on the same page yet, but very close
% #does it make sense from a UI/usability perspective?
%
% my @cust_payby = ();
% if ( $payby eq 'CARD' ) {
%   @cust_payby = $cust_main->cust_payby('CARD','DCRD');
% } elsif ( $payby eq 'CHEK' ) {
%   @cust_payby = $cust_main->cust_payby('CHEK','DCHK');
% } else {
%   die "unknown payby $payby";
% }
%
% my $custpaybynum = length(scalar($cgi->param('custpaybynum')))
%                      ? scalar($cgi->param('custpaybynum'))
%                      : scalar(@cust_payby) && $cust_payby[0]->custpaybynum;

<& /elements/tr-select-cust_payby.html,
     'cust_payby' => \@cust_payby,
     'curr_value' => $custpaybynum,
     'onchange'   => 'cust_payby_changed(this)',
&>

</TABLE>
<BR>
<DIV ID="cust_payby"
  <% $custpaybynum ? 'STYLE="display:none"'
                   : ''
  %>
>
<TABLE class="fsinnerbox">

<& /elements/cust_payby_new.html,
     'cust_payby' => \@cust_payby,
     'curr_value' => $custpaybynum,
&>

</TABLE>
</DIV>

<BR>
<INPUT TYPE="submit" NAME="process" ID="process" VALUE="<% mt('Process payment') |h %>" disabled="disabled" onclick="enableAmountField()">
</FORM>

<SCRIPT TYPE="text/javascript">

$(document).ready(function (){
    validate();
    $('<% $validate_select_fields %>').change(validate);
    $('<% $validate_input_fields %>').keyup(validate);
});

function validate(){
    if (
      $('#amount').val() > 0 && (
        ( $('#custpaybynum').val() > 0 ) ||
% if ($payby eq "CHEK") {
        ( $('input[name=payinfo1]').val().length > 0 &&
          $('input[name=payinfo2]').val().length > 0 &&
          $('input[name=payname]').val().length > 0  &&
          $('select[name=paytype]').val().length > 0
        )
% }
% elsif ($payby eq "CARD") {
        ( $('input[name=payinfo]').val().length > 0 &&
          $('input[name=paycvv]').val().length > 0 &&
          $('input[name=payname]').val().length > 0 &&
          $('#city').val().length > 0 &&
          $('#city').val().length > 0 &&
          $('#state').val().length > 0 &&
          $('#country').val().length > 0
        )
% }
      )
     ) {
        $("#process").prop("disabled", false);
    }
    else {
        $("#process").prop("disabled", true);
    }
}

</SCRIPT>

<& /elements/footer-cust_main.html &>
<%once>

my %weight = (
  1 => 'Primary',
  2 => 'Secondary',
  3 => 'Tertiary',
  4 => 'Fourth',
  5 => 'Fifth',
  6 => 'Sixth',
  7 => 'Seventh',
);

</%once>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Process payment');

my %type = ( 'CARD' => 'credit card',
             'CHEK' => 'electronic check (ACH)',
           );

$cgi->param('payby') =~ /^(CARD|CHEK)$/
  or die "unknown payby ". $cgi->param('payby');
my $payby = $1;

my $validate_select_fields = "#payment_option, #invoice, #custpaybynum, ";
my $validate_input_fields  = "#amount, input[name=payname], ";
if ($payby eq "CHEK") {
  $validate_input_fields  .= "input[name=payinfo1], input[name=payinfo2]";
  $validate_select_fields .= "select[name=paytype] ";
}
elsif ($payby eq "CARD") {
  $validate_input_fields  .= "input[name=payinfo], input[name=paycvv], input[name=address1], #city, #zip";
  $validate_select_fields .= "#state, #country ";
}

$cgi->param('custnum') =~ /^(\d+)$/
  or die "illegal custnum ". $cgi->param('custnum');
my $custnum = $1;

my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
die "unknown custnum $custnum" unless $cust_main;

my $balance = $cust_main->balance;

my $payinfo = '';

my $conf = new FS::Conf;

my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32;

</%init>