1 package FS::payinfo_Mixin;
4 use Business::CreditCard;
8 FS::payinfo_Mixin - Mixin class for records in tables that contain payinfo.
12 package FS::some_table;
14 @ISA = qw( FS::payinfo_Mixin FS::Record );
18 This is a mixin class for records that contain payinfo.
20 This class handles the following functions for payinfo...
22 Payment Mask (Generation and Storage)
23 Data Validation (parent checks need to be sure to call this)
24 Encryption - In the Future (Pull from Record.pm)
25 Bad Card Stuff - In the Future (Integrate Banned Pay)
26 Currency - In the Future
34 The following payment types (payby) are supported:
36 For Customers (cust_main):
37 'CARD' (credit card - automatic), 'DCRD' (credit card - on-demand),
38 'CHEK' (electronic check - automatic), 'DCHK' (electronic check - on-demand),
39 'LECB' (Phone bill billing), 'BILL' (billing), 'COMP' (free), or
40 'PREPAY' (special billing type: applies a credit - see L<FS::prepay_credit> and sets billing type to I<BILL>)
42 For Refunds (cust_refund):
43 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
44 'LECB' (Phone bill billing), 'BILL' (billing), 'CASH' (cash),
45 'WEST' (Western Union), 'MCRD' (Manual credit card), 'CBAK' Chargeback, or 'COMP' (free),
48 For Payments (cust_pay):
49 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
50 'LECB' (phone bill billing), 'BILL' (billing), 'PREP' (prepaid card),
51 'CASH' (cash), 'WEST' (Western Union), or 'MCRD' (Manual credit card)
52 'COMP' (free) is depricated as a payment type in cust_pay
57 my($self,$payby) = @_;
58 if ( defined($payby) ) {
59 $self->setfield('payby', $payby);
61 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
110 my($self,$paymask)=@_;
113 if ($paymask ne '') {
114 # I hate this little bit of magic... I don't expect it to cause a problem, but who knows...
115 # If the payinfo is passed in masked then ignore it and set it based on the payinfo
116 # The only guy that should call this in this way is... $self->payinfo
117 $self->setfield('paymask', $self->mask_payinfo());
119 $paymask=$self->getfield('paymask');
120 if (!defined($paymask) || $paymask eq '') {
121 # Generate it if it's blank - Note that we're not going to set it - just generate
122 $paymask = $self->mask_payinfo();
130 This method converts the payment info (credit card, bank account, etc.) into a masked string.
137 my $payinfo = $self->payinfo;
138 my $payby = $self->payby;
139 # Check to see if it's encrypted...
140 if ($self->is_encrypted($payinfo)) {
144 if ($payby eq 'CARD' || $payby eq 'DCRD' || $payby eq 'MCRD') { # Credit Cards (Show first and last four)
145 $paymask = substr($payinfo,0,4). 'x'x(length($payinfo)-8). substr($payinfo,(length($payinfo)-4));
146 } elsif ($payby eq 'CHEK' ||
147 $payby eq 'DCHK' ) { # Checks (Show last 2 @ bank)
148 my( $account, $aba ) = split('@', $payinfo );
149 $paymask = 'x'x(length($account)-2). substr($account,(length($account)-2))."@".$aba;
150 } else { # Tie up loose ends
166 For Customers (cust_main):
167 'CARD' (credit card - automatic), 'DCRD' (credit card - on-demand),
168 'CHEK' (electronic check - automatic), 'DCHK' (electronic check - on-demand),
169 'LECB' (Phone bill billing), 'BILL' (billing), 'COMP' (free), or
170 'PREPAY' (special billing type: applies a credit - see L<FS::prepay_credit> and sets billing type to I<BILL>)
172 For Refunds (cust_refund):
173 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
174 'LECB' (Phone bill billing), 'BILL' (billing), 'CASH' (cash),
175 'WEST' (Western Union), 'MCRD' (Manual credit card), 'CBAK' (Chargeback), or 'COMP' (free)
177 For Payments (cust_pay):
178 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
179 'LECB' (phone bill billing), 'BILL' (billing), 'PREP' (prepaid card),
180 'CASH' (cash), 'WEST' (Western Union), or 'MCRD' (Manual credit card)
181 'COMP' (free) is depricated as a payment type in cust_pay
192 # Make sure it's a valid payby
193 $self->payby =~ /^(CARD|DCRD|CHEK|DCHK|LECB|BILL|COMP|PREPAY|CASH|WEST|MCRD|PREP|CBAK)$/
194 or return "Illegal payby (overall payinfo_check)";
198 # Okay some aren't valid depending on table
199 if ($self->table eq 'cust_main') {
200 if ($self->payby =~ /^(CASH|WEST|MCRD|PREP|CBAK)$/) {
201 return "Illegal payby (cust_main)";
203 } elsif ($self->table eq 'cust_refund') {
204 if ($self->payby =~ /^(DCRD|DCHK|PREPAY|PREP)$/) {
205 return "Illegal payby (cust_refund)";
207 } elsif ($self->table eq 'cust_pay') {
208 if ($self->payby =~ /^(DCRD|DCHK|PREPAY|CBAK)$/) {
209 return "Illegal payby (cust_pay)";
213 if ( $self->payby eq 'CARD' ) {
214 my $payinfo = $self->payinfo;
216 $self->payinfo($payinfo);
217 if ( $self->payinfo ) {
218 $self->payinfo =~ /^(\d{13,16})$/
219 or return "Illegal (mistyped?) credit card number (payinfo)";
221 Business::CreditCard::validate($self->payinfo) or return "Illegal credit card number";
222 return "Unknown card type" if Business::CreditCard::cardtype($self->payinfo) eq "Unknown";
224 $self->payinfo('N/A');
227 my $error = $self->ut_textn('payinfo');
228 return $error if $error;
236 Have to add the future items...