add payunique field and dup checking
[freeside.git] / FS / FS / cust_pay.pm
index 30333e0..dc6bd40 100644 (file)
@@ -403,6 +403,7 @@ sub check {
     || $self->ut_money('paid')
     || $self->ut_numbern('_date')
     || $self->ut_textn('paybatch')
+    || $self->ut_textn('payunique')
     || $self->ut_enum('closed', [ '', 'Y' ])
     || $self->payinfo_check()
   ;
@@ -416,6 +417,13 @@ sub check {
 
   $self->_date(time) unless $self->_date;
 
+  # UNIQUE index should catch this too, without race conditions, but this
+  # should give a better error message the other 99.9% of the time...
+  if ( length($self->payunique)
+       && qsearchs('cust_pay', { 'payunique' => $self->payunique } ) {
+    return "duplicate transaction"; #well, it *could* be a better error message
+  }
+
   $self->SUPER::check;
 }