X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_bill.pm;h=20755857bfdb4e40250e9c5019af47df0ce0b438;hp=0a8d4a4ae6d48fdff7fd5b16f2ada1568ad3a694;hb=0ada85923cfb057caf1d0e66b73a08b2700703bd;hpb=d65d05b7aaa329fb6005fb7ed4a24daab4fa7941 diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 0a8d4a4ae..20755857b 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -8,7 +8,7 @@ use vars qw( $xaction $E_NoErr ); use vars qw( $bop_processor $bop_login $bop_password $bop_action @bop_options ); use vars qw( $invoice_lines @buf ); #yuck use Date::Format; -use Mail::Internet; +use Mail::Internet 1.44; use Mail::Header; use Text::Template; use FS::Record qw( qsearch qsearchs ); @@ -373,7 +373,7 @@ sub send { #my @print_text = $cust_bill->print_text; #( date ) my @invoicing_list = $self->cust_main->invoicing_list; if ( grep { $_ ne 'POST' } @invoicing_list ) { #email invoice - #false laziness w/FS::cust_pay::delete + #false laziness w/FS::cust_pay::delete & fs_signup_server && ::realtime_card #$ENV{SMTPHOSTS} = $smtpmachine; $ENV{MAILADDRESS} = $invoice_from; my $header = new Mail::Header ( [ @@ -458,7 +458,7 @@ sub realtime_card { my($payname, $payfirst, $paylast); if ( $cust_main->payname ) { $payname = $cust_main->payname; - $payname =~ /^\s*([\w \,\.\-\']*)?\s+([\w\,\.\-\']+)$/ + $payname =~ /^\s*([\w \,\.\-\']*)?\s+([\w\,\.\-\']+)\s*$/ or do { #$dbh->rollback if $oldAutoCommit; return "Illegal payname $payname"; @@ -466,7 +466,7 @@ sub realtime_card { ($payfirst, $paylast) = ($1, $2); } else { $payfirst = $cust_main->getfield('first'); - $paylast = $cust_main->getfield('first'); + $paylast = $cust_main->getfield('last'); $payname = "$payfirst $paylast"; } @@ -478,6 +478,22 @@ sub realtime_card { my $email = $invoicing_list[0]; my( $action1, $action2 ) = split(/\s*\,\s*/, $bop_action ); + + my $description = 'Internet Services'; + if ( $conf->exists('business-onlinepayment-description') ) { + my $dtempl = $conf->config('business-onlinepayment-description'); + + my $agent_obj = $cust_main->agent + or die "can't retreive agent for $cust_main (agentnum ". + $cust_main->agentnum. ")"; + my $agent = $agent_obj->agent; + my $pkgs = join(', ', + map { $_->cust_pkg->part_pkg->pkg } + grep { $_->pkgnum } $self->cust_bill_pkg + ); + $description = eval qq("$dtempl"); + + } my $transaction = new Business::OnlinePayment( $bop_processor, @bop_options ); @@ -486,7 +502,7 @@ sub realtime_card { 'login' => $bop_login, 'password' => $bop_password, 'action' => $action1, - 'description' => 'Internet Services', + 'description' => $description, 'amount' => $amount, 'invoice_number' => $self->invnum, 'customer_id' => $self->custnum, @@ -502,12 +518,14 @@ sub realtime_card { 'expiration' => $exp, 'referer' => 'http://cleanwhisker.420.am/', 'email' => $email, + 'phone' => $cust_main->daytime || $cust_main->night, ); $transaction->submit(); if ( $transaction->is_success() && $action2 ) { my $auth = $transaction->authorization; my $ordernum = $transaction->order_number; + #warn "********* $auth ***********\n"; #warn "********* $ordernum ***********\n"; my $capture = @@ -520,7 +538,7 @@ sub realtime_card { order_number => $ordernum, amount => $amount, authorization => $auth, - description => 'Internet Services', + description => $description, ); $capture->submit(); @@ -558,8 +576,47 @@ sub realtime_card { } #} elsif ( $options{'report_badcard'} ) { } else { - return "$processor error, invnum #". $self->invnum. ': '. - $transaction->result_code. ": ". $transaction->error_message; + + my $perror = "$processor error, invnum #". $self->invnum. ': '. + $transaction->result_code. ": ". $transaction->error_message; + + if ( $conf->exists('emaildecline') + && grep { $_ ne 'POST' } $cust_main->invoicing_list + ) { + my @templ = $conf->config('declinetemplate'); + my $template = new Text::Template ( + TYPE => 'ARRAY', + SOURCE => [ map "$_\n", @templ ], + ) or return "($perror) can't create template: $Text::Template::ERROR"; + $template->compile() + or return "($perror) can't compile template: $Text::Template::ERROR"; + + my $templ_hash = { error => $transaction->error_message }; + + #false laziness w/FS::cust_pay::delete & fs_signup_server && ::send + $ENV{MAILADDRESS} = $invoice_from; + my $header = new Mail::Header ( [ + "From: $invoice_from", + "To: ". join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list ), + "Sender: $invoice_from", + "Reply-To: $invoice_from", + "Date: ". time2str("%a, %d %b %Y %X %z", time), + "Subject: Your credit card could not be processed", + ] ); + my $message = new Mail::Internet ( + 'Header' => $header, + 'Body' => [ $template->fill_in(HASH => $templ_hash) ], + ); + $!=0; + $message->smtpsend( Host => $smtpmachine ) + or $message->smtpsend( Host => $smtpmachine, Debug => 1 ) + or return "($perror) (customer # ". $self->custnum. + ") can't send card decline email to ". + join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list ). + " via server $smtpmachine with SMTP: $!"; + } + + return $perror; } } @@ -670,8 +727,10 @@ sub batch_card { 'payname' => $cust_main->getfield('payname'), 'amount' => $self->owed, } ); - $cust_pay_batch->insert; + my $error = $cust_pay_batch->insert; + die $error if $error; + ''; } =item print_text [TIME]; @@ -802,11 +861,13 @@ sub print_text { my @invoice_template = $conf->config($templatefile) or die "cannot load config file $templatefile"; $invoice_lines = 0; + my $wasfunc = 0; foreach ( grep /invoice_lines\(\d+\)/, @invoice_template ) { #kludgy /invoice_lines\((\d+)\)/; $invoice_lines += $1; + $wasfunc=1; } - die "no invoice_lines() functions in template?" unless $invoice_lines; + die "no invoice_lines() functions in template?" unless $wasfunc; my $invoice_template = new Text::Template ( TYPE => 'ARRAY', SOURCE => [ map "$_\n", @invoice_template ], @@ -822,11 +883,14 @@ sub print_text { $date = $self->_date; $page = 1; - $total_pages = - int( scalar(@FS::cust_bill::buf) / $FS::cust_bill::invoice_lines ); - $total_pages++ - if scalar(@FS::cust_bill::buf) % $FS::cust_bill::invoice_lines; - + if ( $FS::cust_bill::invoice_lines ) { + $total_pages = + int( scalar(@FS::cust_bill::buf) / $FS::cust_bill::invoice_lines ); + $total_pages++ + if scalar(@FS::cust_bill::buf) % $FS::cust_bill::invoice_lines; + } else { + $total_pages = 1; + } #format address (variable for the template) my $l = 0; @@ -860,7 +924,7 @@ sub print_text { #and subroutine for the template sub FS::cust_bill::_template::invoice_lines { - my $lines = shift; + my $lines = shift or return @buf; map { scalar(@buf) ? shift @buf : [ '', '' ]; } @@ -887,7 +951,7 @@ sub print_text { =head1 VERSION -$Id: cust_bill.pm,v 1.24 2002-03-18 21:40:17 ivan Exp $ +$Id: cust_bill.pm,v 1.37 2002-06-07 20:33:27 khoff Exp $ =head1 BUGS