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; the transfer of money from a
33 customer. FS::cust_pay inherits from FS::Record. The following fields are
38 =item paynum - primary key (assigned automatically for new payments)
40 =item invnum - Invoice (see L<FS::cust_bill>)
42 =item paid - Amount of this payment
44 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
45 L<Time::Local> and L<Date::Parse> for conversion functions.
47 =item payby - `CARD' (credit cards), `BILL' (billing), or `COMP' (free)
49 =item payinfo - card number, P.O.#, or comp issuer (4-8 lowercase alphanumerics; think username)
51 =item paybatch - text field for tracking card processing
61 Creates a new payment. To add the payment to the databse, see L<"insert">.
65 sub table { 'cust_pay'; }
69 Adds this payment to the databse, and updates the invoice (see
79 $error = $self->check;
80 return $error if $error;
82 my $old_cust_bill = qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
83 return "Unknown invnum" unless $old_cust_bill;
84 my %hash = $old_cust_bill->hash;
85 $hash{'owed'} = sprintf("%.2f", $hash{owed} - $self->paid );
86 my $new_cust_bill = new FS::cust_bill ( \%hash );
88 local $SIG{HUP} = 'IGNORE';
89 local $SIG{INT} = 'IGNORE';
90 local $SIG{QUIT} = 'IGNORE';
91 local $SIG{TERM} = 'IGNORE';
92 local $SIG{TSTP} = 'IGNORE';
93 local $SIG{PIPE} = 'IGNORE';
95 $error = $new_cust_bill->replace($old_cust_bill);
96 return "Error modifying cust_bill: $error" if $error;
103 Currently unimplemented (accounting reasons).
108 return "Can't (yet?) delete cust_pay records!";
111 =item replace OLD_RECORD
113 Currently unimplemented (accounting reasons).
118 return "Can't (yet?) modify cust_pay records!";
123 Checks all fields to make sure this is a valid payment. If there is an error,
124 returns the error, otherwise returns false. Called by the insert method.
134 $self->ut_numbern('paynum')
135 || $self->ut_number('invnum')
136 || $self->ut_money('paid')
137 || $self->ut_numbern('_date')
139 return $error if $error;
141 $self->_date(time) unless $self->_date;
143 $self->payby =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby";
146 if ( $self->payby eq 'CARD' ) {
147 my $payinfo = $self->payinfo;
149 $self->payinfo($payinfo);
150 if ( $self->payinfo ) {
151 $self->payinfo =~ /^(\d{13,16})$/
152 or return "Illegal (mistyped?) credit card number (payinfo)";
154 validate($self->payinfo) or return "Illegal credit card number";
155 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
157 $self->payinfo('N/A');
161 $error = $self->ut_textn('payinfo');
162 return $error if $error;
165 $error = $self->ut_textn('paybatch');
166 return $error if $error;
176 $Id: cust_pay.pm,v 1.2 2001-02-11 17:17:39 ivan Exp $
180 Delete and replace methods.
184 L<FS::Record>, L<FS::cust_bill>, schema.html from the base documentation.