freeside/FS/FS/ClientAPI Agent.pm,NONE,1.1 Signup.pm,1.13,1.14 MyAccount.pm,1.20,1.21
ivan
ivan at pouncequick.420.am
Thu Jun 10 05:31:35 PDT 2004
- Previous message: freeside/fs_selfservice/FS-SelfService/cgi agent.cgi,NONE,1.1 agent_login.html,NONE,1.1 agent_main.html,NONE,1.1 signup.html,NONE,1.1 cvv2.html,NONE,1.1 cvv2.png,NONE,1.1 cvv2_amex.png,NONE,1.1 list_customers.html,NONE,1.1 view_customer.html,NONE,1.1
- Next message: freeside/httemplate/browse agent.cgi,1.18,1.19
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/cvsroot/freeside/FS/FS/ClientAPI
In directory pouncequick:/tmp/cvs-serv23020/FS/FS/ClientAPI
Modified Files:
Signup.pm MyAccount.pm
Added Files:
Agent.pm
Log Message:
agent interface
Index: Signup.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/ClientAPI/Signup.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- Signup.pm 3 Mar 2004 13:42:08 -0000 1.13
+++ Signup.pm 10 Jun 2004 12:31:31 -0000 1.14
@@ -22,7 +22,7 @@
);
sub signup_info {
- #my $packet = shift;
+ my $packet = shift;
my $conf = new FS::Conf;
@@ -87,24 +87,35 @@
};
- if (
- $conf->config('signup_server-default_agentnum')
- && !exists $signup_info->{'part_pkg'} #cache for performance
- ) {
- my $agentnum = $conf->config('signup_server-default_agentnum');
- my $agent = qsearchs( 'agent', { 'agentnum' => $agentnum } )
- or die "fatal: signup_server-default_agentnum $agentnum not found\n";
- my $pkgpart_href = $agent->pkgpart_hashref;
+ my $agentnum = $conf->config('signup_server-default_agentnum');
- $signup_info->{'part_pkg'} = [
- #map { $_->hashref }
- map { { 'payby' => [ $_->payby ], %{$_->hashref} } }
- grep { $_->svcpart('svc_acct') && $pkgpart_href->{ $_->pkgpart } }
- qsearch( 'part_pkg', { 'disabled' => '' } )
- ];
+ my $session = '';
+ if ( exists $packet->{'session_id'} ) {
+ my $cache = new Cache::SharedMemoryCache( {
+ 'namespace' => 'FS::ClientAPI::Agent',
+ } );
+ $session = $cache->get($packet->{'session_id'});
+ if ( $session ) {
+ $agentnum = $session->{'agentnum'};
+ } else {
+ return { 'error' => "Can't resume session" }; #better error message
+ }
}
- $signup_info;
+ if ( $agentnum ) {
+ $signup_info->{'part_pkg'} = $signup_info->{'agentnum2part_pkg'}{$agentnum};
+ } else {
+ delete $signup_info->{'part_pkg'};
+ }
+
+ if ( $session ) {
+ my $agent_signup_info = { %$signup_info };
+ delete $agent_signup_info->{agentnum2part_pkg};
+ $agent_signup_info->{'agent'} = $session->{'agent'};
+ $agent_signup_info;
+ } else {
+ $signup_info;
+ }
}
@@ -122,12 +133,27 @@
return { 'error' => gettext('no_access_number_selected') }
unless $packet->{'popnum'} || !scalar(qsearch('svc_acct_pop',{} ));
+ my $agentnum;
+ if ( exists $packet->{'session_id'} ) {
+ my $cache = new Cache::SharedMemoryCache( {
+ 'namespace' => 'FS::ClientAPI::Agent',
+ } );
+ my $session = $cache->get($packet->{'session_id'});
+ if ( $session ) {
+ $agentnum = $session->{'agentnum'};
+ } else {
+ return { 'error' => "Can't resume session" }; #better error message
+ }
+ } else {
+ $agentnum = $packet->{agentnum}
+ || $conf->config('signup_server-default_agentnum');
+ }
+
#shares some stuff with htdocs/edit/process/cust_main.cgi... take any
# common that are still here and library them.
my $cust_main = new FS::cust_main ( {
#'custnum' => '',
- 'agentnum' => $packet->{agentnum}
- || $conf->config('signup_server-default_agentnum'),
+ 'agentnum' => $agentnum,
'refnum' => $packet->{refnum}
|| $conf->config('signup_server-default_refnum'),
--- NEW FILE: Agent.pm ---
package FS::ClientAPI::Agent;
#some false laziness w/MyAccount
use strict;
use vars qw($cache);
use Digest::MD5 qw(md5_hex);
use Cache::SharedMemoryCache; #store in db?
use FS::Record qw(qsearchs); # qsearch);
use FS::agent;
use FS::ClientAPI;
FS::ClientAPI->register_handlers(
'Agent/agent_login' => \&agent_login,
'Agent/agent_info' => \&agent_info,
'Agent/agent_list_customers' => \&agent_list_customers,
);
#store in db?
my $cache = new Cache::SharedMemoryCache( {
'namespace' => 'FS::ClientAPI::Agent',
} );
sub agent_login {
my $p = shift;
#don't allow a blank login to first unconfigured agent with no user/pass
return { error => 'Must specify your reseller username and password.' }
unless length($p->{'username'}) && length($p->{'password'});
my $agent = qsearchs( 'agent', {
'username' => $p->{'username'},
'_password' => $p->{'password'},
} );
unless ( $agent ) { return { error => 'Incorrect password.' } }
my $session = {
'agentnum' => $agent->agentnum,
'agent' => $agent->agent,
};
my $session_id;
do {
$session_id = md5_hex(md5_hex(time(). {}. rand(). $$))
} until ( ! defined $cache->get($session_id) ); #just in case
$cache->set( $session_id, $session, '1 hour' );
{ 'error' => '',
'session_id' => $session_id,
};
}
sub agent_info {
my $p = shift;
my $session = $cache->get($p->{'session_id'})
or return { 'error' => "Can't resume session" }; #better error message
#my %return;
my $agentnum = $session->{'agentnum'};
my $agent = qsearchs( 'agent', { 'agentnum' => $agentnum } )
or return { 'error' => "unknown agentnum $agentnum" };
{ 'error' => '',
'agentnum' => $agentnum,
'agent' => $agent->agent,
'num_prospect' => $agent->num_prospect_cust_main,
'num_active' => $agent->num_active_cust_main,
'num_susp' => $agent->num_susp_cust_main,
'num_cancel' => $agent->num_cancel_cust_main,
#%return,
};
}
sub agent_list_customers {
my $p = shift;
my $session = $cache->get($p->{'session_id'})
or return { 'error' => "Can't resume session" }; #better error message
#my %return;
my $agentnum = $session->{'agentnum'};
my $agent = qsearchs( 'agent', { 'agentnum' => $agentnum } )
or return { 'error' => "unknown agentnum $agentnum" };
my @cust_main = ();
warn $p->{'susp'};
push @cust_main,
map $agent->$_(), map $_.'_cust_main',
grep $p->{$_}, qw( prospect active susp cancel );
{ customers => [ map {
my $cust_main = $_;
my $hashref = $cust_main->hashref;
$hashref->{$_} = $cust_main->$_()
foreach qw(name status statuscolor);
delete $hashref->{$_} foreach qw( payinfo paycvv );
$hashref;
} @cust_main
],
}
}
Index: MyAccount.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/ClientAPI/MyAccount.pm,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- MyAccount.pm 18 May 2004 00:20:53 -0000 1.20
+++ MyAccount.pm 10 Jun 2004 12:31:31 -0000 1.21
@@ -25,6 +25,7 @@
'MyAccount/customer_info' => \&customer_info,
'MyAccount/edit_info' => \&edit_info,
'MyAccount/invoice' => \&invoice,
+ 'MyAccount/list_invoices' => \&list_invoices,
'MyAccount/cancel' => \&cancel,
'MyAccount/payment_info' => \&payment_info,
'MyAccount/process_payment' => \&process_payment,
@@ -86,16 +87,31 @@
sub customer_info {
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($session, $custnum, $context);
+ if ( $p->{'session_id'} ) {
+ $context = 'customer';
+ $session = $cache->get($p->{'session_id'})
+ or return { 'error' => "Can't resume session" }; #better error message
+ $custnum = $session->{'custnum'};
+ } elsif ( $p->{'agent_session_id'} ) {
+ $context = 'agent';
+ my $agent_cache = new Cache::SharedMemoryCache( {
+ 'namespace' => 'FS::ClientAPI::Agent',
+ } );
+ $session = $agent_cache->get($p->{'agent_session_id'})
+ or return { 'error' => "Can't resume session" }; #better error message
+ $custnum = $p->{'custnum'};
+ } else {
+ return { 'error' => "Can't resume session" }; #better error message
+ }
+ my %return;
if ( $custnum ) { #customer record
- my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+ my $search = { 'custnum' => $custnum };
+ $search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent';
+ my $cust_main = qsearchs('cust_main', $search )
or return { 'error' => "unknown custnum $custnum" };
$return{balance} = $cust_main->balance;
@@ -357,6 +373,27 @@
}
+sub list_invoices {
+ my $p = shift;
+ my $session = $cache->get($p->{'session_id'})
+ or return { 'error' => "Can't resume session" }; #better error message
+
+ my $custnum = $session->{'custnum'};
+
+ my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+ or return { 'error' => "unknown custnum $custnum" };
+
+ my @cust_bill = $cust_main->cust_bill;
+
+ return { 'error' => '',
+ 'invoices' => [ map { { 'invnum' => $_->invnum,
+ '_date' => $_->_date,
+ }
+ } @cust_bill
+ ]
+ };
+}
+
sub cancel {
my $p = shift;
my $session = $cache->get($p->{'session_id'})
@@ -391,12 +428,30 @@
sub order_pkg {
my $p = shift;
- my $session = $cache->get($p->{'session_id'})
- or return { 'error' => "Can't resume session" }; #better error message
- my $custnum = $session->{'custnum'};
+ my($session, $custnum, $context);
- my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+ if ( $p->{'session_id'} ) {
+ $context = 'customer';
+ $session = $cache->get($p->{'session_id'})
+ or return { 'error' => "Can't resume session" }; #better error message
+ $custnum = $session->{'custnum'};
+ } elsif ( $p->{'agent_session_id'} ) {
+ $context = 'agent';
+ my $agent_cache = new Cache::SharedMemoryCache( {
+ 'namespace' => 'FS::ClientAPI::Agent',
+ } );
+ $session = $agent_cache->get($p->{'agent_session_id'})
+ or return { 'error' => "Can't resume session" }; #better error message
+ $custnum = $p->{'custnum'};
+ } else {
+ return { 'error' => "Can't resume session" }; #better error message
+ }
+
+ my $search = { 'custnum' => $custnum };
+ $search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent';
+
+ my $cust_main = qsearchs('cust_main', $search )
or return { 'error' => "unknown custnum $custnum" };
#false laziness w/ClientAPI/Signup.pm
@@ -503,13 +558,13 @@
my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
or return { 'error' => "unknown custnum $custnum" };
- my $pkgnum = $session->{'pkgnum'};
+ my $pkgnum = $p->{'pkgnum'};
my $cust_pkg = qsearchs('cust_pkg', { 'custnum' => $custnum,
'pkgnum' => $pkgnum, } )
or return { 'error' => "unknown pkgnum $pkgnum" };
- my $error = $cust_main->cancel( 'quiet'=>1 );
+ my $error = $cust_pkg->cancel( 'quiet'=>1 );
return { 'error' => $error };
}
- Previous message: freeside/fs_selfservice/FS-SelfService/cgi agent.cgi,NONE,1.1 agent_login.html,NONE,1.1 agent_main.html,NONE,1.1 signup.html,NONE,1.1 cvv2.html,NONE,1.1 cvv2.png,NONE,1.1 cvv2_amex.png,NONE,1.1 list_customers.html,NONE,1.1 view_customer.html,NONE,1.1
- Next message: freeside/httemplate/browse agent.cgi,1.18,1.19
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the freeside-commits
mailing list