From 17ddcceb66e4c5c45abe890403d2ca98b128d375 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 16 Apr 2002 09:38:20 +0000 Subject: [PATCH] - send a notice to the customer when their card is declined - closes: Bug#351 - freeside-expiration-alerter works fine, closes: Bug#7 --- FS/FS/Conf.pm | 12 ++++++++++ FS/FS/cust_bill.pm | 47 ++++++++++++++++++++++++++++++++++---- FS/bin/freeside-expiration-alerter | 9 ++++---- conf/declinetemplate | 10 ++++++++ httemplate/docs/billing.html | 2 ++ 5 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 conf/declinetemplate diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index f9a49ca04..dc1cbb820 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -895,7 +895,19 @@ httemplate/docs/config.html 'type' => 'checkbox', }, + { + 'key' => 'declinetemplate' + 'section' => 'billing', + 'description' => 'Template file for credit card decline emails.', + 'type' => 'textarea', + }, + { + 'key' => 'emaildecline' + 'section' => 'billing', + 'description' => 'Enable emailing of credit card decline notices.', + 'type' => 'checkbox', + }, ); diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index f157f86f6..cb2aa4629 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -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 & fs_signup_server + #false laziness w/FS::cust_pay::delete & fs_signup_server && ::realtime_card #$ENV{SMTPHOSTS} = $smtpmachine; $ENV{MAILADDRESS} = $invoice_from; my $header = new Mail::Header ( [ @@ -571,8 +571,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 die "($perror) can't create template: $Text::Template::ERROR"; + $template->compile() + or die "($perror) can't compile template: $Text::Template::ERROR"; + + my $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() ], + ); + $!=0; + $message->smtpsend( Host => $smtpmachine ) + or $message->smtpsend( Host => $smtpmachine, Debug => 1 ) + or die "($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; } } @@ -905,7 +944,7 @@ sub print_text { =head1 VERSION -$Id: cust_bill.pm,v 1.27 2002-04-13 09:14:07 ivan Exp $ +$Id: cust_bill.pm,v 1.28 2002-04-16 09:38:19 ivan Exp $ =head1 BUGS diff --git a/FS/bin/freeside-expiration-alerter b/FS/bin/freeside-expiration-alerter index 365b96467..ee3c1fb92 100755 --- a/FS/bin/freeside-expiration-alerter +++ b/FS/bin/freeside-expiration-alerter @@ -142,7 +142,8 @@ foreach my $customer (@customers) ); $!=0; $message->smtpsend( Host => $smtpmachine ) - or die "Can't send expiration email!: $!"; #die? warn? + or $message->smtpsend( Host => $smtpmachine, Debug => 1 ) + or die "Can't send expiration email: $!"; } elsif ( ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list ) { push @body, sprintf(qq{%5d %-32.32s %4s %10s %12s %12s}, @@ -166,8 +167,8 @@ if (scalar(@body)) { $!=0; $message->smtpsend( Host => $smtpmachine ) or $message->smtpsend( Host => $smtpmachine, Debug => 1 ) - or return "can't send alerter failure email to $failure_recipient". - " via server $smtpmachine with SMTP: $!"; + or die "can't send alerter failure email to $failure_recipient". + " via server $smtpmachine with SMTP: $!"; } # subroutines @@ -199,7 +200,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-expiration-alerter,v 1.2 2002-03-07 19:50:24 jeff Exp $ +$Id: freeside-expiration-alerter,v 1.3 2002-04-16 09:38:19 ivan Exp $ =head1 BUGS diff --git a/conf/declinetemplate b/conf/declinetemplate new file mode 100644 index 000000000..9a356ea0f --- /dev/null +++ b/conf/declinetemplate @@ -0,0 +1,10 @@ +Hi, + +Your credit card could not be processed for the following reason: + { $error } + +Please provide us with new billing infromation so that we may continue your +service uninterrupted. + +Thanks. + diff --git a/httemplate/docs/billing.html b/httemplate/docs/billing.html index c6ef7a869..c78a87f04 100644 --- a/httemplate/docs/billing.html +++ b/httemplate/docs/billing.html @@ -7,6 +7,8 @@
  • You can bill individual customers by clicking on the Bill now link on the main customer view.
  • The freeside-daily script should be run daily to bill customers and run invoice collection events.
  • Real-time credit card processing: Install the Business::OnlinePayment module for your processor. Configure the business-onlinepayment configuration option. Disable the default Batch card invoice event and add one for Business::OnlinePayment. +
  • Optional: Credit card expiration alerts: Customize alerter_template configuration option and run freeside-expiration-alerter daily. +
  • Credit card decline alerts: Customize the declinetemplate configuration option and set the emaildecline configuration option.
  • Optional: Invoice template customization