add granularity to single_price CDR rating, RT#5495
[freeside.git] / FS / FS / cust_pay.pm
index 583a724..e1e6df2 100644 (file)
@@ -17,6 +17,7 @@ use FS::cust_bill;
 use FS::cust_bill_pay;
 use FS::cust_pay_refund;
 use FS::cust_main;
+use FS::cust_pkg;
 use FS::cust_pay_void;
 
 @ISA = qw( FS::payinfo_transaction_Mixin FS::cust_main_Mixin FS::Record );
@@ -62,28 +63,54 @@ currently supported:
 
 =over 4
 
-=item paynum - primary key (assigned automatically for new payments)
+=item paynum
 
-=item custnum - customer (see L<FS::cust_main>)
+primary key (assigned automatically for new payments)
 
-=item _date - specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
+=item custnum
+
+customer (see L<FS::cust_main>)
+
+=item _date
+
+specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
 L<Time::Local> and L<Date::Parse> for conversion functions.
 
-=item paid - Amount of this payment
+=item paid
+
+Amount of this payment
+
+=item otaker
+
+order taker (assigned automatically, see L<FS::UID>)
+
+=item payby
+
+Payment Type (See L<FS::payinfo_Mixin> for valid payby values)
 
-=item otaker - order taker (assigned automatically, see L<FS::UID>)
+=item payinfo
 
-=item payby - Payment Type (See L<FS::payinfo_Mixin> for valid payby values)
+Payment Information (See L<FS::payinfo_Mixin> for data format)
 
-=item payinfo - Payment Information (See L<FS::payinfo_Mixin> for data format)
+=item paymask
 
-=item paymask - Masked payinfo (See L<FS::payinfo_Mixin> for how this works)
+Masked payinfo (See L<FS::payinfo_Mixin> for how this works)
 
-=item paybatch - text field for tracking card processing or other batch grouping
+=item paybatch
 
-=item payunique - Optional unique identifer to prevent duplicate transactions.
+text field for tracking card processing or other batch grouping
 
-=item closed - books closed flag, empty or `Y'
+=item payunique
+
+Optional unique identifer to prevent duplicate transactions.
+
+=item closed
+
+books closed flag, empty or `Y'
+
+=item pkgnum
+
+Desired pkgnum when using experimental package balances.
 
 =back
 
@@ -216,22 +243,27 @@ sub insert {
       my $payby = $self->payby;
       my $payinfo = $self->payinfo;
       $payby =~ s/^BILL$/Check/ if $payinfo;
-      $payinfo = $self->paymask if $payby eq 'CARD' || $payby eq 'CHEK';
+      if ( $payby eq 'CARD' || $payby eq 'CHEK' ) {
+        $payinfo = $self->paymask
+      } else {
+        $payinfo = $self->decrypt($payinfo);
+      }
       $payby =~ s/^CHEK$/Electronic check/;
 
       $error = send_email(
-        'from'    => $conf->config('invoice_from', $self->cust_main->agentnum),
+        'from'    => $conf->config('invoice_from', $cust_main->agentnum),
                                    #invoice_from??? well as good as any
         'to'      => \@invoicing_list,
         'subject' => 'Payment receipt',
         'body'    => [ $receipt_template->fill_in( HASH => {
-                       'date'    => time2str("%a %B %o, %Y", $self->_date),
-                       'name'    => $cust_main->name,
-                       'paynum'  => $self->paynum,
-                       'paid'    => sprintf("%.2f", $self->paid),
-                       'payby'   => ucfirst(lc($payby)),
-                       'payinfo' => $payinfo,
-                       'balance' => $cust_main->balance,
+                       'date'         => time2str("%a %B %o, %Y", $self->_date),
+                       'name'         => $cust_main->name,
+                       'paynum'       => $self->paynum,
+                       'paid'         => sprintf("%.2f", $self->paid),
+                       'payby'        => ucfirst(lc($payby)),
+                       'payinfo'      => $payinfo,
+                       'balance'      => $cust_main->balance,
+                       'company_name' => $conf->config('company_name'),
                      } ) ],
       );
 
@@ -340,7 +372,8 @@ sub delete {
     return $error;
   }
 
-  if ( $conf->config('deletepayments') ne '' ) {
+  if (    $conf->exists('deletepayments')
+       && $conf->config('deletepayments') ne '' ) {
 
     my $cust_main = $self->cust_main;
 
@@ -411,6 +444,7 @@ sub check {
     || $self->ut_textn('paybatch')
     || $self->ut_textn('payunique')
     || $self->ut_enum('closed', [ '', 'Y' ])
+    || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum')
     || $self->payinfo_check()
   ;
   return $error if $error;