From 04cc48bd2a049909af54b9e58afebffe51cdd1b2 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 8 Jun 2005 09:03:06 +0000 Subject: [PATCH] prepaid card recharge --- FS/FS/ClientAPI/MyAccount.pm | 37 +++- FS/FS/Conf.pm | 7 + FS/FS/cust_main.pm | 236 ++++++++++++++++++--- FS/FS/svc_acct.pm | 77 +++++-- fs_selfservice/FS-SelfService/SelfService.pm | 1 + .../FS-SelfService/cgi/agent_delete_svc.html | 1 - fs_selfservice/FS-SelfService/cgi/delete_svc.html | 1 - .../FS-SelfService/cgi/make_payment.html | 1 - fs_selfservice/FS-SelfService/cgi/myaccount.html | 1 - .../FS-SelfService/cgi/myaccount_menu.html | 92 +++++++- .../FS-SelfService/cgi/payment_results.html | 1 - .../FS-SelfService/cgi/process_svc_acct.html | 1 - .../FS-SelfService/cgi/process_svc_external.html | 1 - fs_selfservice/FS-SelfService/cgi/provision.html | 1 - .../FS-SelfService/cgi/provision_svc_acct.html | 1 - .../FS-SelfService/cgi/recharge_prepay.html | 36 ++++ .../FS-SelfService/cgi/recharge_results.html | 24 +++ fs_selfservice/FS-SelfService/cgi/selfservice.cgi | 20 +- .../FS-SelfService/cgi/view_invoice.html | 1 - httemplate/view/svc_acct.cgi | 5 + 20 files changed, 479 insertions(+), 66 deletions(-) create mode 100644 fs_selfservice/FS-SelfService/cgi/recharge_prepay.html create mode 100644 fs_selfservice/FS-SelfService/cgi/recharge_results.html diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 478973396..60d1f64d9 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -6,6 +6,7 @@ use subs qw(_cache); use Digest::MD5 qw(md5_hex); use Date::Format; use Business::CreditCard; +use Time::Duration; use FS::CGI qw(small_custview); #doh use FS::Conf; use FS::Record qw(qsearch qsearchs); @@ -135,12 +136,16 @@ sub customer_info { $return{'postal_invoicing'} = 0 < ( grep { $_ eq 'POST' } $cust_main->invoicing_list ); - } else { #no customer record + } elsif ( $session->{'svcnum'} ) { #no customer record my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $session->{'svcnum'} } ) or die "unknown svcnum"; $return{name} = $svc_acct->email; + } else { + + return { 'error' => 'Expired session' }; #XXX redirect to login w/this err! + } return { 'error' => '', @@ -357,6 +362,36 @@ sub process_payment { } +sub process_prepay { + + my $p = shift; + + my $session = _cache->get($p->{'session_id'}) + or return { 'error' => "Can't resume session" }; #better error message + + my %return; + + my $custnum = $session->{'custnum'}; + + my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) + or return { 'error' => "unknown custnum $custnum" }; + + my( $amount, $seconds ) = ( 0, 0 ); + my $error = $cust_main->recharge_prepay( $p->{'prepaid_cardnum'}, + \$amount, + \$seconds + ); + + return { 'error' => $error } if $error; + + return { 'error' => '', + 'amount' => $amount, + 'seconds' => $seconds, + 'duration' => duration_exact($seconds), + }; + +} + sub invoice { my $p = shift; my $session = _cache->get($p->{'session_id'}) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index ea2785bdf..a1fdd034e 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1531,6 +1531,13 @@ httemplate/docs/config.html 'type' => 'checkbox', }, + { + 'key' => 'svc_acct-usage_unsuspend', + 'section' => 'billing', + 'description' => 'Unuspends the package an account belongs to when svc_acct.seconds is incremented from 0 or below to a positive value (accounts with an empty seconds value are ignored). Typically used in conjunction with prepaid packages and freeside-sqlradius-radacctd.', + 'type' => 'checkbox', + }, + ); 1; diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 1edd319cb..775523a56 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1,7 +1,7 @@ package FS::cust_main; use strict; -use vars qw( @ISA @EXPORT_OK $DEBUG $conf @encrypted_fields +use vars qw( @ISA @EXPORT_OK $DEBUG $me $conf @encrypted_fields $import $skip_fuzzyfiles ); use vars qw( $realtime_bop_decline_quiet ); #ugh use Safe; @@ -51,7 +51,7 @@ use FS::Msgcat qw(gettext); $realtime_bop_decline_quiet = 0; $DEBUG = 0; -#$DEBUG = 1; +$me = '[FS::cust_main]'; $import = 0; $skip_fuzzyfiles = 0; @@ -349,33 +349,21 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $prepay_credit = ''; - my $seconds = 0; + my $prepay_identifier = ''; + my( $amount, $seconds ) = ( 0, 0 ); if ( $self->payby eq 'PREPAY' ) { + $self->payby('BILL'); - $prepay_credit = qsearchs( - 'prepay_credit', - { 'identifier' => $self->payinfo }, - '', - 'FOR UPDATE' - ); - unless ( $prepay_credit ) { - $dbh->rollback if $oldAutoCommit; - return "Invalid prepaid card: ". $self->payinfo; - } - $seconds = $prepay_credit->seconds; - if ( $prepay_credit->agentnum ) { - if ( $self->agentnum && $self->agentnum != $prepay_credit->agentnum ) { - $dbh->rollback if $oldAutoCommit; - return "prepaid card not valid for agent ". $self->agentnum; - } - $self->agentnum($prepay_credit->agentnum); - } - my $error = $prepay_credit->delete; + $prepay_identifier = $self->payinfo; + $self->payinfo(''); + + my $error = $self->get_prepay($prepay_identifier, \$amount, \$seconds); if ( $error ) { $dbh->rollback if $oldAutoCommit; - return "removing prepay_credit (transaction rolled back): $error"; + #return "error applying prepaid card (transaction rolled back): $error"; + return $error; } + } my $error = $self->SUPER::insert; @@ -407,15 +395,8 @@ sub insert { return "No svc_acct record to apply pre-paid time"; } - if ( $prepay_credit && $prepay_credit->amount ) { - my $cust_pay = new FS::cust_pay { - 'custnum' => $self->custnum, - 'paid' => $prepay_credit->amount, - #'_date' => #date the prepaid card was purchased??? - 'payby' => 'PREP', - 'payinfo' => $prepay_credit->identifier, - }; - $error = $cust_pay->insert; + if ( $amount ) { + $error = $self->insert_prepay($amount, $prepay_identifier); if ( $error ) { $dbh->rollback if $oldAutoCommit; return "inserting prepayment (transaction rolled back): $error"; @@ -526,6 +507,195 @@ sub order_pkgs { ''; #no error } +=item recharge_prepay IDENTIFIER | PREPAY_CREDIT_OBJ [ , AMOUNTREF, SECONDSREF ] + +Recharges this (existing) customer with the specified prepaid card (see +L), specified either by I or as an +FS::prepay_credit object. If there is an error, returns the error, otherwise +returns false. + +Optionally, two scalar references can be passed as well. They will have their +values filled in with the amount and number of seconds applied by this prepaid +card. + +=cut + +sub recharge_prepay { + my( $self, $prepay_credit, $amountref, $secondsref ) = @_; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my( $amount, $seconds ) = ( 0, 0 ); + + my $error = $self->get_prepay($prepay_credit, \$amount, \$seconds) + || $self->increment_seconds($seconds) + || $self->insert_cust_pay_prepay( $amount, + ref($prepay_credit) + ? $prepay_credit->identifier + : $prepay_credit + ); + + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + if ( defined($amountref) ) { $$amountref = $amount; } + if ( defined($secondsref) ) { $$secondsref = $seconds; } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; + +} + +=item get_prepay IDENTIFIER | PREPAY_CREDIT_OBJ , AMOUNTREF, SECONDSREF + +Looks up and deletes a prepaid card (see L), +specified either by I or as an FS::prepay_credit object. + +References to I and I scalars should be passed as arguments +and will be incremented by the values of the prepaid card. + +If the prepaid card specifies an I (see L), it is used to +check or set this customer's I. + +If there is an error, returns the error, otherwise returns false. + +=cut + + +sub get_prepay { + my( $self, $prepay_credit, $amountref, $secondsref ) = @_; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + unless ( ref($prepay_credit) ) { + + my $identifier = $prepay_credit; + + $prepay_credit = qsearchs( + 'prepay_credit', + { 'identifier' => $prepay_credit }, + '', + 'FOR UPDATE' + ); + + unless ( $prepay_credit ) { + $dbh->rollback if $oldAutoCommit; + return "Invalid prepaid card: ". $identifier; + } + + } + + if ( $prepay_credit->agentnum ) { + if ( $self->agentnum && $self->agentnum != $prepay_credit->agentnum ) { + $dbh->rollback if $oldAutoCommit; + return "prepaid card not valid for agent ". $self->agentnum; + } + $self->agentnum($prepay_credit->agentnum); + } + + my $error = $prepay_credit->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "removing prepay_credit (transaction rolled back): $error"; + } + + $$amountref += $prepay_credit->amount; + $$secondsref += $prepay_credit->seconds; + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; + +} + +=item increment_seconds SECONDS + +Updates this customer's single or primary account (see L) by +the specified number of seconds. If there is an error, returns the error, +otherwise returns false. + +=cut + +sub increment_seconds { + my( $self, $seconds ) = @_; + warn "$me increment_seconds called: $seconds seconds\n" + if $DEBUG; + + my @cust_pkg = grep { $_->part_pkg->svcpart('svc_acct') } + $self->ncancelled_pkgs; + + if ( ! @cust_pkg ) { + return 'No packages with primary or single services found'. + ' to apply pre-paid time'; + } elsif ( scalar(@cust_pkg) > 1 ) { + #maybe have a way to specify the package/account? + return 'Multiple packages found to apply pre-paid time'; + } + + my $cust_pkg = $cust_pkg[0]; + warn " found package pkgnum ". $cust_pkg->pkgnum. "\n" + if $DEBUG; + + my @cust_svc = + $cust_pkg->cust_svc( $cust_pkg->part_pkg->svcpart('svc_acct') ); + + if ( ! @cust_svc ) { + return 'No account found to apply pre-paid time'; + } elsif ( scalar(@cust_svc) > 1 ) { + return 'Multiple accounts found to apply pre-paid time'; + } + + my $svc_acct = $cust_svc[0]->svc_x; + warn " found service svcnum ". $svc_acct->pkgnum. + ' ('. $svc_acct->email. ")\n" + if $DEBUG; + + $svc_acct->increment_seconds($seconds); + +} + +=item insert_cust_pay_prepay AMOUNT [ PAYINFO ] + +Inserts a prepayment in the specified amount for this customer. An optional +second argument can specify the prepayment identifier for tracking purposes. +If there is an error, returns the error, otherwise returns false. + +=cut + +sub insert_cust_pay_prepay { + my( $self, $amount ) = splice(@_, 0, 2); + my $payinfo = scalar(@_) ? shift : ''; + + my $cust_pay = new FS::cust_pay { + 'custnum' => $self->custnum, + 'paid' => $amount, + #'_date' => #date the prepaid card was purchased??? + 'payby' => 'PREP', + 'payinfo' => $payinfo, + }; + $cust_pay->insert; + +} + =item reexport This method is deprecated. See the I option to the insert and diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index a0451938a..496312062 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -37,7 +37,6 @@ use FS::svc_www; @ISA = qw( FS::svc_Common ); $DEBUG = 0; -#$DEBUG = 1; $me = '[FS::svc_acct]'; #ask FS::UID to run this stuff for us later @@ -1117,12 +1116,45 @@ sub acct_snarf { =item decrement_seconds SECONDS -Decrements the I field of this record by the given amount. +Decrements the I field of this record by the given amount. If there +is an error, returns the error, otherwise returns false. =cut sub decrement_seconds { - my( $self, $seconds ) = @_; + shift->_op_seconds('-', @_); +} + +=item increment_seconds SECONDS + +Increments the I field of this record by the given amount. If there +is an error, returns the error, otherwise returns false. + +=cut + +sub increment_seconds { + shift->_op_seconds('+', @_); +} + + +my %op2action = ( + '-' => 'suspend', + '+' => 'unsuspend', +); +my %op2condition = ( + '-' => sub { my($self, $seconds) = @_; + $self->seconds - $seconds <= 0; + }, + '+' => sub { my($self, $seconds) = @_; + $self->seconds + $seconds > 0; + }, +); + +sub _op_seconds { + my( $self, $op, $seconds ) = @_; + warn "$me _op_seconds called for svcnum ". $self->svcnum. + ' ('. $self->email. "): $op $seconds\n" + if $DEBUG; local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -1134,22 +1166,41 @@ sub decrement_seconds { my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; - - my $sth = dbh->prepare( - 'UPDATE svc_acct SET seconds = seconds - ? WHERE svcnum = ?' - ) or die dbh->errstr;; - $sth->execute($seconds, $self->svcnum) or die $sth->errstr; - if ( $conf->exists('svc_acct-usage_suspend') - && $self->seconds - $seconds <= 0 ) { - #my $error = $self->suspend; - my $error = $self->cust_svc->cust_pkg->suspend; - die $error if $error; + + my $sql = "UPDATE svc_acct SET seconds = ". + " CASE WHEN seconds IS NULL THEN 0 ELSE seconds END ". #$seconds||0 + " $op ? WHERE svcnum = ?"; + warn "$me $sql\n" + if $DEBUG; + + my $sth = $dbh->prepare( $sql ) + or die "Error preparing $sql: ". $dbh->errstr; + my $rv = $sth->execute($seconds, $self->svcnum); + die "Error executing $sql: ". $sth->errstr + unless defined($rv); + die "Can't update seconds for svcnum". $self->svcnum + if $rv == 0; + + my $action = $op2action{$op}; + + if ( $conf->exists("svc_acct-usage_$action") + && &{$op2condition{$op}}($self, $seconds) ) { + #my $error = $self->$action(); + my $error = $self->cust_svc->cust_pkg->$action(); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "Error ${action}ing: $error"; + } } + warn "$me update sucessful; committing\n" + if $DEBUG; $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; } + =item seconds_since TIMESTAMP Returns the number of seconds this account has been online since TIMESTAMP, diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index 0f581758b..1e6c4ec0c 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -31,6 +31,7 @@ $socket .= '.'.$tag if defined $tag && length($tag); 'cancel' => 'MyAccount/cancel', #add to ss cgi! 'payment_info' => 'MyAccount/payment_info', 'process_payment' => 'MyAccount/process_payment', + 'process_prepay' => 'MyAccount/process_prepay', 'list_pkgs' => 'MyAccount/list_pkgs', #add to ss cgi! 'order_pkg' => 'MyAccount/order_pkg', #add to ss cgi! 'cancel_pkg' => 'MyAccount/cancel_pkg', #add to ss cgi! diff --git a/fs_selfservice/FS-SelfService/cgi/agent_delete_svc.html b/fs_selfservice/FS-SelfService/cgi/agent_delete_svc.html index e8be07ed1..7a2b75071 100644 --- a/fs_selfservice/FS-SelfService/cgi/agent_delete_svc.html +++ b/fs_selfservice/FS-SelfService/cgi/agent_delete_svc.html @@ -1,7 +1,6 @@ MyAccount MyAccount

<%= $url = "$selfurl?session=$session_id;action="; ''; %> - <%= include('myaccount_menu') %>
<%= $small_custview %> diff --git a/fs_selfservice/FS-SelfService/cgi/delete_svc.html b/fs_selfservice/FS-SelfService/cgi/delete_svc.html index 16054a77c..8468deb4b 100644 --- a/fs_selfservice/FS-SelfService/cgi/delete_svc.html +++ b/fs_selfservice/FS-SelfService/cgi/delete_svc.html @@ -1,7 +1,6 @@ MyAccount MyAccount

<%= $url = "$selfurl?session=$session_id;action="; ''; %> - <%= include('myaccount_menu') %>
diff --git a/fs_selfservice/FS-SelfService/cgi/make_payment.html b/fs_selfservice/FS-SelfService/cgi/make_payment.html index 3522c0867..1bbbe90b2 100644 --- a/fs_selfservice/FS-SelfService/cgi/make_payment.html +++ b/fs_selfservice/FS-SelfService/cgi/make_payment.html @@ -1,7 +1,6 @@ MyAccount MyAccount

<%= $url = "$selfurl?session=$session_id;action="; ''; %> - <%= include('myaccount_menu') %>
Make a payment

diff --git a/fs_selfservice/FS-SelfService/cgi/myaccount.html b/fs_selfservice/FS-SelfService/cgi/myaccount.html index 9997d7059..546ca1112 100644 --- a/fs_selfservice/FS-SelfService/cgi/myaccount.html +++ b/fs_selfservice/FS-SelfService/cgi/myaccount.html @@ -1,7 +1,6 @@ MyAccount MyAccount

<%= $url = "$selfurl?session=$session_id;action="; ''; %> - <%= include('myaccount_menu') %>
diff --git a/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html b/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html index ba3b3f2ff..f2e5e998e 100644 --- a/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html +++ b/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html @@ -1,13 +1,89 @@ <%= $url = "$selfurl?session=$session_id;action="; ''; %> + diff --git a/fs_selfservice/FS-SelfService/cgi/payment_results.html b/fs_selfservice/FS-SelfService/cgi/payment_results.html index 44289deba..de6c54dae 100644 --- a/fs_selfservice/FS-SelfService/cgi/payment_results.html +++ b/fs_selfservice/FS-SelfService/cgi/payment_results.html @@ -1,7 +1,6 @@ MyAccountMyAccount

<%= $url = "$selfurl?session=$session_id;action="; ''; %> -
-Overview

-Change payment info *

-Change service address *

-Setup my services

-Purchase additional package *

- -Change password(s)

-Logout

+ + +<%= + +my @menu = ( +{ title=>' ' }, +{ title=>'Overview', url=>'myaccount', size=>'+1', }, +{ title=>' ' }, + +{ title=>'Purchase', size=>'+1', }, + { title=>'Purchase additional package*', url=>'order', 'indent'=>2 }, +); + +if ( 1 ) { #XXXFIXME "enable selfservice prepay features" flag or something, eventually per-pkg or something really fancy + + push @menu, ( + { title=>'Recharge my account with a credit card', + url=>'make_payment', indent=>2 }, + { title=>'Recharge my account with a prepaid card', + url=>'recharge_prepay', indent=>2 }, + ); + +} + +push @menu, ( + +{ title=>' ' }, + +{ title=>'Setup my services', url=>'provision', size=>'+1', }, + +{ title=>' ' }, + +{ title=>'Change my information', size=>'+1', }, + { title=>'Change payment information*', url=>'change_bill', indent=>2 }, + { title=>'Change service address*', url=>'change_ship', indent=>2 }, + { title=>'Change password(s)*', url=>'hmmmFIXME', indent=>2 }, + +{ title=>' ' }, + +{ title=>'Logout', url=>'logout', size=>'+1', }, + +); + +foreach my $item ( @menu ) { + + $OUT .= '{'url'} && $action eq $item->{'url'} ) { + $OUT .= ' BGCOLOR="#eeeeee" '. + ' STYLE="border-top: 1px solid black;'. + ' border-left: 1px solid black;'. + ' border-bottom: 1px solid black"'; + } else { + $OUT .= ' STYLE="border-right: 1px solid black"'; + } + $OUT.='>'; + + $OUT .= '' + if exists $item->{'size'}; + + $OUT .= ' ' x $item->{'indent'} + if exists $item->{'indent'}; + + $OUT .= '' + if exists $item->{'url'} && $action ne $item->{'url'}; + + $item->{'title'} =~ s/ / /g; + $OUT .= $item->{'title'}; + + $OUT .= '' + if exists $item->{'size'}; + + $OUT .= '' + if exists $item->{'url'} && $action ne $item->{'url'}; + + $OUT .= ''; + +} + +%> + +
+ +(tempFIXME) Change password(s)

* coming soon
<%= include('myaccount_menu') %>
Payment results

diff --git a/fs_selfservice/FS-SelfService/cgi/process_svc_acct.html b/fs_selfservice/FS-SelfService/cgi/process_svc_acct.html index 7052059c4..200a80dc9 100644 --- a/fs_selfservice/FS-SelfService/cgi/process_svc_acct.html +++ b/fs_selfservice/FS-SelfService/cgi/process_svc_acct.html @@ -1,7 +1,6 @@ MyAccount MyAccount

<%= $url = "$selfurl?session=$session_id;action="; ''; %> - <%= include('myaccount_menu') %>
diff --git a/fs_selfservice/FS-SelfService/cgi/process_svc_external.html b/fs_selfservice/FS-SelfService/cgi/process_svc_external.html index 772cf0838..2328fa10f 100644 --- a/fs_selfservice/FS-SelfService/cgi/process_svc_external.html +++ b/fs_selfservice/FS-SelfService/cgi/process_svc_external.html @@ -1,7 +1,6 @@ <%= $error ? 'MyAccount' : sprintf("Your serial number is %010d-$title", $id) %> MyAccount

<%= $url = "$selfurl?session=$session_id;action="; ''; %> - <%= include('myaccount_menu') %>
diff --git a/fs_selfservice/FS-SelfService/cgi/provision.html b/fs_selfservice/FS-SelfService/cgi/provision.html index 6d80e89db..d31e6070b 100644 --- a/fs_selfservice/FS-SelfService/cgi/provision.html +++ b/fs_selfservice/FS-SelfService/cgi/provision.html @@ -1,7 +1,6 @@ MyAccount MyAccount

<%= $url = "$selfurl?session=$session_id;action="; ''; %> - <%= include('myaccount_menu') %>
<%= include('provision_list') %> diff --git a/fs_selfservice/FS-SelfService/cgi/provision_svc_acct.html b/fs_selfservice/FS-SelfService/cgi/provision_svc_acct.html index cf3585721..50540742a 100644 --- a/fs_selfservice/FS-SelfService/cgi/provision_svc_acct.html +++ b/fs_selfservice/FS-SelfService/cgi/provision_svc_acct.html @@ -1,7 +1,6 @@ MyAccount MyAccount

<%= $url = "$selfurl?session=$session_id;action="; ''; %> - <%= include('myaccount_menu') %>
<%= include('svc_acct') %> diff --git a/fs_selfservice/FS-SelfService/cgi/recharge_prepay.html b/fs_selfservice/FS-SelfService/cgi/recharge_prepay.html new file mode 100644 index 000000000..f8584597a --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/recharge_prepay.html @@ -0,0 +1,36 @@ +MyAccount +MyAccount

+<%= $url = "$selfurl?session=$session_id;action="; ''; %> +<%= include('myaccount_menu') %> +
+Recharge with prepaid card

+
+ + + + + + + + +
Prepaid card number + +
+
+ + +
+
+
+powered by freeside + + diff --git a/fs_selfservice/FS-SelfService/cgi/recharge_results.html b/fs_selfservice/FS-SelfService/cgi/recharge_results.html new file mode 100644 index 000000000..ec3ea2c7a --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/recharge_results.html @@ -0,0 +1,24 @@ +MyAccount +MyAccount

+<%= $url = "$selfurl?session=$session_id;action="; ''; %> +<%= include('myaccount_menu') %> +
+Recharge results

+<%= if ( $error ) { + $OUT .= qq!Error processing your prepaid card: $error!; +} else { + $OUT .= 'Prepaid card recharge sucessful!

'; + + $OUT .= '$'. sprintf('%.2f', $amount). ' added to your account.

' + if $amount; + + $OUT .= $duration. ' added to your account.

' + if $seconds; + + $OUT .= 'Thank you.'; +} %> +
+
+powered by freeside + + diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi index 0816758fb..034a684c6 100644 --- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -9,6 +9,7 @@ use Text::Template; use HTML::Entities; use FS::SelfService qw( login customer_info invoice payment_info process_payment + process_prepay list_pkgs part_svc_info provision_acct provision_external unprovision_svc @@ -61,7 +62,7 @@ $session_id = $cgi->param('session'); #order|pw_list XXX ??? $cgi->param('action') =~ - /^(myaccount|view_invoice|make_payment|payment_results|logout|change_bill|change_ship|provision|provision_svc|process_svc_acct|process_svc_external|delete_svc)$/ + /^(myaccount|view_invoice|make_payment|payment_results|recharge_prepay|recharge_results|logout|change_bill|change_ship|provision|provision_svc|process_svc_acct|process_svc_external|delete_svc)$/ or die "unknown action ". $cgi->param('action'); my $action = $1; @@ -79,6 +80,7 @@ if ( $result->{error} eq "Can't resume session" ) { #ick warn "processing template $action\n"; do_template($action, { 'session_id' => $session_id, + 'action' => $action, #so the menu knows what tab we're on... %{$result} }); @@ -173,6 +175,22 @@ sub payment_results { } +sub recharge_prepay { + customer_info( 'session_id' => $session_id ); +} + +sub recharge_results { + + my $prepaid_cardnum = $cgi->param('prepaid_cardnum'); + $prepaid_cardnum =~ s/\W//g; + $prepaid_cardnum =~ /^(\w*)$/ or die "illegal prepaid card number"; + $prepaid_cardnum = $1; + + process_prepay ( 'session_id' => $session_id, + 'prepaid_cardnum' => $prepaid_cardnum, + ); +} + sub logout { FS::SelfService::logout( 'session_id' => $session_id ); } diff --git a/fs_selfservice/FS-SelfService/cgi/view_invoice.html b/fs_selfservice/FS-SelfService/cgi/view_invoice.html index 46f731890..72d061980 100644 --- a/fs_selfservice/FS-SelfService/cgi/view_invoice.html +++ b/fs_selfservice/FS-SelfService/cgi/view_invoice.html @@ -1,7 +1,6 @@ MyAccount MyAccount

<%= $url = "$selfurl?session=$session_id;action="; ''; %> - <%= include('myaccount_menu') %> '; +if ( $svc_acct->seconds =~ /^\d+$/ ) { + print ''; +} + # Can this be abstracted further? Maybe a library function like # widget('HTML', 'view', $svc_acct) ? It would definitely make UI # style management easier. -- 2.11.0
diff --git a/httemplate/view/svc_acct.cgi b/httemplate/view/svc_acct.cgi index 246a7fbc8..1486d7b11 100755 --- a/httemplate/view/svc_acct.cgi +++ b/httemplate/view/svc_acct.cgi @@ -283,6 +283,11 @@ foreach $attribute ( grep /^rc_/, $svc_acct->fields ) { print '
RADIUS groups'. join('
', $svc_acct->radius_groups). '
Prepaid time'. + duration_exact($svc_acct->seconds). '