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)
25 Encryption - In the Future (Pull from Record.pm)
26 Bad Card Stuff - In the Future (Integrate Banned Pay)
27 Currency - In the Future
35 The following payment types (payby) are supported:
37 For Customers (cust_main):
38 'CARD' (credit card - automatic), 'DCRD' (credit card - on-demand),
39 'CHEK' (electronic check - automatic), 'DCHK' (electronic check - on-demand),
40 'LECB' (Phone bill billing), 'BILL' (billing), 'COMP' (free), or
41 'PREPAY' (special billing type: applies a credit and sets billing type to I<BILL> - see L<FS::prepay_credit>)
43 For Refunds (cust_refund):
44 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
45 'LECB' (Phone bill billing), 'BILL' (billing), 'CASH' (cash),
46 'WEST' (Western Union), 'MCRD' (Manual credit card), 'CBAK' Chargeback, or 'COMP' (free)
49 For Payments (cust_pay):
50 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
51 'LECB' (phone bill billing), 'BILL' (billing), 'PREP' (prepaid card),
52 'CASH' (cash), 'WEST' (Western Union), or 'MCRD' (Manual credit card)
53 'COMP' (free) is depricated as a payment type in cust_pay
57 # was this supposed to do something?
60 # my($self,$payby) = @_;
61 # if ( defined($payby) ) {
62 # $self->setfield('payby', $payby);
64 # return $self->getfield('payby')
69 Payment information (payinfo) can be one of the following types:
71 Card Number, P.O., comp issuer (4-8 lowercase alphanumerics; think username) or prepayment identifier (see L<FS::prepay_credit>)
76 my($self,$payinfo) = @_;
77 if ( defined($payinfo) ) {
78 $self->setfield('payinfo', $payinfo); # This is okay since we are the 'setter'
79 $self->paymask($self->mask_payinfo());
81 $payinfo = $self->getfield('payinfo'); # This is okay since we are the 'getter'
88 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
93 my($self,$paycvv) = @_;
94 # This is only allowed in cust_main... Even then it really shouldn't be stored...
95 if ($self->table eq 'cust_main') {
96 if ( defined($paycvv) ) {
97 $self->setfield('paycvv', $paycvv); # This is okay since we are the 'setter'
99 $paycvv = $self->getfield('paycvv'); # This is okay since we are the 'getter'
103 # warn "This doesn't work for other tables besides cust_main
113 my($self,$paymask)=@_;
116 if ($paymask ne '') {
117 # I hate this little bit of magic... I don't expect it to cause a problem, but who knows...
118 # If the payinfo is passed in masked then ignore it and set it based on the payinfo
119 # The only guy that should call this in this way is... $self->payinfo
120 $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 generate
125 $paymask = $self->mask_payinfo();
139 This method converts the payment info (credit card, bank account, etc.) into a masked string.
146 my $payinfo = $self->payinfo;
147 my $payby = $self->payby;
148 # Check to see if it's encrypted...
149 if ($self->is_encrypted($payinfo)) {
153 if ($payby eq 'CARD' || $payby eq 'DCRD' || $payby eq 'MCRD') { # Credit Cards (Show first and last four)
154 $paymask = substr($payinfo,0,6). 'x'x(length($payinfo)-10). substr($payinfo,(length($payinfo)-4));
155 } elsif ($payby eq 'CHEK' ||
156 $payby eq 'DCHK' ) { # Checks (Show last 2 @ bank)
157 my( $account, $aba ) = split('@', $payinfo );
158 $paymask = 'x'x(length($account)-2). substr($account,(length($account)-2))."@".$aba;
159 } else { # Tie up loose ends
168 Checks payby and payinfo.
170 For Customers (cust_main):
171 'CARD' (credit card - automatic), 'DCRD' (credit card - on-demand),
172 'CHEK' (electronic check - automatic), 'DCHK' (electronic check - on-demand),
173 'LECB' (Phone bill billing), 'BILL' (billing), 'COMP' (free), or
174 'PREPAY' (special billing type: applies a credit - see L<FS::prepay_credit> and sets billing type to I<BILL>)
176 For Refunds (cust_refund):
177 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
178 'LECB' (Phone bill billing), 'BILL' (billing), 'CASH' (cash),
179 'WEST' (Western Union), 'MCRD' (Manual credit card), 'CBAK' (Chargeback), or 'COMP' (free)
181 For Payments (cust_pay):
182 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
183 'LECB' (phone bill billing), 'BILL' (billing), 'PREP' (prepaid card),
184 'CASH' (cash), 'WEST' (Western Union), or 'MCRD' (Manual credit card)
185 'COMP' (free) is depricated as a payment type in cust_pay
192 FS::payby->can_payby($self->table, $self->payby)
193 or return "Illegal payby";
195 if ( $self->payby eq 'CARD' ) {
196 my $payinfo = $self->payinfo;
198 $self->payinfo($payinfo);
199 if ( $self->payinfo ) {
200 $self->payinfo =~ /^(\d{13,16})$/
201 or return "Illegal (mistyped?) credit card number (payinfo)";
203 validate($self->payinfo) or return "Illegal credit card number";
204 return "Unknown card type" if cardtype($self->payinfo) eq "Unknown";
206 $self->payinfo('N/A');
209 my $error = $self->ut_textn('payinfo');
210 return $error if $error;
216 Have to add the future items...
220 L<FS::payby>, L<FS::Record>