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.
27 The following payment types (payby) are supported:
29 For Customers (cust_main):
30 'CARD' (credit card - automatic), 'DCRD' (credit card - on-demand),
31 'CHEK' (electronic check - automatic), 'DCHK' (electronic check - on-demand),
32 'LECB' (Phone bill billing), 'BILL' (billing), 'COMP' (free), or
33 'PREPAY' (special billing type: applies a credit and sets billing type to I<BILL> - see L<FS::prepay_credit>)
35 For Refunds (cust_refund):
36 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
37 'LECB' (Phone bill billing), 'BILL' (billing), 'CASH' (cash),
38 'WEST' (Western Union), 'MCRD' (Manual credit card), 'CBAK' Chargeback, or 'COMP' (free)
41 For Payments (cust_pay):
42 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
43 'LECB' (phone bill billing), 'BILL' (billing), 'PREP' (prepaid card),
44 'CASH' (cash), 'WEST' (Western Union), or 'MCRD' (Manual credit card)
45 'COMP' (free) is depricated as a payment type in cust_pay
49 # was this supposed to do something?
52 # my($self,$payby) = @_;
53 # if ( defined($payby) ) {
54 # $self->setfield('payby', $payby);
56 # return $self->getfield('payby')
61 Payment information (payinfo) can be one of the following types:
63 Card Number, P.O., comp issuer (4-8 lowercase alphanumerics; think username) or prepayment identifier (see L<FS::prepay_credit>)
68 my($self,$payinfo) = @_;
70 if ( defined($payinfo) ) {
71 $self->setfield('payinfo', $payinfo);
72 $self->paymask($self->mask_payinfo) unless $payinfo =~ /^99\d{14}$/; #token
74 $self->getfield('payinfo');
80 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
85 my($self,$paycvv) = @_;
86 # This is only allowed in cust_main... Even then it really shouldn't be stored...
87 if ($self->table eq 'cust_main') {
88 if ( defined($paycvv) ) {
89 $self->setfield('paycvv', $paycvv); # This is okay since we are the 'setter'
91 $paycvv = $self->getfield('paycvv'); # This is okay since we are the 'getter'
95 # warn "This doesn't work for other tables besides cust_main
105 my($self, $paymask) = @_;
107 if ( defined($paymask) ) {
108 $self->setfield('paymask', $paymask);
110 $self->getfield('paymask') || $self->mask_payinfo;
120 =item mask_payinfo [ PAYBY, PAYINFO ]
122 This method converts the payment info (credit card, bank account, etc.) into a
125 Optionally, an arbitrary payby and payinfo can be passed.
131 my $payby = scalar(@_) ? shift : $self->payby;
132 my $payinfo = scalar(@_) ? shift : $self->payinfo;
134 # Check to see if it's encrypted...
136 if ( $self->is_encrypted($payinfo) ) {
138 } elsif ( $payinfo =~ /^99\d{14}$/ || $payinfo eq 'N/A' ) { #token
139 $paymask = 'N/A (tokenized)'; #?
142 if ($payby eq 'CARD' || $payby eq 'DCRD' || $payby eq 'MCRD') {
144 my $conf = new FS::Conf;
145 my $mask_method = $conf->config('card_masking_method') || 'first6last4';
146 $mask_method =~ /^first(\d+)last(\d+)$/
147 or die "can't parse card_masking_method $mask_method";
148 my($first, $last) = ($1, $2);
150 $paymask = substr($payinfo,0,$first).
151 'x'x(length($payinfo)-$first-$last).
152 substr($payinfo,(length($payinfo)-$last));
153 } elsif ($payby eq 'CHEK' || $payby eq 'DCHK' ) {
154 # Checks (Show last 2 @ bank)
155 my( $account, $aba ) = split('@', $payinfo );
156 $paymask = 'x'x(length($account)-2).
157 substr($account,(length($account)-2))."@".$aba;
158 } else { # Tie up loose ends
167 Checks payby and payinfo.
169 For Customers (cust_main):
170 'CARD' (credit card - automatic), 'DCRD' (credit card - on-demand),
171 'CHEK' (electronic check - automatic), 'DCHK' (electronic check - on-demand),
172 'LECB' (Phone bill billing), 'BILL' (billing), 'COMP' (free), or
173 'PREPAY' (special billing type: applies a credit - see L<FS::prepay_credit> and sets billing type to I<BILL>)
175 For Refunds (cust_refund):
176 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
177 'LECB' (Phone bill billing), 'BILL' (billing), 'CASH' (cash),
178 'WEST' (Western Union), 'MCRD' (Manual credit card), 'CBAK' (Chargeback), or 'COMP' (free)
180 For Payments (cust_pay):
181 'CARD' (credit cards), 'CHEK' (electronic check/ACH),
182 'LECB' (phone bill billing), 'BILL' (billing), 'PREP' (prepaid card),
183 'CASH' (cash), 'WEST' (Western Union), or 'MCRD' (Manual credit card)
184 'COMP' (free) is depricated as a payment type in cust_pay
191 FS::payby->can_payby($self->table, $self->payby)
192 or return "Illegal payby: ". $self->payby;
194 if ( $self->payby eq 'CARD' && ! $self->is_encrypted($self->payinfo) ) {
195 my $payinfo = $self->payinfo;
197 $self->payinfo($payinfo);
198 if ( $self->payinfo ) {
199 $self->payinfo =~ /^(\d{13,16})$/
200 or return "Illegal (mistyped?) credit card number (payinfo)";
202 validate($self->payinfo) or return "Illegal credit card number";
203 return "Unknown card type" if $self->payinfo !~ /^99\d{14}$/ #token
204 && cardtype($self->payinfo) eq "Unknown";
206 $self->payinfo('N/A'); #???
209 if ( $self->is_encrypted($self->payinfo) ) {
210 #something better? all it would cause is a decryption error anyway?
211 my $error = $self->ut_anything('payinfo');
212 return $error if $error;
214 my $error = $self->ut_textn('payinfo');
215 return $error if $error;
223 =item payby_payinfo_pretty
225 Returns payment method and information (suitably masked, if applicable) as
226 a human-readable string, such as:
228 Card #54xxxxxxxxxxxx32
236 sub payby_payinfo_pretty {
238 if ( $self->payby eq 'CARD' ) {
239 'Card #'. $self->paymask;
240 } elsif ( $self->payby eq 'CHEK' ) {
241 'E-check acct#'. $self->payinfo;
242 } elsif ( $self->payby eq 'BILL' ) {
243 'Check #'. $self->payinfo;
244 } elsif ( $self->payby eq 'PREP' ) {
245 'Prepaid card #'. $self->payinfo;
246 } elsif ( $self->payby eq 'CASH' ) {
247 'Cash '. $self->payinfo;
248 } elsif ( $self->payby eq 'WEST' ) {
249 'Western Union'; #. $self->payinfo;
250 } elsif ( $self->payby eq 'MCRD' ) {
251 'Manual credit card'; #. $self->payinfo;
253 $self->payby. ' '. $self->payinfo;
263 L<FS::payby>, L<FS::Record>