1 package FS::cust_pay_batch;
6 use Business::CreditCard;
8 @ISA = qw( FS::Record );
12 FS::cust_pay_batch - Object methods for batch cards
16 use FS::cust_pay_batch;
18 $record = new FS::cust_pay_batch \%hash;
19 $record = new FS::cust_pay_batch { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::cust_pay_batch object represents a credit card transaction ready to be
32 batched (sent to a processor). FS::cust_pay_batch inherits from FS::Record.
33 Typically called by the collect method of an FS::cust_main object. The
34 following fields are currently supported:
38 =item trancode - 77 for charges
42 =item exp - card expiration
46 =item invnum - invoice
48 =item custnum - customer
50 =item payname - name on card
76 Creates a new record. To add the record to the database, see L<"insert">.
78 Note that this stores the hash reference, not a distinct copy of the hash it
79 points to. You can ask the object for a copy with the I<hash> method.
83 sub table { 'cust_pay_batch'; }
87 Adds this record to the database. If there is an error, returns the error,
88 otherwise returns false.
92 Delete this record from the database. If there is an error, returns the error,
93 otherwise returns false.
95 =item replace OLD_RECORD
99 #Replaces the OLD_RECORD with this one in the database. If there is an error,
100 #returns the error, otherwise returns false.
105 return "Can't (yet?) replace batched transactions!";
110 Checks all fields to make sure this is a valid transaction. If there is
111 an error, returns the error, otherwise returns false. Called by the insert
120 $self->ut_numbern('trancode')
121 || $self->ut_number('cardnum')
122 || $self->ut_money('amount')
123 || $self->ut_number('invnum')
124 || $self->ut_number('custnum')
125 || $self->ut_text('address1')
126 || $self->ut_textn('address2')
127 || $self->ut_text('city')
128 || $self->ut_text('state')
131 return $error if $error;
133 $self->getfield('last') =~ /^([\w \,\.\-\']+)$/ or return "Illegal last name";
134 $self->setfield('last',$1);
136 $self->first =~ /^([\w \,\.\-\']+)$/ or return "Illegal first name";
139 my $cardnum = $self->cardnum;
141 $cardnum =~ /^(\d{13,16})$/
142 or return "Illegal credit card number";
144 $self->cardnum($cardnum);
145 validate($cardnum) or return "Illegal credit card number";
146 return "Unknown card type" if cardtype($cardnum) eq "Unknown";
148 if ( $self->exp eq '' ) {
149 return "Expriation date required"; #unless
152 if ( $self->exp =~ /^(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})$/ ) {
153 $self->exp("$1-$2-$3");
154 } elsif ( $self->exp =~ /^(\d{1,2})[\/\-](\d{2}(\d{2})?)$/ ) {
155 if ( length($2) == 4 ) {
156 $self->exp("$2-$1-01");
157 } elsif ( $2 > 98 ) { #should pry change to check for "this year"
158 $self->exp("19$2-$1-01");
160 $self->exp("20$2-$1-01");
163 return "Illegal expiration date";
167 if ( $self->payname eq '' ) {
168 $self->payname( $self->first. " ". $self->getfield('last') );
170 $self->payname =~ /^([\w \,\.\-\']+)$/
171 or return "Illegal billing name";
175 $self->zip =~ /^\s*(\w[\w\-\s]{3,8}\w)\s*$/
176 or return "Illegal zip: ". $self->zip;
179 $self->country =~ /^(\w\w)$/ or return "Illegal country: ". $self->country;
182 #check invnum, custnum, ?
191 $Id: cust_pay_batch.pm,v 1.2 2000-06-17 21:48:05 ivan Exp $
195 There should probably be a configuration file with a list of allowed credit
200 L<FS::cust_main>, L<FS::Record>