X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpayinfo_Mixin.pm;h=9879a3abd2604000cad8f58254709b153280b16d;hb=fed12e8214a8a951377961ccbe7a09171b1e38c2;hp=84264c966ff37358a46e9f09c9b370a15d35cf17;hpb=970dfae19db81ed3afdd9f7e15637907f84d5341;p=freeside.git diff --git a/FS/FS/payinfo_Mixin.pm b/FS/FS/payinfo_Mixin.pm index 84264c966..9879a3abd 100644 --- a/FS/FS/payinfo_Mixin.pm +++ b/FS/FS/payinfo_Mixin.pm @@ -3,6 +3,9 @@ package FS::payinfo_Mixin; use strict; use Business::CreditCard; use FS::payby; +use FS::Record qw(qsearch); + +use vars qw($ignore_masked_payinfo); =head1 NAME @@ -165,7 +168,8 @@ sub mask_payinfo { # Checks (Show last 2 @ bank) my( $account, $aba ) = split('@', $payinfo ); return 'x'x(length($account)-2). - substr($account,(length($account)-2))."@".$aba; + substr($account,(length($account)-2)). + ( length($aba) ? "@".$aba : ''); } else { # Tie up loose ends return $payinfo; @@ -205,17 +209,21 @@ sub payinfo_check { if ( $self->payby eq 'CARD' && ! $self->is_encrypted($self->payinfo) ) { my $payinfo = $self->payinfo; - $payinfo =~ s/\D//g; - $self->payinfo($payinfo); - if ( $self->payinfo ) { - $self->payinfo =~ /^(\d{13,16}|\d{8,9})$/ - or return "Illegal (mistyped?) credit card number (payinfo)"; - $self->payinfo($1); - validate($self->payinfo) or return "Illegal credit card number"; - return "Unknown card type" if $self->payinfo !~ /^99\d{14}$/ #token - && cardtype($self->payinfo) eq "Unknown"; + if ( $ignore_masked_payinfo and $self->mask_payinfo eq $self->payinfo ) { + # allow it } else { - $self->payinfo('N/A'); #??? + $payinfo =~ s/\D//g; + $self->payinfo($payinfo); + if ( $self->payinfo ) { + $self->payinfo =~ /^(\d{13,16}|\d{8,9})$/ + or return "Illegal (mistyped?) credit card number (payinfo)"; + $self->payinfo($1); + validate($self->payinfo) or return "Illegal credit card number"; + return "Unknown card type" if $self->payinfo !~ /^99\d{14}$/ #token + && cardtype($self->payinfo) eq "Unknown"; + } else { + $self->payinfo('N/A'); #??? + } } } else { if ( $self->is_encrypted($self->payinfo) ) { @@ -228,8 +236,6 @@ sub payinfo_check { } } - ''; - } =item payby_payinfo_pretty @@ -266,6 +272,30 @@ sub payby_payinfo_pretty { } } +=item payinfo_used [ PAYINFO ] + +Returns 1 if there's an existing payment using this payinfo. This can be +used to set the 'recurring payment' flag required by some processors. + +=cut + +sub payinfo_used { + my $self = shift; + my $payinfo = shift || $self->payinfo; + my %hash = ( + 'custnum' => $self->custnum, + 'payby' => 'CARD', + ); + + return 1 + if qsearch('cust_pay', { %hash, 'payinfo' => $payinfo } ) + || qsearch('cust_pay', + { %hash, 'paymask' => $self->mask_payinfo('CARD', $payinfo) } ) + ; + + return 0; +} + =back =head1 BUGS