my $p = shift;
my $conf = new FS::Conf;
-
my $svc_x = '';
my $session = {};
+
if ( $p->{'domain'} eq 'svc_phone'
&& $conf->exists('selfservice_server-phone_login') ) {
$svc_x = $svc_phone;
} elsif ( $p->{email}
- && (my $contact = FS::contact->by_selfservice_email($p->{email}))
+ && (my $contact = FS::contact->by_selfservice_email($p->{email},'case_insensitive'))
)
{
+ my @customers = grep $_->selfservice_access, $contact->cust_contact;
+ my @cust_contact;
+
+ foreach my $customer (@customers) {
+ if ($conf->exists('username-uppercase') || $conf->exists('username-uppercase', $customer->cust_main->agentnum)) {
+ my $check_contact = FS::contact->by_selfservice_email_custnum($p->{email}, $customer->custnum);
+ push @cust_contact, $customer if $check_contact;
+ }
+ else { push @cust_contact, $customer; }
+ }
+
+ return { error => 'Username '.$p->{email}.' not found!'}
+ unless @cust_contact;
+
return { error => 'Incorrect contact password.' }
unless $contact->authenticate_password($p->{'password'});
$session->{'contactnum'} = $contact->contactnum;
- my @cust_contact = grep $_->selfservice_access, $contact->cust_contact;
if ( scalar(@cust_contact) == 1 ) {
$session->{'custnum'} = $cust_contact[0]->custnum;
} elsif ( scalar(@cust_contact) ) {
## get default cust_payby and change it. For old v3 selfservice that upgraded to v4. this is for v4 only
my ($cust_payby) = $cust_main->cust_payby();
- $p->{'custpaybynum'} = $cust_payby->custpaybynum;
- update_payby($p);
+ if ($cust_payby) {
+ $p->{'custpaybynum'} = $cust_payby->custpaybynum;
+ update_payby($p);
+ }
+ else {
+ insert_payby($p);
+ }
}
my $new = new FS::cust_main { $cust_main->hash };
$return{credit_card_surcharge_percentage} = $conf->config('credit-card-surcharge-percentage', $cust_main->agentnum);
$return{credit_card_surcharge_flatfee} = $conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum);
+ # A value for 'payby' must be defined in %return
+ $return{payby} = $return{paybys}->[0]
+ if !$return{payby}
+ && ref $return{paybys}
+ && scalar @{ $return{paybys} };
+
return { 'error' => '',
%return,
};
my $payinfo2 = $1;
$p->{'payinfo'} = $payinfo1. '@'. $payinfo2;
}
+ elsif ($p->{'payby'} eq 'CARD') {
+ $p->{paydate} = $p->{year} . '-' . $p->{month} . '-01' unless $p->{paydate};
+ }
my $cust_payby = new FS::cust_payby {
'custnum' => $custnum,
$p->{paydate} = $p->{year} . '-' . $p->{month} . '-01' unless $p->{paydate};
}
- # Perform update within a transaction
- local $FS::UID::AutoCommit = 0;
-
my $cust_payby = qsearchs('cust_payby', {
'custnum' => $custnum,
'custpaybynum' => $p->{'custpaybynum'},
$cust_payby->set($field,$p->{$field});
}
- my $error = $cust_payby->replace;
+ # Update column if given a value, and the given value wasn't
+ # the value generated by $cust_main->masked($column);
+ $cust_main->set( $_, $p->{$_} )
+ for grep{ $p->{$_} !~ /^x/i; }
+ grep{ exists $p->{$_} }
+ qw/ss stateid/;
- if (!$error) {
- my $is_changed = 0;
- for my $field ( qw/ss stateid/ ) {
- next if !exists $p->{$field} || $p->{$field} =~ /^x/i;
- $cust_main->set( $field, $p->{$field} );
- $is_changed = 1;
- }
- $error = $cust_main->replace if $is_changed;
- }
+ # Perform updates within a transaction
+ local $FS::UID::AutoCommit = 0;
- if ( $error ) {
+ if ( my $error = $cust_payby->replace || $cust_main->replace ) {
dbh->rollback;
- return { 'error' => $error };
- } else {
- dbh->commit;
- return { 'custpaybynum' => $cust_payby->custpaybynum };
+ return { error => $error };
}
-
+
+ dbh->commit;
+ return { custpaybynum => $cust_payby->custpaybynum };
}
sub verify_payby {
my $cust_main = '';
if ( $p->{'email'} ) { #new-style, changes contact and svc_acct
- $contact = FS::contact->by_selfservice_email($p->{'email'});
+ $contact = FS::contact->by_selfservice_email($p->{'email'}, 'case_insensitive');
- if ( $contact ) {
- my @cust_contact = grep $_->selfservice_access, $contact->cust_contact;
- $cust_main = $cust_contact[0]->cust_main if scalar(@cust_contact) == 1;
+ my @customers = grep $_->selfservice_access, $contact->cust_contact;
+ my @cust_contact;
+
+ foreach my $customer (@customers) {
+ if ($conf->exists('username-uppercase') || $conf->exists('username-uppercase', $customer->cust_main->agentnum)) {
+ my $check_contact = FS::contact->by_selfservice_email_custnum($p->{email}, $customer->custnum);
+ push @cust_contact, $customer if $check_contact;
+ }
+ else { push @cust_contact, $customer; }
}
+ $contact = '' unless @cust_contact;
+ $cust_main = $cust_contact[0]->cust_main if scalar(@cust_contact) == 1;
+
#also look for an svc_acct, otherwise it would be super confusing
my($username, $domain) = split('@', $p->{'email'});