prepaid download/upload tracking
[freeside.git] / httemplate / misc / process / recharge_svc.html
1 %
2 %
3 %#untaint svcnum
4 %my $svcnum = $cgi->param('svcnum');
5 %$svcnum =~ /^(\d+)$/ || die "Illegal svcnum";
6 %$svcnum = $1;
7 %
8 %#untaint prepaid
9 %my $prepaid = $cgi->param('prepaid');
10 %$prepaid =~ /^(\w*)$/;
11 %$prepaid = $1;
12 %
13 %my $error = '';
14 %my $svc_acct = qsearchs( 'svc_acct', {'svcnum'=>$svcnum} );
15 %$error = "Can't recharge service $svcnum. " unless $svc_acct;
16 %
17 %my $cust_main = $svc_acct->cust_svc->cust_pkg->cust_main;
18 %
19 %my $oldAutoCommit = $FS::UID::AutoCommit;
20 %local $FS::UID::AutoCommit = 0;
21 %my $dbh = dbh;
22 %
23 %
24 %unless ($error) {
25 %
26 %my ($amount, $seconds, $up, $down) = (0, 0, 0, 0);
27 %$error = $cust_main->get_prepay($prepaid, \$amount, \$seconds, \$up, \$down)
28 %      || $svc_acct->increment_seconds($seconds)
29 %      || $svc_acct->increment_upbytes($up)
30 %      || $svc_acct->increment_downbytes($down)
31 %      || $svc_acct->increment_totalbytes($up + $down)
32 %      || $cust_main->insert_cust_pay_prepay( $amount, $prepaid );
33 %}
34 %
35 %if ($error) {
36 %  $cgi->param('error', $error);
37 %  $dbh->rollback if $oldAutoCommit;
38 %  print $cgi->redirect(popurl(2). "recharge_svc.html?". $cgi->query_string );
39 %}
40 %
41 <% header("Package recharged") %>
42   <SCRIPT TYPE="text/javascript">
43     window.top.location.reload();
44   </SCRIPT>
45   </BODY></HTML>
46