4 use vars qw(@ISA @EXPORT_OK);
6 use Business::CreditCard;
7 use FS::Record qw(fields qsearchs);
10 @ISA = qw(FS::Record Exporter);
11 @EXPORT_OK = qw(fields);
15 FS::cust_pay - Object methods for cust_pay objects
21 $record = create FS::cust_pay \%hash;
22 $record = create FS::cust_pay { 'column' => 'value' };
24 $error = $record->insert;
26 $error = $new_record->replace($old_record);
28 $error = $record->delete;
30 $error = $record->check;
34 An FS::cust_pay object represents a payment. FS::cust_pay inherits from
35 FS::Record. The following fields are currently supported:
39 =item paynum - primary key (assigned automatically for new payments)
41 =item invnum - Invoice (see L<FS::cust_bill>)
43 =item paid - Amount of this payment
45 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
46 L<Time::Local> and L<Date::Parse> for conversion functions.
48 =item payby - `CARD' (credit cards), `BILL' (billing), or `COMP' (free)
50 =item payinfo - card number, P.O.#, or comp issuer (4-8 lowercase alphanumerics; think username)
52 =item paybatch - text field for tracking card processing
62 Creates a new payment. To add the payment to the databse, see L<"insert">.
67 my($proto,$hashref)=@_;
69 #now in FS::Record::new
71 #foreach $field (fields('cust_pay')) {
72 # $hashref->{$field}='' unless defined $hashref->{$field};
75 $proto->new('cust_pay',$hashref);
81 Adds this payment to the databse, and updates the invoice (see
92 return $error if $error;
94 my($old_cust_bill) = qsearchs('cust_bill', {
95 'invnum' => $self->getfield('invnum')
97 return "Unknown invnum" unless $old_cust_bill;
98 my(%hash)=$old_cust_bill->hash;
99 $hash{owed} = sprintf("%.2f",$hash{owed} - $self->getfield('paid') );
100 my($new_cust_bill) = create FS::cust_bill ( \%hash );
102 local $SIG{HUP} = 'IGNORE';
103 local $SIG{INT} = 'IGNORE';
104 local $SIG{QUIT} = 'IGNORE';
105 local $SIG{TERM} = 'IGNORE';
106 local $SIG{TSTP} = 'IGNORE';
108 $error=$new_cust_bill -> replace($old_cust_bill);
109 return "Error modifying cust_bill: $error" if $error;
116 Currently unimplemented (accounting reasons).
121 return "Can't (yet?) delete cust_pay records!";
128 =item replace OLD_RECORD
130 Currently unimplemented (accounting reasons).
135 return "Can't (yet?) modify cust_pay records!";
138 # return "(Old) Not a cust_pay record!" unless $old->table eq "cust_pay";
146 Checks all fields to make sure this is a valid payment. If there is an error,
147 returns the error, otherwise returns false. Called by the insert method.
153 return "Not a cust_pay record!" unless $self->table eq "cust_pay";
154 my($recref) = $self->hashref;
156 $recref->{paynum} =~ /^(\d*)$/ or return "Illegal paynum";
157 $recref->{paynum} = $1;
159 $recref->{invnum} =~ /^(\d+)$/ or return "Illegal invnum";
160 $recref->{invnum} = $1;
162 $recref->{paid} =~ /^(\d+(\.\d\d)?)$/ or return "Illegal paid";
163 $recref->{paid} = $1;
165 $recref->{_date} =~ /^(\d*)$/ or return "Illegal date";
166 $recref->{_date} = $recref->{_date} ? $1 : time;
168 $recref->{payby} =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby";
169 $recref->{payby} = $1;
171 if ( $recref->{payby} eq 'CARD' ) {
173 $recref->{payinfo} =~ s/\D//g;
174 if ( $recref->{payinfo} ) {
175 $recref->{payinfo} =~ /^(\d{13,16})$/
176 or return "Illegal (mistyped?) credit card number (payinfo)";
177 $recref->{payinfo} = $1;
178 #validate($recref->{payinfo})
179 # or return "Illegal credit card number";
180 my($type)=cardtype($recref->{payinfo});
181 return "Unknown credit card type"
182 unless ( $type =~ /^VISA/ ||
183 $type =~ /^MasterCard/ ||
184 $type =~ /^American Express/ ||
185 $type =~ /^Discover/ );
187 $recref->{payinfo}='N/A';
190 } elsif ( $recref->{payby} eq 'BILL' ) {
192 $recref->{payinfo} =~ /^([\w \-]*)$/
193 or return "Illegal P.O. number (payinfo)";
194 $recref->{payinfo} = $1;
196 } elsif ( $recref->{payby} eq 'COMP' ) {
198 $recref->{payinfo} =~ /^([\w]{2,8})$/
199 or return "Illegal comp account issuer (payinfo)";
200 $recref->{payinfo} = $1;
204 $recref->{paybatch} =~ /^([\w\-\:]*)$/
205 or return "Illegal paybatch";
206 $recref->{paybatch} = $1;
216 It doesn't properly override FS::Record yet.
218 Delete and replace methods.
222 L<FS::Record>, L<FS::cust_bill>, schema.html from the base documentation.
226 ivan@voicenet.com 97-jul-1 - 25 - 29
228 new api ivan@sisd.com 98-mar-13
230 pod ivan@sisd.com 98-sep-21