- send a notice to the customer when their card is declined - closes: Bug#351
authorivan <ivan>
Tue, 16 Apr 2002 09:38:20 +0000 (09:38 +0000)
committerivan <ivan>
Tue, 16 Apr 2002 09:38:20 +0000 (09:38 +0000)
- freeside-expiration-alerter works fine, closes: Bug#7

FS/FS/Conf.pm
FS/FS/cust_bill.pm
FS/bin/freeside-expiration-alerter
conf/declinetemplate [new file with mode: 0644]
httemplate/docs/billing.html

index f9a49ca..dc1cbb8 100644 (file)
@@ -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',
+  },
 
 );
 
index f157f86..cb2aa46 100644 (file)
@@ -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
 
index 365b964..ee3c1fb 100755 (executable)
@@ -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 (file)
index 0000000..9a356ea
--- /dev/null
@@ -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.
+
index c6ef7a8..c78a87f 100644 (file)
@@ -7,6 +7,8 @@
     <li>You can bill individual customers by clicking on the <i>Bill now</i> link on the main customer view.
     <li>The <a href="man/bin/freeside-daily.html"><b>freeside-daily</b></a> script should be run daily to bill customers and run invoice collection events.
     <li>Real-time credit card processing: Install the <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> module for your processor.  Configure the <a href="../config/config-view.cgi#business-onlinepayment">business-onlinepayment</a> configuration option.  Disable the default <b>Batch card</b> <a href="../browse/part_bill_event.cgi">invoice event</a> and add one for Business::OnlinePayment.
+    <li>Optional: Credit card expiration alerts: Customize <a href="../config/config.cgi#alerter_template">alerter_template</a> configuration option and run <a href="man/bin/freeside-expiration-alerter.html">freeside-expiration-alerter</a> daily.
+    <li>Credit card decline alerts: Customize the <a href="../config/config.cgi#declinetemplate">declinetemplate</a> configuration option and set the <a href="../config/config.cgi#emaildecline">emaildecline</a> configuration option.
     <li>Optional: Invoice template customization
       <ul>
         <li>See the <a href="http://search.cpan.org/doc/MJD/Text-Template-1.42/Template.pm">Text::Template</a> documentation for details on the substitution language.