use strict;
use vars qw($cache);
+use subs qw(_cache);
use Digest::MD5 qw(md5_hex);
use Date::Format;
use Business::CreditCard;
-use Cache::SharedMemoryCache; #store in db?
+use Time::Duration;
use FS::CGI qw(small_custview); #doh
use FS::Conf;
use FS::Record qw(qsearch qsearchs);
use FS::Msgcat qw(gettext);
+use FS::ClientAPI_SessionCache;
use FS::svc_acct;
use FS::svc_domain;
use FS::svc_external;
use FS::cust_main_county;
use FS::cust_pkg;
-#use FS::ClientAPI; #hmm
-FS::ClientAPI->register_handlers(
- 'MyAccount/login' => \&login,
- 'MyAccount/logout' => \&logout,
- '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,
- 'MyAccount/list_pkgs' => \&list_pkgs,
- 'MyAccount/order_pkg' => \&order_pkg,
- 'MyAccount/cancel_pkg' => \&cancel_pkg,
- 'MyAccount/charge' => \&charge,
- 'MyAccount/part_svc_info' => \&part_svc_info,
- 'MyAccount/provision_acct' => \&provision_acct,
- 'MyAccount/provision_external' => \&provision_external,
- 'MyAccount/unprovision_svc' => \&unprovision_svc,
-);
-
use vars qw( @cust_main_editable_fields );
@cust_main_editable_fields = qw(
first last company address1 address2 city
county state zip country daytime night fax
ship_first ship_last ship_company ship_address1 ship_address2 ship_city
ship_state ship_zip ship_country ship_daytime ship_night ship_fax
- payby payinfo payname
+ payby payinfo payname paystart_month paystart_year payissue payip
);
use subs qw(_provision);
-#store in db?
-my $cache = new Cache::SharedMemoryCache( {
- 'namespace' => 'FS::ClientAPI::MyAccount',
-} );
+sub _cache {
+ $cache ||= new FS::ClientAPI_SessionCache( {
+ 'namespace' => 'FS::ClientAPI::MyAccount',
+ } );
+}
#false laziness w/FS::ClientAPI::passwd::passwd
sub login {
my $session_id;
do {
$session_id = md5_hex(md5_hex(time(). {}. rand(). $$))
- } until ( ! defined $cache->get($session_id) ); #just in case
+ } until ( ! defined _cache->get($session_id) ); #just in case
- $cache->set( $session_id, $session, '1 hour' );
+ _cache->set( $session_id, $session, '1 hour' );
return { 'error' => '',
'session_id' => $session_id,
sub logout {
my $p = shift;
if ( $p->{'session_id'} ) {
- $cache->remove($p->{'session_id'});
+ _cache->remove($p->{'session_id'});
return { 'error' => '' };
} else {
return { 'error' => "Can't resume session" }; #better error message
}
$return{'invoicing_list'} =
- join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list );
+ join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list );
$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' => '',
sub edit_info {
my $p = shift;
- my $session = $cache->get($p->{'session_id'})
+ my $session = _cache->get($p->{'session_id'})
or return { 'error' => "Can't resume session" }; #better error message
my $custnum = $session->{'custnum'}
sub payment_info {
my $p = shift;
- my $session = $cache->get($p->{'session_id'})
+ my $session = _cache->get($p->{'session_id'})
or return { 'error' => "Can't resume session" }; #better error message
##
'MasterCard' => 'MasterCard',
'Discover' => 'Discover card',
'American Express' => 'American Express card',
+ 'Switch' => 'Switch',
+ 'Solo' => 'Solo',
},
};
my $p = shift;
- my $session = $cache->get($p->{'session_id'})
+ my $session = _cache->get($p->{'session_id'})
or return { 'error' => "Can't resume session" }; #better error message
my %return;
'payname' => $payname,
'paybatch' => $paybatch,
'paycvv' => $paycvv,
- map { $_ => $p->{$_} } qw( address1 address2 city state zip )
+ map { $_ => $p->{$_} } qw( paystart_month paystart_year payissue payip
+ address1 address2 city state zip )
);
return { 'error' => $error } if $error;
if ( $p->{'save'} ) {
my $new = new FS::cust_main { $cust_main->hash };
$new->set( $_ => $p->{$_} )
- foreach qw( payname address1 address2 city state zip payinfo );
+ foreach qw( payname paystart_month paystart_year payissue payip
+ address1 address2 city state zip payinfo );
$new->set( 'paydate' => $p->{'year'}. '-'. $p->{'month'}. '-01' );
$new->set( 'payby' => $p->{'auto'} ? 'CARD' : 'DCRD' );
my $error = $new->replace($cust_main);
}
+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'})
+ my $session = _cache->get($p->{'session_id'})
or return { 'error' => "Can't resume session" }; #better error message
my $custnum = $session->{'custnum'};
sub list_invoices {
my $p = shift;
- my $session = $cache->get($p->{'session_id'})
+ my $session = _cache->get($p->{'session_id'})
or return { 'error' => "Can't resume session" }; #better error message
my $custnum = $session->{'custnum'};
sub cancel {
my $p = shift;
- my $session = $cache->get($p->{'session_id'})
+ my $session = _cache->get($p->{'session_id'})
or return { 'error' => "Can't resume session" }; #better error message
my $custnum = $session->{'custnum'};
sub cancel_pkg {
my $p = shift;
- my $session = $cache->get($p->{'session_id'})
+ my $session = _cache->get($p->{'session_id'})
or return { 'error' => "Can't resume session" }; #better error message
my $custnum = $session->{'custnum'};
if ( $p->{'session_id'} ) {
$context = 'customer';
- $session = $cache->get($p->{'session_id'})
- or return { 'error' => "Can't resume session" }; #better error message
+ $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( {
+ my $agent_cache = new FS::ClientAPI_SessionCache( {
'namespace' => 'FS::ClientAPI::Agent',
} );
$session = $agent_cache->get($p->{'agent_session_id'})
- or return { 'error' => "Can't resume session" }; #better error message
+ or return ( 'error' => "Can't resume session" ); #better error message
$custnum = $p->{'custnum'};
} else {
- return { 'error' => "Can't resume session" }; #better error message
+ return ( 'error' => "Can't resume session" ); #better error message
}
($context, $session, $custnum);
}
-
1;