X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FSignup.pm;h=5407a8fa665bcf942a08fbe2e04416d22b175826;hb=e18442a0b77e7ef55d51f369eabba19848d19a08;hp=593c426b59e3ff351939ea1fc738fe588f38eaef;hpb=4ed0a352b2319c2fc14ee7af09a21caf727e7b12;p=freeside.git diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm index 593c426b5..5407a8fa6 100644 --- a/FS/FS/ClientAPI/Signup.pm +++ b/FS/FS/ClientAPI/Signup.pm @@ -4,6 +4,7 @@ use strict; use vars qw( $DEBUG $me ); use Data::Dumper; use Tie::RefHash; +use Digest::SHA qw(sha512_hex); use FS::Conf; use FS::Record qw(qsearch qsearchs dbdef); use FS::CGI qw(popurl); @@ -174,6 +175,7 @@ sub signup_info { 'card_types' => card_types(), 'paytypes' => [ @FS::cust_main::paytypes ], 'cvv_enabled' => 1, + 'require_cvv' => $conf->exists('signup-require_cvv'), 'stateid_enabled' => $conf->exists('show_stateid'), 'paystate_enabled' => $conf->exists('show_bankstate'), 'ship_enabled' => 1, @@ -530,7 +532,7 @@ sub new_customer { || $conf->config('signup_server-default_refnum'), ( map { $_ => $template_cust->$_ } qw( - last first company daytime night fax + last first company daytime night fax mobile ) ), @@ -561,7 +563,8 @@ sub new_customer { map { $_ => $packet->{$_} } qw( last first ss company - daytime night fax stateid stateid_state + daytime night fax mobile + stateid stateid_state payby payinfo paycvv paydate payname paystate paytype paystart_month paystart_year payissue @@ -631,6 +634,11 @@ sub new_customer { if $gw && $gw->gateway_namespace eq 'Business::OnlineThirdPartyPayment'; } + return { 'error' => "CVV2 is required" } + if $cust_main->payby =~ /^(CARD|DCRD)$/ + && ! $cust_main->paycvv + && $conf->exists('signup-require_cvv'); + $cust_main->payinfo($cust_main->daytime) if $cust_main->payby eq 'LECB' && ! $cust_main->payinfo; @@ -872,6 +880,7 @@ sub new_customer { #false laziness w/ above # fresh restart to support "free account" portals with 3.x/4.x-style # addressless accounts +# and a contact (for self-service login) sub new_customer_minimal { my $packet = shift; @@ -922,7 +931,7 @@ sub new_customer_minimal { map { $_ => $packet->{$_} } qw( last first ss company - daytime night fax + daytime night fax mobile ), } ); @@ -931,74 +940,103 @@ sub new_customer_minimal { ? split( /\s*\,\s*/, $packet->{'invoicing_list'} ) : (); + use Tie::RefHash; + tie my %hash, 'Tie::RefHash', (); + my @svc = (); + $packet->{'pkgpart'} =~ /^(\d+)$/ or '' =~ /^()$/; my $pkgpart = $1; - return { 'error' => 'Please select a package' } unless $pkgpart; #msgcat - my $part_pkg = - qsearchs( 'part_pkg', { 'pkgpart' => $pkgpart } ) - or return { 'error' => "WARNING: unknown pkgpart: $pkgpart" }; - my $svcpart = $part_pkg->svcpart($svc_x); + if ( $pkgpart ) { - my $cust_pkg = new FS::cust_pkg ( { - #later#'custnum' => $custnum, - 'pkgpart' => $packet->{'pkgpart'}, - } ); - #my $error = $cust_pkg->check; - #return { 'error' => $error } if $error; - - #should be all auto-magic and shit - my @svc = (); - if ( $svc_x eq 'svc_acct' ) { + my $part_pkg = + qsearchs( 'part_pkg', { 'pkgpart' => $pkgpart } ) + or return { 'error' => "WARNING: unknown pkgpart: $pkgpart" }; + my $svcpart = $part_pkg->svcpart($svc_x); - my $svc = new FS::svc_acct { - 'svcpart' => $svcpart, - map { $_ => $packet->{$_} } - qw( username _password sec_phrase popnum domsvc ), - }; + my $cust_pkg = new FS::cust_pkg ( { + #later#'custnum' => $custnum, + 'pkgpart' => $packet->{'pkgpart'}, + } ); + #my $error = $cust_pkg->check; + #return { 'error' => $error } if $error; - push @svc, $svc; + #should be all auto-magic and shit + if ( $svc_x eq 'svc_acct' ) { - } elsif ( $svc_x eq 'svc_phone' ) { + my $svc = new FS::svc_acct { + 'svcpart' => $svcpart, + map { $_ => $packet->{$_} } + qw( username _password sec_phrase popnum domsvc ), + }; - push @svc, new FS::svc_phone ( { - 'svcpart' => $svcpart, - map { $_ => $packet->{$_} } - qw( countrycode phonenum sip_password pin ), - } ); + push @svc, $svc; - } elsif ( $svc_x eq 'svc_pbx' ) { + } elsif ( $svc_x eq 'svc_phone' ) { - push @svc, new FS::svc_pbx ( { + push @svc, new FS::svc_phone ( { 'svcpart' => $svcpart, - map { $_ => $packet->{$_} } - qw( id title ), - } ); - - } else { - die "unknown signup service $svc_x"; + map { $_ => $packet->{$_} } + qw( countrycode phonenum sip_password pin ), + } ); + + } elsif ( $svc_x eq 'svc_pbx' ) { + + push @svc, new FS::svc_pbx ( { + 'svcpart' => $svcpart, + map { $_ => $packet->{$_} } + qw( id title ), + } ); + + } else { + die "unknown signup service $svc_x"; + } + + foreach my $svc ( @svc ) { + my $y = $svc->setdefault; # arguably should be in new method + return { 'error' => $y } if $y && !ref($y); + #$error = $svc->check; + #return { 'error' => $error } if $error; + } + + use Tie::RefHash; + tie my %hash, 'Tie::RefHash'; + $hash{ $cust_pkg } = \@svc; + } - foreach my $svc ( @svc ) { - my $y = $svc->setdefault; # arguably should be in new method - return { 'error' => $y } if $y && !ref($y); - #$error = $svc->check; - #return { 'error' => $error } if $error; + my %opt = (); + if ( $invoicing_list[0] && $packet->{'_password'} ) { + $opt{'contact'} = [ + new FS::contact { 'first' => $cust_main->first, + 'last' => $cust_main->get('last'), + '_password' => $packet->{'_password'}, + 'emailaddress' => $invoicing_list[0], + 'selfservice_access' => 'Y', + } + ]; } - use Tie::RefHash; - tie my %hash, 'Tie::RefHash'; - %hash = ( $cust_pkg => \@svc ); - #msgcat my $error = $cust_main->insert( \%hash, \@invoicing_list, + %opt, ); return { 'error' => $error } if $error; + my $session = { 'custnum' => $cust_main->custnum }; + + my $session_id; + do { + $session_id = sha1_hex(time(). {}. rand(). $$) + } until ( ! defined _myaccount_cache->get($session_id) ); #just in case + + _cache->set( $session_id, $session, '1 hour' ); # 1 hour? + my %return = ( 'error' => '', 'signup_service' => $svc_x, 'custnum' => $cust_main->custnum, + 'session_id' => $session_id, ); if ( $svc[0] ) { @@ -1023,6 +1061,13 @@ sub new_customer_minimal { } +use vars qw( $myaccount_cache ); +sub _myaccount_cache { + $myaccount_cache ||= new FS::ClientAPI_SessionCache( { + 'namespace' => 'FS::ClientAPI::MyAccount', + } ); +} + sub capture_payment { my $packet = shift;