1 package FS::payinfo_Mixin;
4 use Business::CreditCard;
9 FS::payinfo_Mixin - Mixin class for records in tables that contain payinfo.
13 package FS::some_table;
15 @ISA = qw( FS::payinfo_Mixin FS::Record );
19 This is a mixin class for records that contain payinfo.
21 This class handles the following functions for payinfo...
23 Payment Mask (Generation and Storage)
24 Data Validation (parent checks need to be sure to call this)
33 The following payment types (payby) are supported:
35 For Customers (cust_main):
36 'CARD' (credit card - automatic), 'DCRD' (credit card - on-demand),
37 'CHEK' (electronic check - automatic), 'DCHK' (electronic check - on-demand),
38 'LECB' (Phone bill billing), 'BILL' (billing), 'COMP' (free), or
39 'PREPAY' (special billing type: applies a credit and sets billing type to I<BILL> - see L<FS::prepay_credit>)
41 For Refunds (cust_refund):
42 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
43 'LECB' (Phone bill billing), 'BILL' (billing), 'CASH' (cash),
44 'WEST' (Western Union), 'MCRD' (Manual credit card), 'CBAK' Chargeback, or 'COMP' (free)
47 For Payments (cust_pay):
48 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
49 'LECB' (phone bill billing), 'BILL' (billing), 'PREP' (prepaid card),
50 'CASH' (cash), 'WEST' (Western Union), or 'MCRD' (Manual credit card)
51 'COMP' (free) is depricated as a payment type in cust_pay
55 # was this supposed to do something?
58 # my($self,$payby) = @_;
59 # if ( defined($payby) ) {
60 # $self->setfield('payby', $payby);
62 # return $self->getfield('payby')
67 Payment information (payinfo) can be one of the following types:
69 Card Number, P.O., comp issuer (4-8 lowercase alphanumerics; think username) or prepayment identifier (see L<FS::prepay_credit>)
74 my($self,$payinfo) = @_;
75 if ( defined($payinfo) ) {
76 $self->setfield('payinfo', $payinfo); # This is okay since we are the 'setter'
77 $self->paymask($self->mask_payinfo());
79 $payinfo = $self->getfield('payinfo'); # This is okay since we are the 'getter'
86 Card Verification Value, "CVV2" (also known as CVC2 or CID), the 3 or 4 digit number on the back (or front, for American Express) of the credit card
91 my($self,$paycvv) = @_;
92 # This is only allowed in cust_main... Even then it really shouldn't be stored...
93 if ($self->table eq 'cust_main') {
94 if ( defined($paycvv) ) {
95 $self->setfield('paycvv', $paycvv); # This is okay since we are the 'setter'
97 $paycvv = $self->getfield('paycvv'); # This is okay since we are the 'getter'
101 # warn "This doesn't work for other tables besides cust_main
111 my($self, $paymask) = @_;
113 if ( defined($paymask) && $paymask ne '' ) {
114 # I hate this little bit of magic... I don't expect it to cause a problem,
115 # but who knows... If the payinfo is passed in masked then ignore it and
116 # set it based on the payinfo. The only guy that should call this in this
117 # way is... $self->payinfo
118 $self->setfield('paymask', $self->mask_payinfo());
122 $paymask=$self->getfield('paymask');
123 if (!defined($paymask) || $paymask eq '') {
124 # Generate it if it's blank - Note that we're not going to set it - just
126 $paymask = $self->mask_payinfo();
140 =item mask_payinfo [ PAYBY, PAYINFO ]
142 This method converts the payment info (credit card, bank account, etc.) into a
145 Optionally, an arbitrary payby and payinfo can be passed.
151 my $payby = scalar(@_) ? shift : $self->payby;
152 my $payinfo = scalar(@_) ? shift : $self->payinfo;
154 # Check to see if it's encrypted...
156 if ( $self->is_encrypted($payinfo) ) {
160 if ($payby eq 'CARD' || $payby eq 'DCRD' || $payby eq 'MCRD') {
162 my $conf = new FS::Conf;
163 my $mask_method = $conf->config('card_masking_method') || 'first6last4';
164 $mask_method =~ /^first(\d+)last(\d+)$/
165 or die "can't parse card_masking_method $mask_method";
166 my($first, $last) = ($1, $2);
168 $paymask = substr($payinfo,0,$first).
169 'x'x(length($payinfo)-$first-$last).
170 substr($payinfo,(length($payinfo)-$last));
171 } elsif ($payby eq 'CHEK' || $payby eq 'DCHK' ) {
172 # Checks (Show last 2 @ bank)
173 my( $account, $aba ) = split('@', $payinfo );
174 $paymask = 'x'x(length($account)-2).
175 substr($account,(length($account)-2))."@".$aba;
176 } else { # Tie up loose ends
185 Checks payby and payinfo.
187 For Customers (cust_main):
188 'CARD' (credit card - automatic), 'DCRD' (credit card - on-demand),
189 'CHEK' (electronic check - automatic), 'DCHK' (electronic check - on-demand),
190 'LECB' (Phone bill billing), 'BILL' (billing), 'COMP' (free), or
191 'PREPAY' (special billing type: applies a credit - see L<FS::prepay_credit> and sets billing type to I<BILL>)
193 For Refunds (cust_refund):
194 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
195 'LECB' (Phone bill billing), 'BILL' (billing), 'CASH' (cash),
196 'WEST' (Western Union), 'MCRD' (Manual credit card), 'CBAK' (Chargeback), or 'COMP' (free)
198 For Payments (cust_pay):
199 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
200 'LECB' (phone bill billing), 'BILL' (billing), 'PREP' (prepaid card),
201 'CASH' (cash), 'WEST' (Western Union), or 'MCRD' (Manual credit card)
202 'COMP' (free) is depricated as a payment type in cust_pay
209 FS::payby->can_payby($self->table, $self->payby)
210 or return "Illegal payby: ". $self->payby;
212 if ( $self->payby eq 'CARD' && ! $self->is_encrypted($self->payinfo) ) {
213 my $payinfo = $self->payinfo;
215 $self->payinfo($payinfo);
216 if ( $self->payinfo ) {
217 $self->payinfo =~ /^(\d{13,16})$/
218 or return "Illegal (mistyped?) credit card number (payinfo)";
220 validate($self->payinfo) or return "Illegal credit card number";
221 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
223 $self->payinfo('N/A'); #???
226 if ( $self->is_encrypted($self->payinfo) ) {
227 #something better? all it would cause is a decryption error anyway?
228 my $error = $self->ut_anything('payinfo');
229 return $error if $error;
231 my $error = $self->ut_textn('payinfo');
232 return $error if $error;
240 =item payby_payinfo_pretty
242 Returns payment method and information (suitably masked, if applicable) as
243 a human-readable string, such as:
245 Card #54xxxxxxxxxxxx32
253 sub payby_payinfo_pretty {
255 if ( $self->payby eq 'CARD' ) {
256 'Card #'. $self->paymask;
257 } elsif ( $self->payby eq 'CHEK' ) {
258 'E-check acct#'. $self->payinfo;
259 } elsif ( $self->payby eq 'BILL' ) {
260 'Check #'. $self->payinfo;
261 } elsif ( $self->payby eq 'PREP' ) {
262 'Prepaid card #'. $self->payinfo;
263 } elsif ( $self->payby eq 'CASH' ) {
264 'Cash '. $self->payinfo;
265 } elsif ( $self->payby eq 'WEST' ) {
266 'Western Union'; #. $self->payinfo;
267 } elsif ( $self->payby eq 'MCRD' ) {
268 'Manual credit card'; #. $self->payinfo;
270 $self->payby. ' '. $self->payinfo;
279 Encryption - In the Future (Pull from Record.pm)
280 Bad Card Stuff - In the Future (Integrate Banned Pay)
281 Currency - In the Future
285 L<FS::payby>, L<FS::Record>