X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_payby.pm;h=79a1468581a84d29b76627abe3c0bb4c287025f2;hb=461cf66878e2d63d0360184aeeebcbc0e45acfb9;hp=b1a7ddb56b974880a43dc6d8a2045ad98cb9a9cc;hpb=7b40e0e045368d350529d78208be0e6124f94b5a;p=freeside.git diff --git a/FS/FS/cust_payby.pm b/FS/FS/cust_payby.pm index b1a7ddb56..79a146858 100644 --- a/FS/FS/cust_payby.pm +++ b/FS/FS/cust_payby.pm @@ -2,9 +2,12 @@ package FS::cust_payby; use base qw( FS::payinfo_Mixin FS::cust_main_Mixin FS::Record ); use strict; +use Scalar::Util qw( blessed ); +use Digest::SHA qw( sha512_base64 ); use Business::CreditCard qw( validate cardtype ); use FS::UID qw( dbh ); use FS::Msgcat qw( gettext ); +use FS::Misc qw( card_types ); use FS::Record; #qw( qsearch qsearchs ); use FS::payby; use FS::cust_main; @@ -152,7 +155,8 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $error = $self->SUPER::insert; + my $error = $self->check_payinfo_cardtype + || $self->SUPER::insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -201,8 +205,7 @@ sub replace { ) ) { -warn $self->payinfo; -warn $old->payinfo; + $self->payinfo($old->payinfo); } elsif ( $self->payby =~ /^(CHEK|DCHK)$/ && $self->payinfo =~ /xx/ ) { @@ -227,6 +230,14 @@ warn $old->payinfo; || $old->payby =~ /^(CHEK|DCHK)$/ && $self->payby =~ /^(CHEK|DCHK)$/ ) && ( $old->payinfo eq $self->payinfo || $old->paymask eq $self->paymask ); + if ( $self->payby =~ /^(CARD|DCRD)$/ + && $old->payinfo ne $self->payinfo + && $old->paymask ne $self->paymask ) + { + my $error = $self->check_payinfo_cardtype; + return $error if $error; + } + local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; local $SIG{QUIT} = 'IGNORE'; @@ -482,6 +493,23 @@ sub check { $self->SUPER::check; } +sub check_payinfo_cardtype { + my $self = shift; + + my $payinfo = $self->payinfo; + $payinfo =~ s/\D//g; + + return '' if $payinfo =~ /^99\d{14}$/; #token + + my %bop_card_types = map { $_=>1 } values %{ card_types() }; + my $cardtype = cardtype($payinfo); + + return "$cardtype not accepted" unless $bop_card_types{$cardtype}; + + ''; + +} + sub _banned_pay_hashref { my $self = shift; @@ -499,6 +527,14 @@ sub _banned_pay_hashref { }; } +sub _new_banned_pay_hashref { + my $self = shift; + my $hr = $self->_banned_pay_hashref; + $hr->{payinfo_hash} = 'SHA512'; + $hr->{payinfo} = sha512_base64($hr->{payinfo}); + $hr; +} + =item paydate_mon_year Returns a two element list consisting of the paydate month and year. @@ -568,15 +604,20 @@ sub cgi_cust_payby_fields { payinfo1 payinfo2 payinfo3 paytype paystate payname_CHEK )]; } -=item cgi_hash_callback HASHREF +=item cgi_hash_callback HASHREF OLD Subroutine (not a class or object method). Processes a hash reference of web interface contet (transfers the data from pseudo-fields to real fields). +If OLD object is passed, also preserves locationnum, paystart_month, paystart_year, +payissue and payip. If the new field is blank but the old is not, the old field +will be preserved. + =cut sub cgi_hash_callback { my $hashref = shift; + my $old = shift; my %noauto = ( 'CARD' => 'DCRD', @@ -610,6 +651,14 @@ sub cgi_hash_callback { $hashref->{paydate}= $hashref->{paydate_month}. '-'. $hashref->{paydate_year}; + if ($old) { + foreach my $field ( qw(locationnum paystart_month paystart_year payissue payip) ) { + next if $hashref->{$field}; + next unless $old->get($field); + $hashref->{$field} = $old->get($field); + } + } + } =item search_sql