5 use Business::CreditCard;
6 use FS::Record qw( qsearchs );
9 @ISA = qw( FS::Record );
13 FS::cust_pay - Object methods for cust_pay objects
19 $record = new FS::cust_pay \%hash;
20 $record = new FS::cust_pay { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::cust_pay object represents a payment. FS::cust_pay inherits from
33 FS::Record. The following fields are currently supported:
37 =item paynum - primary key (assigned automatically for new payments)
39 =item invnum - Invoice (see L<FS::cust_bill>)
41 =item paid - Amount of this payment
43 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
44 L<Time::Local> and L<Date::Parse> for conversion functions.
46 =item payby - `CARD' (credit cards), `BILL' (billing), or `COMP' (free)
48 =item payinfo - card number, P.O.#, or comp issuer (4-8 lowercase alphanumerics; think username)
50 =item paybatch - text field for tracking card processing
60 Creates a new payment. To add the payment to the databse, see L<"insert">.
64 sub table { 'cust_pay'; }
68 Adds this payment to the databse, and updates the invoice (see
78 $error = $self->check;
79 return $error if $error;
81 my $old_cust_bill = qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
82 return "Unknown invnum" unless $old_cust_bill;
83 my %hash = $old_cust_bill->hash;
84 $hash{'owed'} = sprintf("%.2f", $hash{owed} - $self->paid );
85 my $new_cust_bill = new FS::cust_bill ( \%hash );
87 local $SIG{HUP} = 'IGNORE';
88 local $SIG{INT} = 'IGNORE';
89 local $SIG{QUIT} = 'IGNORE';
90 local $SIG{TERM} = 'IGNORE';
91 local $SIG{TSTP} = 'IGNORE';
92 local $SIG{PIPE} = 'IGNORE';
94 $error = $new_cust_bill->replace($old_cust_bill);
95 return "Error modifying cust_bill: $error" if $error;
102 Currently unimplemented (accounting reasons).
107 return "Can't (yet?) delete cust_pay records!";
110 =item replace OLD_RECORD
112 Currently unimplemented (accounting reasons).
117 return "Can't (yet?) modify cust_pay records!";
122 Checks all fields to make sure this is a valid payment. If there is an error,
123 returns the error, otherwise returns false. Called by the insert method.
133 $self->ut_numbern('paynum')
134 || $self->ut_number('invnum')
135 || $self->ut_money('paid')
136 || $self->ut_numbern('_date')
138 return $error if $error;
140 $self->_date(time) unless $self->_date;
142 $self->payby =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby";
145 if ( $self->payby eq 'CARD' ) {
146 my $payinfo = $self->payinfo;
147 $self->payinfo($payinfo =~ s/\D//g);
148 if ( $self->payinfo ) {
149 $self->payinfo =~ /^(\d{13,16})$/
150 or return "Illegal (mistyped?) credit card number (payinfo)";
152 validate($self->payinfo) or return "Illegal credit card number";
153 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
155 $self->payinfo('N/A');
159 $error = $self->ut_textn('payinfo');
160 return $error if $error;
163 $error = $self->ut_textn('paybatch');
164 return $error if $error;
174 $Id: cust_pay.pm,v 1.3 1999-01-25 12:26:11 ivan Exp $
178 Delete and replace methods.
182 L<FS::Record>, L<FS::cust_bill>, schema.html from the base documentation.
186 ivan@voicenet.com 97-jul-1 - 25 - 29
188 new api ivan@sisd.com 98-mar-13
190 pod ivan@sisd.com 98-sep-21
192 $Log: cust_pay.pm,v $
193 Revision 1.3 1999-01-25 12:26:11 ivan
194 yet more mod_perl stuff
196 Revision 1.2 1998/12/29 11:59:43 ivan
197 mostly properly OO, some work still to be done with svc_ stuff