X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpayinfo_Mixin.pm;h=41768189e0e9cf50e86651c9d3fc96b7ee69a77d;hb=3cbdd85a96348a287623e3b97c937c7749e99392;hp=e14c5895fadda5e56d6130e2682de32a8491211e;hpb=fbccadc20ceb30d90ef5ab8a2e135834a1aded31;p=freeside.git diff --git a/FS/FS/payinfo_Mixin.pm b/FS/FS/payinfo_Mixin.pm index e14c5895f..41768189e 100644 --- a/FS/FS/payinfo_Mixin.pm +++ b/FS/FS/payinfo_Mixin.pm @@ -4,6 +4,8 @@ use strict; use Business::CreditCard; use FS::payby; use FS::Record qw(qsearch); +use FS::UID qw(driver_name); +use Time::Local qw(timelocal); use vars qw($ignore_masked_payinfo); @@ -38,14 +40,15 @@ For Customers (cust_main): For Refunds (cust_refund): 'CARD' (credit cards), 'CHEK' (electronic check/ACH), 'LECB' (Phone bill billing), 'BILL' (billing), 'CASH' (cash), -'WEST' (Western Union), 'MCRD' (Manual credit card), 'CBAK' Chargeback, or 'COMP' (free) +'WEST' (Western Union), 'MCRD' (Manual credit card), 'MCHK' (Manual electronic +check), 'CBAK' Chargeback, or 'COMP' (free) For Payments (cust_pay): 'CARD' (credit cards), 'CHEK' (electronic check/ACH), 'LECB' (phone bill billing), 'BILL' (billing), 'PREP' (prepaid card), -'CASH' (cash), 'WEST' (Western Union), 'MCRD' (Manual credit card), -'PPAL' (PayPal) +'CASH' (cash), 'WEST' (Western Union), 'MCRD' (Manual credit card), 'MCHK' +(Manual electronic check), 'PPAL' (PayPal) 'COMP' (free) is depricated as a payment type in cust_pay =cut @@ -129,7 +132,11 @@ sub mask_payinfo { return 'N/A (tokenized)'; #? } else { # if not, mask it... - if ($payby eq 'CARD' || $payby eq 'DCRD' || $payby eq 'MCRD') { + if ($payby eq 'CARD' || $payby eq 'DCRD') { + #|| $payby eq 'MCRD') { + #MCRD isn't a card in payinfo, + #its a record of an _offline_ + #card # Credit Cards @@ -177,23 +184,6 @@ sub mask_payinfo { Checks payby and payinfo. -For Customers (cust_main): -'CARD' (credit card - automatic), 'DCRD' (credit card - on-demand), -'CHEK' (electronic check - automatic), 'DCHK' (electronic check - on-demand), -'LECB' (Phone bill billing), 'BILL' (billing), 'COMP' (free), or -'PREPAY' (special billing type: applies a credit - see L and sets billing type to I) - -For Refunds (cust_refund): -'CARD' (credit cards), 'CHEK' (electronic check/ACH), -'LECB' (Phone bill billing), 'BILL' (billing), 'CASH' (cash), -'WEST' (Western Union), 'MCRD' (Manual credit card), 'CBAK' (Chargeback), or 'COMP' (free) - -For Payments (cust_pay): -'CARD' (credit cards), 'CHEK' (electronic check/ACH), -'LECB' (phone bill billing), 'BILL' (billing), 'PREP' (prepaid card), -'CASH' (cash), 'WEST' (Western Union), or 'MCRD' (Manual credit card) -'COMP' (free) is depricated as a payment type in cust_pay - =cut sub payinfo_check { @@ -251,7 +241,11 @@ sub payby_payinfo_pretty { my $locale = shift; my $lh = FS::L10N->get_handle($locale); if ( $self->payby eq 'CARD' ) { - $lh->maketext('Card #') . $self->paymask; + if ($self->paymask =~ /tokenized/) { + $lh->maketext('Tokenized Card'); + } else { + $lh->maketext('Card #') . $self->paymask; + } } elsif ( $self->payby eq 'CHEK' ) { #false laziness w/view/cust_main/payment_history.html::translate_payinfo @@ -276,6 +270,8 @@ sub payby_payinfo_pretty { $lh->maketext('Western Union'); } elsif ( $self->payby eq 'MCRD' ) { $lh->maketext('Manual credit card'); + } elsif ( $self->payby eq 'MCHK' ) { + $lh->maketext('Manual electronic check'); } elsif ( $self->payby eq 'EDI' ) { $lh->maketext('EDI') . ' ' . $self->paymask; } elsif ( $self->payby eq 'PPAL' ) { @@ -336,6 +332,78 @@ sub display_status { } } +=item paydate_monthyear + +Returns a two-element list consisting of the month and year of this customer's +paydate (credit card expiration date for CARD customers) + +=cut + +sub paydate_monthyear { + my $self = shift; + if ( $self->paydate =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #Pg date format + ( $2, $1 ); + } elsif ( $self->paydate =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) { + ( $1, $3 ); + } else { + ('', ''); + } +} + +=item paydate_epoch + +Returns the exact time in seconds corresponding to the payment method +expiration date. For CARD/DCRD customers this is the end of the month; +for others (COMP is the only other payby that uses paydate) it's the start. +Returns 0 if the paydate is empty or set to the far future. + +=cut + +sub paydate_epoch { + my $self = shift; + my ($month, $year) = $self->paydate_monthyear; + return 0 if !$year or $year >= 2037; + if ( $self->payby eq 'CARD' or $self->payby eq 'DCRD' ) { + $month++; + if ( $month == 13 ) { + $month = 1; + $year++; + } + return timelocal(0,0,0,1,$month-1,$year) - 1; + } + else { + return timelocal(0,0,0,1,$month-1,$year); + } +} + +=item paydate_epoch_sql + +Class method. Returns an SQL expression to obtain the payment expiration date +as a number of seconds. + +=cut + +# Special expiration date behavior for non-CARD/DCRD customers has been +# carefully preserved. Do we really use that? +sub paydate_epoch_sql { + my $class = shift; + my $table = $class->table; + my ($case1, $case2); + if ( driver_name eq 'Pg' ) { + $case1 = "EXTRACT( EPOCH FROM CAST( $table.paydate AS TIMESTAMP ) + INTERVAL '1 month') - 1"; + $case2 = "EXTRACT( EPOCH FROM CAST( $table.paydate AS TIMESTAMP ) )"; + } + elsif ( lc(driver_name) eq 'mysql' ) { + $case1 = "UNIX_TIMESTAMP( DATE_ADD( CAST( $table.paydate AS DATETIME ), INTERVAL 1 month ) ) - 1"; + $case2 = "UNIX_TIMESTAMP( CAST( $table.paydate AS DATETIME ) )"; + } + else { return '' } + return "CASE WHEN $table.payby IN('CARD','DCRD') + THEN ($case1) + ELSE ($case2) + END" +} + =back =head1 BUGS