3 % my ($amount, $seconds, $up, $down, $total) = (0, 0, 0, 0, 0);
4 % #should probably use payby.pm but whatever
5 % if ($payby eq 'PREP') {
6 % $error = $cust_main->get_prepay($prepaid, \$amount, \$seconds, \$up, \$down, \$total)
7 % || $svc_acct->increment_seconds($seconds)
8 % || $svc_acct->increment_upbytes($up)
9 % || $svc_acct->increment_downbytes($down)
10 % || $svc_acct->increment_totalbytes($total)
11 % || $cust_main->insert_cust_pay_prepay( $amount, $prepaid );
12 % } elsif ( $payby =~ /^(CARD|DCRD|CHEK|DCHK|LECB|BILL|COMP)$/ ) {
13 % my $part_pkg = $svc_acct->cust_svc->cust_pkg->part_pkg;
14 % $amount = $part_pkg->option('recharge_amount', 1);
15 % my %rhash = map { $_ =~ /^recharge_(.*)$/; $1, $part_pkg->option($_) }
16 % grep { $part_pkg->option($_, 1) }
17 % qw ( recharge_seconds recharge_upbytes recharge_downbytes
18 % recharge_totalbytes );
20 % my $description = "Recharge";
21 % $description .= " $rhash{seconds}s" if $rhash{seconds};
22 % $description .= " $rhash{upbytes} up" if $rhash{upbytes};
23 % $description .= " $rhash{downbytes} down" if $rhash{downbytes};
24 % $description .= " $rhash{totalbytes} total" if $rhash{totalbytes};
26 % $error = $cust_main->charge($amount, "Recharge " . $svc_acct->label,
27 % $description, $part_pkg->taxclass);
29 % if ($part_pkg->option('recharge_reset', 1)) {
30 % $error ||= $svc_acct->set_usage(\%rhash);
32 % $error ||= $svc_acct->recharge(\%rhash);
35 % my $old_balance = $cust_main->balance;
36 % $error ||= $cust_main->bill;
37 % $error ||= $cust_main->apply_payments_and_credits;
38 % my $bill_error = $cust_main->collect('realtime' => 1) unless $error;
39 % $error ||= "Failed to collect - $bill_error"
40 % if $cust_main->balance > $old_balance && $cust_main->balance > 0
41 % && $payby ne 'BILL';
44 % $error = "fatal error - unknown payby: $payby";
49 % $cgi->param('error', $error);
50 % $dbh->rollback if $oldAutoCommit;
51 % print $cgi->redirect(popurl(2). "recharge_svc.html?". $cgi->query_string );
53 %$dbh->commit or die $dbh->errstr if $oldAutoCommit;
55 <% header("Package recharged") %>
56 <SCRIPT TYPE="text/javascript">
57 window.top.location.reload();
62 my $conf = new FS::Conf;
65 unless $FS::CurrentUser::CurrentUser->access_right('Recharge customer service');
68 my $svcnum = $cgi->param('svcnum');
69 $svcnum =~ /^(\d+)$/ || die "Illegal svcnum";
73 my $prepaid = $cgi->param('prepaid');
74 $prepaid =~ /^(\w*)$/;
78 my $payby = $cgi->param('payby');
79 $payby =~ /^([A-Z]*)$/;
83 my $svc_acct = qsearchs( 'svc_acct', {'svcnum'=>$svcnum} );
84 $error = "Can't recharge service $svcnum. " unless $svc_acct;
86 my $cust_main = $svc_acct->cust_svc->cust_pkg->cust_main;
88 my $oldAutoCommit = $FS::UID::AutoCommit;
89 local $FS::UID::AutoCommit = 0;