fix encryption upgrades when a payment is refunded, then deleted. RT#74270, RT#73085
[freeside.git] / FS / FS / cust_refund.pm
index ced9540..2d5b3aa 100644 (file)
@@ -82,6 +82,10 @@ Payment Type (See L<FS::payinfo_Mixin> for valid payby values)
 
 Payment Information (See L<FS::payinfo_Mixin> for data format)
 
+=item paycardtype
+
+Detected credit card type, if appropriate; autodetected.
+
 =item paymask
 
 Masked payinfo (See L<FS::payinfo_Mixin> for how this works)
@@ -285,7 +289,8 @@ otherwise returns false.
 
 sub replace {
   my $self = shift;
-  return "Can't modify closed refund" if $self->closed =~ /^Y/i;
+  return "Can't modify closed refund" 
+    if $self->closed =~ /^Y/i && !$FS::payinfo_Mixin::allow_closed_replace;
   $self->SUPER::replace(@_);
 }
 
@@ -467,11 +472,27 @@ sub unapplied_sql {
 
 }
 
+sub _upgrade_schema {
+  #my ($class, %opts) = @_;
+
+  my $sql = 'UPDATE cust_refund SET source_paynum = NULL
+               WHERE source_paynum IS NOT NULL
+                 AND NOT EXISTS ( SELECT 1 FROM cust_pay
+                                    WHERE paynum = cust_refund.source_paynum )
+            ';
+  my $sth = dbh->prepare($sql) or die dbh->errstr;
+  $sth->execute or die $sth->errstr;
+  '';
+}
+
 # Used by FS::Upgrade to migrate to a new database.
 sub _upgrade_data {  # class method
   my ($class, %opts) = @_;
   $class->_upgrade_reasonnum(%opts);
   $class->_upgrade_otaker(%opts);
+
+  local $ignore_empty_reasonnum = 1;
+  $class->upgrade_set_cardtype;
 }
 
 =back