4 %my $svcnum = $cgi->param('svcnum');
5 %$svcnum =~ /^(\d+)$/ || die "Illegal svcnum";
9 %my $prepaid = $cgi->param('prepaid');
10 %$prepaid =~ /^(\w*)$/;
14 %my $payby = $cgi->param('payby');
15 %$payby =~ /^([A-Z]*)$/;
19 %my $svc_acct = qsearchs( 'svc_acct', {'svcnum'=>$svcnum} );
20 %$error = "Can't recharge service $svcnum. " unless $svc_acct;
22 %my $cust_main = $svc_acct->cust_svc->cust_pkg->cust_main;
24 %my $oldAutoCommit = $FS::UID::AutoCommit;
25 %local $FS::UID::AutoCommit = 0;
31 % my ($amount, $seconds, $up, $down, $total) = (0, 0, 0, 0, 0);
32 % #should probably use payby.pm but whatever
33 % if ($payby eq 'PREP') {
34 % $error = $cust_main->get_prepay($prepaid, \$amount, \$seconds, \$up, \$down, \$total)
35 % || $svc_acct->increment_seconds($seconds)
36 % || $svc_acct->increment_upbytes($up)
37 % || $svc_acct->increment_downbytes($down)
38 % || $svc_acct->increment_totalbytes($total)
39 % || $cust_main->insert_cust_pay_prepay( $amount, $prepaid );
40 % } elsif ( $payby =~ /^(CARD|DCRD|CHEK|DCHK|LECB|BILL|COMP)$/ ) {
41 % my $part_pkg = $svc_acct->cust_svc->cust_pkg->part_pkg;
42 % $amount = $part_pkg->option('recharge_amount', 1);
43 % my %rhash = map { $_ =~ /^recharge_(.*)$/; $1, $part_pkg->option($_, 1) }
44 % qw ( recharge_seconds recharge_upbytes recharge_downbytes
45 % recharge_totalbytes );
47 % my $description = "Recharge";
48 % $description .= " $rhash{seconds}s" if $rhash{seconds};
49 % $description .= " $rhash{upbytes} up" if $rhash{upbytes};
50 % $description .= " $rhash{downbytes} down" if $rhash{downbytes};
51 % $description .= " $rhash{totalbytes} total" if $rhash{totalbytes};
53 % $error = $cust_main->charge($amount, "Recharge " . $svc_acct->label,
54 % $description, $part_pkg->taxclass);
56 % $error ||= $svc_acct->recharge(\%rhash);
58 % my $old_balance = $cust_main->balance;
59 % $error ||= $cust_main->bill;
60 % $error ||= $cust_main->apply_payments_and_credits;
61 % my $bill_error = $cust_main->collect('realtime' => 1) unless $error;
62 % $error ||= "Failed to collect - $bill_error"
63 % if $cust_main->balance > $old_balance && $cust_main->balance > 0
64 % && $payby ne 'BILL';
67 % $error = "fatal error - unknown payby: $payby";
72 % $cgi->param('error', $error);
73 % $dbh->rollback if $oldAutoCommit;
74 % print $cgi->redirect(popurl(2). "recharge_svc.html?". $cgi->query_string );
76 %$dbh->commit or die $dbh->errstr if $oldAutoCommit;
78 <% header("Package recharged") %>
79 <SCRIPT TYPE="text/javascript">
80 window.top.location.reload();
84 my $conf = new FS::Conf;