X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FMyAccount.pm;h=21a923f3306df3420d0fcd76247ef76dc7e3e496;hb=f73dba57a29dea6dc340f61592ea32e081a74a1f;hp=3424966b14a530ff3d0a67794edc697763fb37ee;hpb=3db7a9e18974266c8181a071b25d7f2b82d6bc8f;p=freeside.git diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 3424966b1..21a923f33 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -171,6 +171,13 @@ sub login { ); return { error => 'User not found.' } unless $svc_acct; + if($conf->exists('selfservice_server-login_svcpart')) { + my @svcpart = $conf->config('selfservice_server-login_svcpart'); + my $svcpart = $svc_acct->cust_svc->svcpart; + return { error => 'Invalid user.' } + unless grep($_ eq $svcpart, @svcpart); + } + return { error => 'Incorrect password.' } unless $svc_acct->check_password($p->{'password'}); @@ -266,6 +273,9 @@ sub access_info { @{ $info->{cust_paybys} } ]; + $info->{'self_suspend_reason'} = + $conf->config('selfservice-self_suspend_reason'); + return { %$info, 'custnum' => $custnum, 'access_pkgnum' => $session->{'pkgnum'}, @@ -357,6 +367,11 @@ sub customer_info { $return{support_services} = \@support_services; } + if ( $conf->config('prepayment_discounts-credit_type') ) { + #need to eval? + $return{discount_terms_hash} = { $cust_main->discount_terms_hash }; + } + } elsif ( $session->{'svcnum'} ) { #no customer record my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $session->{'svcnum'} } ) @@ -459,10 +474,10 @@ sub payment_info { #generic ## + my $conf = new FS::Conf; use vars qw($payment_info); #cache for performance unless ( $payment_info ) { - my $conf = new FS::Conf; my %states = map { $_->state => 1 } qsearch('cust_main_county', { 'country' => $conf->config('countrydefault') || 'US' @@ -555,6 +570,11 @@ sub payment_info { } + if ( $conf->config('prepayment_discounts-credit_type') ) { + #need to eval? + $return{discount_terms_hash} = { $cust_main->discount_terms_hash }; + } + #doubleclick protection my $_date = time; $return{paybatch} = "webui-MyAccount-$_date-$$-". rand() * 2**32; @@ -586,6 +606,10 @@ sub process_payment { my $amount = $1; return { error => 'Amount must be greater than 0' } unless $amount > 0; + $p->{'discount_term'} =~ /^\s*(\d*)\s*$/ + or return { 'error' => gettext('illegal_discount_term'). ': '. $p->{'discount_term'} }; + my $discount_term = $1; + $p->{'payname'} =~ /^([\w \,\.\-\']+)$/ or return { 'error' => gettext('illegal_name'). " payname: ". $p->{'payname'} }; my $payname = $1; @@ -664,6 +688,7 @@ sub process_payment { 'paybatch' => $paybatch, #this doesn't actually do anything 'paycvv' => $paycvv, 'pkgnum' => $session->{'pkgnum'}, + 'discount_term' => $discount_term, map { $_ => $p->{$_} } @{ $payby2fields{$payby} } ); return { 'error' => $error } if $error; @@ -861,6 +886,7 @@ sub list_invoices { return { 'error' => '', 'invoices' => [ map { { 'invnum' => $_->invnum, '_date' => $_->_date, + 'date' => time2str("%b %o, %Y", $_->_date), } } @cust_bill ] @@ -896,9 +922,42 @@ sub list_pkgs { my $cust_main = qsearchs('cust_main', $search ) or return { 'error' => "unknown custnum $custnum" }; - #return { 'cust_pkg' => [ map { $_->hashref } $cust_main->ncancelled_pkgs ] }; - my $conf = new FS::Conf; + +# the duplication below is necessary: +# 1. to maintain the current buggy behaviour wrt the cust_pkg and part_pkg +# hashes overwriting each other (setup and no_auto fields). Fixing that is a +# non-backwards-compatible change breaking the software of anyone using the API +# instead of the stock selfservice +# 2. to return cancelled packages as well - for wholesale and non-wholesale + if( $conf->exists('selfservice_server-view-wholesale') ) { + return { 'svcnum' => $session->{'svcnum'}, + 'custnum' => $custnum, + 'cust_pkg' => [ map { + { $_->hash, + part_pkg => [ map $_->hashref, $_->part_pkg ], + part_svc => + [ map $_->hashref, $_->available_part_svc ], + cust_svc => + [ map { my $ref = { $_->hash, + label => [ $_->label ], + }; + $ref->{_password} = $_->svc_x->_password + if $context eq 'agent' + && $conf->exists('agent-showpasswords') + && $_->part_svc->svcdb eq 'svc_acct'; + $ref; + } $_->cust_svc + ], + }; + } $cust_main->cust_pkg + ], + 'small_custview' => + small_custview( $cust_main, $conf->config('countrydefault') ), + 'wholesale_view' => 1, + 'date_format' => $conf->config('date_format') || '%m/%d/%Y', + }; + } { 'svcnum' => $session->{'svcnum'}, 'custnum' => $custnum, @@ -1181,6 +1240,7 @@ sub order_pkg { 'svc_domain' => [ qw( domain ) ], 'svc_phone' => [ qw( phonenum pin sip_password phone_name ) ], 'svc_external' => [ qw( id title ) ], + 'svc_pbx' => [ qw( id name ) ], ); my $svc_x = "FS::$svcdb"->new( { @@ -1237,7 +1297,9 @@ sub order_pkg { $cust_pkg->reexport; } - return { error => '', pkgnum => $cust_pkg->pkgnum }; + my $svcnum = $svc[0] ? $svc[0]->svcnum : ''; + + return { error=>'', pkgnum=>$cust_pkg->pkgnum, svcnum=>$svcnum }; } @@ -1435,8 +1497,18 @@ sub order_renew { } -sub cancel_pkg { +# these are basically the same +sub cancel_pkg { alter_pkg(shift, 'cancel', 'quiet' => 1) } +sub suspend_pkg { + my $conf = new FS::Conf; + my $reasonnum = $conf->config('selfservice-self_suspend_reason') + or return { 'error' => "Permission denied" }; + alter_pkg(shift, 'suspend', 'reason' => $reasonnum) +} + +sub alter_pkg { my $p = shift; + my $method = shift; my $session = _cache->get($p->{'session_id'}) or return { 'error' => "Can't resume session" }; #better error message @@ -1451,7 +1523,7 @@ sub cancel_pkg { 'pkgnum' => $pkgnum, } ) or return { 'error' => "unknown pkgnum $pkgnum" }; - my $error = $cust_pkg->cancel( 'quiet'=>1 ); + my $error = $cust_pkg->$method(@_); return { 'error' => $error }; } @@ -1669,10 +1741,6 @@ sub create_ticket { my($context, $session, $custnum) = _custoragent_session_custnum($p); return { 'error' => $session } if $context eq 'error'; - local($DEBUG) = 1; - local($FS::TicketSystem::RT_Internal::DEBUG) = 1; - local($FS::TicketSystem::RT_Internal::DEBUG) = 1; - warn "$me create_ticket: initializing ticket system\n" if $DEBUG; FS::TicketSystem->init(); @@ -1729,6 +1797,7 @@ sub _custoragent_session_custnum { $custnum = $p->{'custnum'}; } else { + $context = 'error'; return ( 'error' => "Can't resume session" ); #better error message }