X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main.pm;h=32bf2a333b858944fe6ebf383e5e36cc940691dc;hp=41b2743208e483b8d5944ee2199ad0011b190d13;hb=00f903db5078b4137495a3fb6b650890ce92fb5c;hpb=eb1796299a429ba5cd3b939a65bf5e95abf0086c diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 41b274320..32bf2a333 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -542,6 +542,16 @@ sub insert { } + # validate card (needs custnum already set) + if ( $self->payby =~ /^(CARD|DCRD)$/ + && $conf->exists('business-onlinepayment-verification') ) { + $error = $self->realtime_verify_bop({ 'method'=>'CC' }); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + warn " setting contacts\n" if $DEBUG > 1; @@ -1538,6 +1548,25 @@ sub replace { { my $error = $self->check_payinfo_cardtype; return $error if $error; + + if ( $conf->exists('business-onlinepayment-verification') ) { + #need to standardize paydate for this, false laziness with check + my( $m, $y ); + if ( $self->paydate =~ /^(\d{1,2})[\/\-](\d{2}(\d{2})?)$/ ) { + ( $m, $y ) = ( $1, length($2) == 4 ? $2 : "20$2" ); + } elsif ( $self->paydate =~ /^19(\d{2})[\/\-](\d{1,2})[\/\-]\d+$/ ) { + ( $m, $y ) = ( $2, "19$1" ); + } elsif ( $self->paydate =~ /^(20)?(\d{2})[\/\-](\d{1,2})[\/\-]\d+$/ ) { + ( $m, $y ) = ( $3, "20$2" ); + } else { + return "Illegal expiration date: ". $self->paydate; + } + $m = sprintf('%02d',$m); + $self->paydate("$y-$m-01"); + + $error = $self->realtime_verify_bop({ 'method'=>'CC' }); + return $error if $error; + } } return "Invoicing locale is required" @@ -2358,6 +2387,9 @@ Always returns a list: an empty list on success or a list of errors. sub cancel { my( $self, %opt ) = @_; + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + warn "$me cancel called on customer ". $self->custnum. " with options ". join(', ', map { "$_: $opt{$_}" } keys %opt ). "\n" if $DEBUG; @@ -2374,24 +2406,63 @@ sub cancel { my $ban = new FS::banned_pay $self->_new_banned_pay_hashref; my $error = $ban->insert; - return ( $error ) if $error; + if ($error) { + dbh->rollback if $oldAutoCommit; + return ( $error ); + } } my @pkgs = $self->ncancelled_pkgs; + # bill all packages first, so we don't lose usage, service counts for + # bulk billing, etc. if ( !$opt{nobill} && $conf->exists('bill_usage_on_cancel') ) { $opt{nobill} = 1; my $error = $self->bill( pkg_list => [ @pkgs ], cancel => 1 ); - warn "Error billing during cancel, custnum ". $self->custnum. ": $error" - if $error; + if ($error) { + # we should return an error and exit in this case, yes? + warn "Error billing during cancel, custnum ". $self->custnum. ": $error"; + dbh->rollback if $oldAutoCommit; + return ( "Error billing during cancellation: $error" ); + } + } + + my @errors; + # now cancel all services, the same way we would for individual packages + my @cust_svc = map { $_->cust_svc } @pkgs; + my @sorted_cust_svc = + map { $_->[0] } + sort { $a->[1] <=> $b->[1] } + map { [ $_, $_->svc_x ? $_->svc_x->table_info->{'cancel_weight'} : -1 ]; } + @cust_svc + ; + warn "$me removing ".scalar(@sorted_cust_svc)." service(s) for customer ". + $self->custnum."\n" + if $DEBUG; + foreach my $cust_svc (@sorted_cust_svc) { + my $part_svc = $cust_svc->part_svc; + next if ( defined($part_svc) and $part_svc->preserve ); + my $error = $cust_svc->cancel; # immediate cancel, no date option + push @errors, $error if $error; + } + if (@errors) { + # then we won't get to the point of canceling packages + dbh->rollback if $oldAutoCommit; + return @errors; } - warn "$me cancelling ". scalar($self->ncancelled_pkgs). "/". - scalar(@pkgs). " packages for customer ". $self->custnum. "\n" + warn "$me cancelling ". scalar(@pkgs) ." package(s) for customer ". + $self->custnum. "\n" if $DEBUG; - grep { $_ } map { $_->cancel(%opt) } $self->ncancelled_pkgs; + @errors = grep { $_ } map { $_->cancel(%opt) } @pkgs; + if (@errors) { + dbh->rollback if $oldAutoCommit; + return @errors; + } + + return; } sub _banned_pay_hashref {