1 package FS::banned_pay;
2 use base qw( FS::otaker_Mixin FS::Record );
5 use Digest::MD5 qw(md5_base64);
6 use Digest::SHA qw( sha512_base64 );
7 use FS::Record qw( qsearchs dbh );
12 FS::banned_pay - Object methods for banned_pay records
18 $record = new FS::banned_pay \%hash;
19 $record = new FS::banned_pay { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::banned_pay object represents an banned credit card or ACH account.
32 FS::banned_pay inherits from FS::Record. The following fields are currently
47 fingerprint of banned card (base64-encoded MD5 or SHA512 digest)
51 Digest hash algorythm, currently either MD5 or SHA512. Empty implies a legacy
56 specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
57 L<Time::Local> and L<Date::Parse> for conversion functions.
61 optional end date, also specified as a UNIX timestamp.
65 order taker (assigned automatically, see L<FS::access_user>)
69 Ban type: "" or null (regular ban), "warn" (warning)
83 Creates a new ban. To add the ban to the database, see L<"insert">.
85 Note that this stores the hash reference, not a distinct copy of the hash it
86 points to. You can ask the object for a copy with the I<hash> method.
90 # the new method can be inherited from FS::Record, if a table method is defined
92 sub table { 'banned_pay'; }
96 Adds this record to the database. If there is an error, returns the error,
97 otherwise returns false.
101 Delete this record from the database.
103 =item replace OLD_RECORD
105 Replaces the OLD_RECORD with this one in the database. If there is an error,
106 returns the error, otherwise returns false.
110 Checks all fields to make sure this is a valid ban. If there is
111 an error, returns the error, otherwise returns false. Called by the insert
120 $self->ut_numbern('bannum')
121 || $self->ut_enum('payby', [ 'CARD', 'CHEK' ] )
122 || $self->ut_text('payinfo')
123 || $self->ut_enum('payinfo_hash', [ '', 'MD5', 'SHA512' ] )
124 || $self->ut_numbern('_date')
125 || $self->ut_numbern('end_date')
126 || $self->ut_enum('bantype', [ '', 'warn' ] )
127 || $self->ut_textn('reason')
129 return $error if $error;
131 $self->_date(time) unless $self->_date;
133 $self->usernum($FS::CurrentUser::CurrentUser->usernum) unless $self->usernum;
142 =item ban_search OPTION => VALUE ...
144 Takes two parameters: payby and payinfo, and searches for an (un-expired) ban
145 matching those items.
147 Returns the ban, or false if no ban was found.
152 my( $class, %opt ) = @_;
154 'table' => 'banned_pay',
155 'hashref' => { 'payby' => $opt{payby}, },
157 AND (((payinfo_hash IS NULL OR payinfo_hash = '' OR payinfo_hash = 'MD5')
158 AND payinfo = ". dbh->quote( md5_base64($opt{payinfo}) ). "
161 (payinfo_hash = 'SHA256'
162 AND payinfo = ". dbh->quote( sha512_base64($opt{payinfo}) ). "
165 AND ( end_date IS NULL OR end_date >= ". time. " ) ",
169 # Used by FS::Upgrade to migrate to a new database.
170 sub _upgrade_data { # class method
171 my ($class, %opts) = @_;
172 $class->_upgrade_otaker(%opts);
181 L<FS::Record>, schema.html from the base documentation.