From 9cdbb7eb2cb2d5d01bb9edbbd48a67ba06bf456f Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 9 Apr 2007 23:38:27 +0000 Subject: [PATCH] trigger recharge from the backend as in self-service --- httemplate/misc/process/recharge_svc.html | 53 +++++++++++++++++++++++++++---- httemplate/misc/recharge_svc.html | 41 ++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/httemplate/misc/process/recharge_svc.html b/httemplate/misc/process/recharge_svc.html index d9fa2070e..df6715630 100755 --- a/httemplate/misc/process/recharge_svc.html +++ b/httemplate/misc/process/recharge_svc.html @@ -9,6 +9,11 @@ %my $prepaid = $cgi->param('prepaid'); %$prepaid =~ /^(\w*)$/; %$prepaid = $1; + +%#untaint payby +%my $payby = $cgi->param('payby'); +%$payby =~ /^([A-Z]*)$/; +%$payby = $1; % %my $error = ''; %my $svc_acct = qsearchs( 'svc_acct', {'svcnum'=>$svcnum} ); @@ -24,12 +29,43 @@ %unless ($error) { % %my ($amount, $seconds, $up, $down, $total) = (0, 0, 0, 0, 0); -%$error = $cust_main->get_prepay($prepaid, \$amount, \$seconds, \$up, \$down, \$total) -% || $svc_acct->increment_seconds($seconds) -% || $svc_acct->increment_upbytes($up) -% || $svc_acct->increment_downbytes($down) -% || $svc_acct->increment_totalbytes($total) -% || $cust_main->insert_cust_pay_prepay( $amount, $prepaid ); +% if ($payby eq 'PREP') { +% $error = $cust_main->get_prepay($prepaid, \$amount, \$seconds, \$up, \$down, \$total) +% || $svc_acct->increment_seconds($seconds) +% || $svc_acct->increment_upbytes($up) +% || $svc_acct->increment_downbytes($down) +% || $svc_acct->increment_totalbytes($total) +% || $cust_main->insert_cust_pay_prepay( $amount, $prepaid ); +% }elsif ($payby =~ /^(CARD|DCRD|CHEK|DCHK|LECB|BILL|COMP)$/) { +% my $part_pkg = $svc_acct->cust_svc->cust_pkg->part_pkg; +% $amount = $part_pkg->option('recharge_amount', 1); +% my %rhash = map { $_ =~ /^recharge_(.*)$/; $1, $part_pkg->option($_, 1) } +% qw ( recharge_seconds recharge_upbytes recharge_downbytes +% recharge_totalbytes ); +% +% my $description = "Recharge"; +% $description .= " $rhash{seconds}s" if $rhash{seconds}; +% $description .= " $rhash{upbytes} up" if $rhash{upbytes}; +% $description .= " $rhash{downbytes} down" if $rhash{downbytes}; +% $description .= " $rhash{totalbytes} total" if $rhash{totalbytes}; +% +% $error = $cust_main->charge($amount, "Recharge " . $svc_acct->label, +% $description, $part_pkg->taxclass); +% +% $error ||= $svc_acct->recharge(\%rhash); +% +% if ($conf->exists('backend-realtime')) { +% my $old_balance = $cust_main->balance; +% $error ||= $cust_main->bill; +% $cust_main->apply_payments_and_credits unless $error; +% my $bill_error = $cust_main->collect('realtime' => 1) unless $error; +% $error ||= "Failed to collect - $bill_error" +% if ($cust_main->balance > $old_balance && $cust_main->balance > 0 +% && $payby ne 'BILL'); +% } +% }else{ +$ $error "fatal error - unknown payby: $payby"; +% } %} % %if ($error) { @@ -37,10 +73,13 @@ % $dbh->rollback if $oldAutoCommit; % print $cgi->redirect(popurl(2). "recharge_svc.html?". $cgi->query_string ); %} +%$dbh->commit or die $dbh->errstr if $oldAutoCommit; % <% header("Package recharged") %> - +<%init> +my $conf = new FS::Conf; + diff --git a/httemplate/misc/recharge_svc.html b/httemplate/misc/recharge_svc.html index 61f738455..9373b825c 100755 --- a/httemplate/misc/recharge_svc.html +++ b/httemplate/misc/recharge_svc.html @@ -12,9 +12,26 @@ <% "Recharge $svcnum: $label - $value" %> <% ntable("#cccccc", 2) %> + + + <% $recharge_label ? '' : 'disabled' %>> + Prepaid Card +% if ($recharge_label) { + > + <% $recharge_label %> +% } + Enter prepaid card: - + > @@ -26,11 +43,16 @@ +<%once> +my $conf = new FS::Conf; +my $money_char = $conf->config('money_char') || '$'; + <%init> -my($svcnum, $cust_svc, $label, $value, $prepaid); +my($svcnum, $cust_svc, $part_pkg, $label, $value, $prepaid, $amount, $payby); if ( $cgi->param('error') ) { $svcnum = $cgi->param('svcnum'); $prepaid = $cgi->param('prepaid'); + $payby = $cgi->param('payby'); } elsif ( $cgi->param('svcnum') =~ /^(\d+)$/ ) { $svcnum = $1; } else { @@ -44,5 +66,20 @@ die "No such service: $svcnum" unless $cust_svc; ($label, $value) = $cust_svc->label; +$payby = $cust_svc->cust_pkg->cust_main->payby unless $payby; +$part_pkg = $cust_svc->cust_pkg->part_pkg; +$amount = $part_pkg->option('recharge_amount', 1) || 0; +my $recharge_label = "Charge $money_char$amount for "; +$recharge_label .= $part_pkg->option('recharge_seconds', 1) . 's ' + if $part_pkg->option('recharge_seconds', 1); +$recharge_label .= $part_pkg->option('recharge_upbytes', 1) . ' up ' + if $part_pkg->option('recharge_upbytes', 1); +$recharge_label .= $part_pkg->option('recharge_downbytes', 1) . ' down ' + if $part_pkg->option('recharge_downbytes', 1); +$recharge_label .= $part_pkg->option('recharge_totalbytes', 1) . ' total ' + if $part_pkg->option('recharge_totalbytes', 1); +$recharge_label = '' + unless ($recharge_label ne "Charge $money_char$amount for "); + -- 2.11.0