[freeside-commits]
freeside/FS/FS Schema.pm, 1.1, 1.2 banned_pay.pm,
NONE, 1.1 cancel_reason.pm, NONE, 1.1 cust_main.pm, 1.192, 1.193
Ivan,,,
ivan at wavetail.420.am
Sat Aug 27 01:46:59 PDT 2005
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv13629/FS/FS
Modified Files:
Schema.pm cust_main.pm
Added Files:
banned_pay.pm cancel_reason.pm
Log Message:
add banned credit card / ACH table, re-do cancel popup to have a checkbox to ban payinfo
--- NEW FILE: cancel_reason.pm ---
package FS::cancel_reason;
use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs );
@ISA = qw(FS::Record);
=head1 NAME
FS::cancel_reason - Object methods for cancel_reason records
=head1 SYNOPSIS
use FS::cancel_reason;
$record = new FS::cancel_reason \%hash;
$record = new FS::cancel_reason { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
=head1 DESCRIPTION
An FS::cancel_reason object represents an cancellation reason.
FS::cancel_reason inherits from FS::Record. The following fields are
currently supported:
=over 4
=item reasonnum - primary key
=item reason -
=item disabled - empty or "Y"
=back
=head1 METHODS
=over 4
=item new HASHREF
Creates a new cancellation reason. To add the reason to the database, see
L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the I<hash> method.
=cut
# the new method can be inherited from FS::Record, if a table method is defined
sub table { 'cancel_reason'; }
=item insert
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
=cut
# the insert method can be inherited from FS::Record
=item delete
Delete this record from the database.
=cut
# the delete method can be inherited from FS::Record
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
=cut
# the replace method can be inherited from FS::Record
=item check
Checks all fields to make sure this is a valid reason. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
=cut
# the check method should currently be supplied - FS::Record contains some
# data checking routines
sub check {
my $self = shift;
my $error =
$self->ut_numbern('reasonnum')
|| $self->ut_text('reason')
|| $self->ut_enum('disabled', [ '', 'Y' ] )
;
return $error if $error;
$self->SUPER::check;
}
=back
=head1 BUGS
=head1 SEE ALSO
L<FS::Record>, schema.html from the base documentation.
=cut
1;
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Schema.pm 17 Aug 2005 22:23:45 -0000 1.1
+++ Schema.pm 27 Aug 2005 08:46:57 -0000 1.2
@@ -1229,6 +1229,32 @@
'index' => [ [ 'agentnum', 'cardtype' ], ],
},
+ 'banned_pay' => {
+ 'columns' => [
+ 'bannum', 'serial', '', '',
+ 'payby', 'char', '', 4,
+ 'payinfo', 'varchar', '', 128, #say, a 512-big digest _hex encoded
+ #'paymask', 'varchar', 'NULL', $char_d,
+ '_date', @date_type,
+ 'otaker', 'varchar', '', 32,
+ 'reason', 'varchar', 'NULL', $char_d,
+ ],
+ 'primary_key' => 'bannum',
+ 'unique' => [ [ 'payby', 'payinfo' ] ],
+ 'index' => [],
+ },
+
+ 'cancel_reason' => {
+ 'columns' => [
+ 'reasonnum', 'serial', '', '',
+ 'reason', 'varchar', '', $char_d,
+ 'disabled', 'char', 'NULL', 1,
+ ],
+ 'primary_key' => 'reasonnum',
+ 'unique' => [],
+ 'index' => [ [ 'disabled' ] ],
+ },
+
};
}
--- NEW FILE: banned_pay.pm ---
package FS::banned_pay;
use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs );
use FS::UID qw( getotaker );
@ISA = qw(FS::Record);
=head1 NAME
FS::banned_pay - Object methods for banned_pay records
=head1 SYNOPSIS
use FS::banned_pay;
$record = new FS::banned_pay \%hash;
$record = new FS::banned_pay { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
=head1 DESCRIPTION
An FS::banned_pay object represents an banned credit card or ACH account.
FS::banned_pay inherits from FS::Record. The following fields are currently
supported:
=over 4
=item bannum - primary key
=item payby - I<CARD> or I<CHEK>
=item payinfo - fingerprint of banned card (base64-encoded MD5 digest)
=item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
L<Time::Local> and L<Date::Parse> for conversion functions.
=item otaker - order taker (assigned automatically, see L<FS::UID>)
=item reason - reason (text)
=back
=head1 METHODS
=over 4
=item new HASHREF
Creates a new ban. To add the ban to the database, see L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the I<hash> method.
=cut
# the new method can be inherited from FS::Record, if a table method is defined
sub table { 'banned_pay'; }
=item insert
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
=cut
# the insert method can be inherited from FS::Record
=item delete
Delete this record from the database.
=cut
# the delete method can be inherited from FS::Record
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
=cut
# the replace method can be inherited from FS::Record
=item check
Checks all fields to make sure this is a valid ban. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
=cut
# the check method should currently be supplied - FS::Record contains some
# data checking routines
sub check {
my $self = shift;
my $error =
$self->ut_numbern('bannum')
|| $self->ut_enum('payby', [ 'CARD', 'CHEK' ] )
|| $self->ut_text('payinfo')
|| $self->ut_numbern('_date')
|| $self->ut_textn('reason')
;
return $error if $error;
$self->_date(time) unless $self->_date;
$self->otaker(getotaker);
$self->SUPER::check;
}
=back
=head1 BUGS
=head1 SEE ALSO
L<FS::Record>, schema.html from the base documentation.
=cut
1;
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.192
retrieving revision 1.193
diff -u -d -r1.192 -r1.193
--- cust_main.pm 24 Aug 2005 13:22:27 -0000 1.192
+++ cust_main.pm 27 Aug 2005 08:46:57 -0000 1.193
@@ -14,6 +14,7 @@
#eval "use Time::Local qw(timelocal timelocal_nocheck);";
eval "use Time::Local qw(timelocal_nocheck);";
}
+use Digest::MD5 qw(md5_base64);
use Date::Format;
#use Date::Manip;
use String::Approx qw(amatch);
@@ -21,6 +22,7 @@
use FS::UID qw( getotaker dbh );
use FS::Record qw( qsearchs qsearch dbdef );
use FS::Misc qw( send_email );
+use FS::Msgcat qw(gettext);
use FS::cust_pkg;
use FS::cust_svc;
use FS::cust_bill;
@@ -44,7 +46,7 @@
use FS::type_pkgs;
use FS::payment_gateway;
use FS::agent_payment_gateway;
-use FS::Msgcat qw(gettext);
+use FS::banned_pay;
@ISA = qw( FS::Record );
@@ -1140,8 +1142,13 @@
$self->payinfo($payinfo);
validate($payinfo)
or return gettext('invalid_card'); # . ": ". $self->payinfo;
+
return gettext('unknown_card_type')
if cardtype($self->payinfo) eq "Unknown";
+
+ my $ban = qsearchs('banned_pay', $self->_banned_pay_hashref);
+ return "Banned credit card" if $ban;
+
if ( defined $self->dbdef_table->column('paycvv') ) {
if (length($self->paycvv) && !$self->is_encrypted($self->paycvv)) {
if ( cardtype($self->payinfo) eq 'American Express card' ) {
@@ -1191,6 +1198,9 @@
$self->payinfo($payinfo);
$self->paycvv('') if $self->dbdef_table->column('paycvv');
+ my $ban = qsearchs('banned_pay', $self->_banned_pay_hashref);
+ return "Banned ACH account" if $ban;
+
} elsif ( $self->payby eq 'LECB' ) {
my $payinfo = $self->payinfo;
@@ -1428,19 +1438,56 @@
Cancels all uncancelled packages (see L<FS::cust_pkg>) for this customer.
-Available options are: I<quiet>
+Available options are: I<quiet>, I<reasonnum>, and I<ban>
I<quiet> can be set true to supress email cancellation notices.
+# I<reasonnum> can be set to a cancellation reason (see L<FS::cancel_reason>)
+
+I<ban> can be set true to ban this customer's credit card or ACH information,
+if present.
+
Always returns a list: an empty list on success or a list of errors.
=cut
sub cancel {
my $self = shift;
+ my %opt = @_;
+
+ if ( $opt{'ban'} && $self->payby =~ /^(CARD|DCRD|CHEK|DCHK)$/ ) {
+
+ #should try decryption (we might have the private key)
+ # and if not maybe queue a job for the server that does?
+ return ( "Can't (yet) ban encrypted credit cards" )
+ if $self->is_encrypted($self->payinfo);
+
+ my $ban = new FS::banned_pay $self->_banned_pay_hashref;
+ my $error = $ban->insert;
+ return ( $error ) if $error;
+
+ }
+
grep { $_ } map { $_->cancel(@_) } $self->ncancelled_pkgs;
}
+sub _banned_pay_hashref {
+ my $self = shift;
+
+ my %payby2ban = (
+ 'CARD' => 'CARD',
+ 'DCRD' => 'CARD',
+ 'CHEK' => 'CHEK',
+ 'DCHK' => 'CHEK'
+ );
+
+ {
+ 'payby' => $payby2ban{$self->payby},
+ 'payinfo' => md5_base64($self->payinfo),
+ #'reason' =>
+ };
+}
+
=item agent
Returns the agent (see L<FS::agent>) for this customer.
More information about the freeside-commits
mailing list