error message in decline templates, RT#9507
authormark <mark>
Thu, 5 Aug 2010 00:24:57 +0000 (00:24 +0000)
committermark <mark>
Thu, 5 Aug 2010 00:24:57 +0000 (00:24 +0000)
FS/FS/cust_main.pm
FS/FS/msg_template.pm
httemplate/edit/msg_template.html

index b1bf179..5898a6a 100644 (file)
@@ -5116,8 +5116,11 @@ sub _realtime_bop_result {
       my $msgnum = $conf->config('decline_msgnum', $self->agentnum);
       my $error = '';
       if ( $msgnum ) {
+        # include the raw error message in the transaction state
+        $cust_pay_pending->setfield('error', $transaction->error_message);
         my $msg_template = qsearchs('msg_template', { msgnum => $msgnum });
-        $error = $msg_template->send( 'cust_main' => $self );
+        $error = $msg_template->send( 'cust_main' => $self,
+                                      'object'    => $cust_pay_pending );
       }
       else { #!$msgnum
 
index 7d507f4..d1db17d 100644 (file)
@@ -166,7 +166,7 @@ Customer object (required).
 =item object
 
 Additional context object (currently, can be a cust_main, cust_pkg, 
-cust_bill, svc_acct, or cust_pay object).
+cust_bill, svc_acct, cust_pay, or cust_pay_pending object).
 
 =back
 
@@ -324,6 +324,9 @@ sub substitutions {
       [ company_name      => sub { 
           $conf->config('company_name', shift->agentnum) 
         } ],
+      [ company_address   => sub {
+          $conf->config('company_address', shift->agentnum)
+        } ],
     ],
     # next_bill_date
     'cust_pkg'  => [qw( 
@@ -351,11 +354,13 @@ sub substitutions {
     )],
     #XXX not really thinking about cust_bill substitutions quite yet
     
+    # for welcome and limit warning messages
     'svc_acct' => [qw(
       username
       ),
       [ password          => sub { shift->getfield('_password') } ],
-    ], # for welcome messages
+    ],
+    # for payment receipts
     'cust_pay' => [qw(
       paynum
       _date
@@ -370,6 +375,22 @@ sub substitutions {
             $cust_pay->paymask : $cust_pay->decrypt($cust_pay->payinfo)
         } ],
     ],
+    # for payment decline messages
+    # try to support all cust_pay fields
+    # 'error' is a special case, it contains the raw error from the gateway
+    'cust_pay_pending' => [qw(
+      _date
+      error
+      ),
+      [ paid              => sub { sprintf("%.2f", shift->paid) } ],
+      [ payby             => sub { FS::payby->shortname(shift->payby) } ],
+      [ date              => sub { time2str("%a %B %o, %Y", shift->_date) } ],
+      [ payinfo           => sub {
+          my $pending = shift;
+          ($pending->payby eq 'CARD' || $pending->payby eq 'CHEK') ?
+            $pending->paymask : $pending->decrypt($pending->payinfo)
+        } ],
+    ],
   };
 }
 
index 67eae18..c38c40e 100644 (file)
@@ -51,6 +51,7 @@ my %substitutions = (
     '$ucfirst_cust_status'  => 'Status, capitalized',
     '$cust_statuscolor'     => 'Status color code',
     '$company_name'   => 'Our company name',
+    '$company_address'=> 'Our company address',
   ],
   'contact' => [ # duplicate this for shipping
     '$name'           => 'Company and contact name',
@@ -101,6 +102,7 @@ my %substitutions = (
     '$payby'          => 'Payment method',
     '$date'           => 'Payment date',
     '$payinfo'        => 'Card/account# (masked)',
+    '$error'          => 'Decline reason',
   ],
 );
 my @c = @{ $substitutions{'contact'} };