[freeside-commits] branch FREESIDE_4_BRANCH updated. 5a97f3f545d11966801077b9740e5f91fb2bbf6a

Mark Wells mark at 420.am
Wed Dec 21 15:40:09 PST 2016


The branch, FREESIDE_4_BRANCH has been updated
       via  5a97f3f545d11966801077b9740e5f91fb2bbf6a (commit)
      from  bc1b0f58caeecdfb63f1450968a05db050d6758b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5a97f3f545d11966801077b9740e5f91fb2bbf6a
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Dec 21 15:25:35 2016 -0800

    fix payinfo_used on batch payments with encrypted payinfo, related to #19571

diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index e0a7143..64ce7ec 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -540,7 +540,8 @@ otherwise returns false.
 
 sub replace {
   my $self = shift;
-  return "Can't modify closed payment" if $self->closed =~ /^Y/i;
+  return "Can't modify closed payment"
+    if $self->closed =~ /^Y/i && !$FS::payinfo_Mixin::allow_closed_replace;
   $self->SUPER::replace(@_);
 }
 
@@ -1215,6 +1216,30 @@ sub _upgrade_data {  #class method
   ###
   $class->upgrade_set_cardtype;
 
+  # for batch payments, make sure paymask is set
+  do {
+    local $FS::payinfo_Mixin::allow_closed_replace = 1;
+    local $FS::payinfo_Mixin::ignore_masked_payinfo = 1;
+
+    my $cursor = FS::Cursor->new({
+      table => 'cust_pay',
+      extra_sql => ' WHERE paymask IS NULL AND payinfo IS NOT NULL
+                    AND payby IN(\'CARD\', \'CHEK\')
+                    AND batchnum IS NOT NULL',
+    });
+
+    # records from cursors for some reason don't decrypt payinfo, so
+    # call replace_old to fetch the record "normally"
+    while (my $cust_pay = $cursor->fetch) {
+      $cust_pay = $cust_pay->replace_old;
+      $cust_pay->set('paymask', $cust_pay->mask_payinfo);
+      my $error = $cust_pay->replace;
+      if ($error) {
+        die "$error (setting masked payinfo on payment#". $cust_pay->paynum.
+          ")\n"
+      }
+    }
+  };
 }
 
 sub process_upgrade_paybatch {
diff --git a/FS/FS/cust_pay_batch.pm b/FS/FS/cust_pay_batch.pm
index 8127c6a..d29c6d0 100644
--- a/FS/FS/cust_pay_batch.pm
+++ b/FS/FS/cust_pay_batch.pm
@@ -297,6 +297,7 @@ sub approve {
       'custnum'   => $new->custnum,
       'payby'     => $new->payby,
       'payinfo'   => $new->payinfo || $old->payinfo,
+      'paymask'   => $new->mask_payinfo,
       'paid'      => $new->paid,
       '_date'     => $new->_date,
       'usernum'   => $new->usernum,
diff --git a/FS/FS/payinfo_Mixin.pm b/FS/FS/payinfo_Mixin.pm
index 5f7ce35..cf5a7df 100644
--- a/FS/FS/payinfo_Mixin.pm
+++ b/FS/FS/payinfo_Mixin.pm
@@ -8,7 +8,7 @@ use FS::UID qw(driver_name);
 use FS::Cursor;
 use Time::Local qw(timelocal);
 
-use vars qw($ignore_masked_payinfo);
+use vars qw( $ignore_masked_payinfo $allow_closed_replace );
 
 =head1 NAME
 
@@ -304,13 +304,12 @@ sub payinfo_used {
   my $payinfo = shift || $self->payinfo;
   my %hash = (
     'custnum' => $self->custnum,
-    'payby'   => 'CARD',
+    'payby'   => $self->payby,
   );
 
   return 1
   if qsearch('cust_pay', { %hash, 'payinfo' => $payinfo } )
-  || qsearch('cust_pay', 
-    { %hash, 'paymask' => $self->mask_payinfo('CARD', $payinfo) }  )
+  || qsearch('cust_pay', { %hash, 'paymask' => $self->mask_payinfo } )
   ;
 
   return 0;

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cust_pay.pm       |   27 ++++++++++++++++++++++++++-
 FS/FS/cust_pay_batch.pm |    1 +
 FS/FS/payinfo_Mixin.pm  |    7 +++----
 3 files changed, 30 insertions(+), 5 deletions(-)




More information about the freeside-commits mailing list