X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FMyAccount.pm;h=0b19e116c7a21c7bd8df19f471a2fd8a3f956922;hb=6bc756ca8124ecc42fc1fed2dd660f1b08561d29;hp=b42a91e80e5c6c12997a4eb2a446546443833446;hpb=e3380da234d14fc2702300a90f4a0b5ff72cba82;p=freeside.git diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index b42a91e80..0b19e116c 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -17,6 +17,7 @@ use FS::Misc qw(card_types); use FS::ClientAPI_SessionCache; use FS::svc_acct; use FS::svc_domain; +use FS::svc_phone; use FS::svc_external; use FS::part_svc; use FS::cust_main; @@ -42,6 +43,7 @@ use vars qw( @cust_main_editable_fields ); 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 paystart_month paystart_year payissue payip + ss paytype paystate stateid stateid_state ); use subs qw(_provision); @@ -56,28 +58,53 @@ sub _cache { sub login { my $p = shift; - my $svc_domain = qsearchs('svc_domain', { 'domain' => $p->{'domain'} } ) - or return { error => 'Domain '. $p->{'domain'}. ' not found' }; + my $conf = new FS::Conf; - my $svc_acct = qsearchs( 'svc_acct', { 'username' => $p->{'username'}, - 'domsvc' => $svc_domain->svcnum, } - ); - return { error => 'User not found.' } unless $svc_acct; + my $svc_x = ''; + if ( $p->{'domain'} eq 'svc_phone' + && $conf->exists('selfservice_server-phone_login') ) { - my $conf = new FS::Conf; - my $pkg_svc = $svc_acct->cust_svc->pkg_svc; - return { error => 'Only primary user may log in.' } - if $conf->exists('selfservice_server-primary_only') - && ( ! $pkg_svc || $pkg_svc->primary_svc ne 'Y' ); + my $svc_phone = qsearch( 'svc_phone', { 'phonenum' => $p->{'username'}, } ); + return { error => 'Number not found.' } unless $svc_phone; + + #XXX? + #my $pkg_svc = $svc_acct->cust_svc->pkg_svc; + #return { error => 'Only primary user may log in.' } + # if $conf->exists('selfservice_server-primary_only') + # && ( ! $pkg_svc || $pkg_svc->primary_svc ne 'Y' ); + + return { error => 'Incorrect PIN.' } + unless $svc_phone->check_pin($p->{'password'}); + + $svc_x = $svc_phone; + + } else { + + my $svc_domain = qsearchs('svc_domain', { 'domain' => $p->{'domain'} } ) + or return { error => 'Domain '. $p->{'domain'}. ' not found' }; + + my $svc_acct = qsearchs( 'svc_acct', { 'username' => $p->{'username'}, + 'domsvc' => $svc_domain->svcnum, } + ); + return { error => 'User not found.' } unless $svc_acct; + + my $pkg_svc = $svc_acct->cust_svc->pkg_svc; + return { error => 'Only primary user may log in.' } + if $conf->exists('selfservice_server-primary_only') + && ( ! $pkg_svc || $pkg_svc->primary_svc ne 'Y' ); + + return { error => 'Incorrect password.' } + unless $svc_acct->check_password($p->{'password'}); - return { error => 'Incorrect password.' } - unless $svc_acct->check_password($p->{'password'}); + $svc_x = $svc_acct; + + } my $session = { - 'svcnum' => $svc_acct->svcnum, + 'svcnum' => $svc_x->svcnum, }; - my $cust_pkg = $svc_acct->cust_svc->cust_pkg; + my $cust_pkg = $svc_x->cust_svc->cust_pkg; if ( $cust_pkg ) { my $cust_main = $cust_pkg->cust_main; $session->{'custnum'} = $cust_main->custnum; @@ -113,6 +140,14 @@ sub customer_info { return { 'error' => $session } if $context eq 'error'; my %return; + + my $conf = new FS::Conf; + if ($conf->exists('cust_main-require_address2')) { + $return{'require_address2'} = '1'; + }else{ + $return{'require_address2'} = ''; + } + if ( $custnum ) { #customer record my $search = { 'custnum' => $custnum }; @@ -133,7 +168,6 @@ sub customer_info { } $cust_main->open_cust_bill; $return{open_invoices} = \@open; - my $conf = new FS::Conf; $return{small_custview} = small_custview( $cust_main, $conf->config('countrydefault') ); @@ -208,13 +242,46 @@ sub edit_info { $new->set( $_ => $p->{$_} ) foreach grep { exists $p->{$_} } @cust_main_editable_fields; - if ( $p->{'payby'} =~ /^(CARD|DCRD)$/ ) { + my $payby = ''; + if (exists($p->{'payby'})) { + $p->{'payby'} =~ /^([A-Z]{4})$/ + or return { 'error' => "illegal_payby " . $p->{'payby'} }; + $payby = $1; + } + + if ( $payby =~ /^(CARD|DCRD)$/ ) { + $new->paydate($p->{'year'}. '-'. $p->{'month'}. '-01'); + if ( $new->payinfo eq $cust_main->paymask ) { $new->payinfo($cust_main->payinfo); } else { - $new->paycvv($p->{'paycvv'}); + $new->payinfo($p->{'payinfo'}); } + + $new->set( 'payby' => $p->{'auto'} ? 'CARD' : 'DCRD' ); + + }elsif ( $payby =~ /^(CHEK|DCHK)$/ ) { + my $payinfo; + $p->{'payinfo1'} =~ /^([\dx]+)$/ + or return { 'error' => "illegal account number ". $p->{'payinfo1'} }; + my $payinfo1 = $1; + $p->{'payinfo2'} =~ /^([\dx]+)$/ + or return { 'error' => "illegal ABA/routing number ". $p->{'payinfo2'} }; + my $payinfo2 = $1; + $payinfo = $payinfo1. '@'. $payinfo2; + + if ( $payinfo eq $cust_main->paymask ) { + $new->payinfo($cust_main->payinfo); + } else { + $new->payinfo($payinfo); + } + + $new->set( 'payby' => $p->{'auto'} ? 'CHEK' : 'DCHK' ); + + }elsif ( $payby =~ /^(BILL)$/ ) { + } elsif ( $payby ) { #notyet ready + return { 'error' => "unknown payby $payby" }; } my @invoicing_list; @@ -265,6 +332,8 @@ sub payment_info { 'paytypes' => [ @FS::cust_main::paytypes ], + 'paybys' => [ $conf->config('signup_server-payby') ], + 'stateid_label' => FS::Msgcat::_gettext('stateid'), 'stateid_state_label' => FS::Msgcat::_gettext('stateid_state'), @@ -793,6 +862,7 @@ sub order_pkg { my $cust_main = qsearchs('cust_main', $search ) or return { 'error' => "unknown custnum $custnum" }; + my $status = $cust_main->status; #false laziness w/ClientAPI/Signup.pm my $cust_pkg = new FS::cust_pkg ( { @@ -864,7 +934,7 @@ sub order_pkg { my $conf = new FS::Conf; if ( $conf->exists('signup_server-realtime') ) { - my $bill_error = _do_bop_realtime( $cust_main ); + my $bill_error = _do_bop_realtime( $cust_main, $status ); if ($bill_error) { $cust_pkg->cancel('quiet'=>1); @@ -892,6 +962,7 @@ sub change_pkg { my $cust_main = qsearchs('cust_main', $search ) or return { 'error' => "unknown custnum $custnum" }; + my $status = $cust_main->status; my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $p->{pkgnum} } ) or return { 'error' => "unknown package $p->{pkgnum}" }; @@ -905,7 +976,7 @@ sub change_pkg { my $conf = new FS::Conf; if ( $conf->exists('signup_server-realtime') ) { - my $bill_error = _do_bop_realtime( $cust_main ); + my $bill_error = _do_bop_realtime( $cust_main, $status ); if ($bill_error) { $newpkg[0]->suspend; @@ -933,6 +1004,7 @@ sub order_recharge { my $cust_main = qsearchs('cust_main', $search ) or return { 'error' => "unknown custnum $custnum" }; + my $status = $cust_main->status; my $cust_svc = qsearchs( 'cust_svc', { 'svcnum' => $p->{'svcnum'} } ) or return { 'error' => "unknown service " . $p->{'svcnum'} }; @@ -956,7 +1028,7 @@ sub order_recharge { my $conf = new FS::Conf; if ( $conf->exists('signup_server-realtime') && !$bill_error ) { - $bill_error = _do_bop_realtime( $cust_main ); + $bill_error = _do_bop_realtime( $cust_main, $status ); if ($bill_error) { return $bill_error; @@ -976,7 +1048,7 @@ sub order_recharge { } sub _do_bop_realtime { - my ($cust_main) = @_; + my ($cust_main, $status) = (shift, shift); my $old_balance = $cust_main->balance; @@ -986,10 +1058,14 @@ sub _do_bop_realtime { if ( $cust_main->balance > $old_balance && $cust_main->balance > 0 - && $cust_main->payby !~ /^(BILL|DCRD|DCHK)$/ ) { + && ( $cust_main->payby !~ /^(BILL|DCRD|DCHK)$/ ? + 1 : $status eq 'suspended' ) ) { #this makes sense. credit is "un-doing" the invoice + my $conf = new FS::Conf; $cust_main->credit( sprintf("%.2f", $cust_main->balance - $old_balance ), - 'self-service decline' ); + 'self-service decline', + 'reason_type' => $conf->config('signup_credit_type'), + ); $cust_main->apply_credits( 'order' => 'newest' ); return { 'error' => '_decline', 'bill_error' => $bill_error }; @@ -1026,10 +1102,17 @@ sub provision_acct { if $p->{'_password'} ne $p->{'_password2'}; return { 'error' => gettext('empty_password') } unless length($p->{'_password'}); + + if ($p->{'domsvc'}) { + my %domains = domain_select_hash FS::svc_acct(map { $_ => $p->{$_} } + qw ( svcpart pkgnum ) ); + return { 'error' => gettext('invalid_domain') } + unless ($domains{$p->{'domsvc'}}); + } _provision( 'FS::svc_acct', - [qw(username _password)], - [qw(username _password)], + [qw(username _password domsvc)], + [qw(username _password domsvc)], $p, @_ );