diff options
author | Ivan Kohler <ivan@freeside.biz> | 2016-01-29 18:26:43 -0800 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2016-01-29 18:26:43 -0800 |
commit | 5d089cbe4980f7c9c25b83e164099b22bc59eead (patch) | |
tree | 9c1668cb5003e706b7f2f61ab8c54c9795576572 /FS | |
parent | 9db332d80967969856c5b5fe8b6ac91304734b04 (diff) |
Use any card on file when making a payment, RT#23741
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/cust_main.pm | 82 | ||||
-rw-r--r-- | FS/FS/cust_payby.pm | 33 |
2 files changed, 94 insertions, 21 deletions
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 9e0db2903..8e0984882 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -4435,8 +4435,10 @@ sub payment_history { Saves a new cust_payby for this customer, replacing an existing entry only in select circumstances. Does not validate input. -If auto is specified, marks this as the customer's primary method (weight 1) -and changes existing primary methods for that payby to secondary methods (weight 2.) +If auto is specified, marks this as the customer's primary method, or the +specified weight. Existing payment methods have their weight incremented as +appropriate. + If bill_location is specified with auto, also sets location in cust_main. Will not insert complete duplicates of existing records, or records in which the @@ -4448,39 +4450,77 @@ blanks when replacing. Accepts the following named parameters: -payment_payby - either CARD or CHEK +=over 4 + +=item payment_payby + +either CARD or CHEK + +=item auto + +save as an automatic payment type (CARD/CHEK if true, DCRD/DCHK if false) + +=item weight + +optional, set higher than 1 for secondary, etc. + +=item payinfo + +required + +=item paymask + +optional, but should be specified for anything that might be tokenized, will be preserved when replacing + +=item payname + +required + +=item payip + +optional, will be preserved when replacing + +=item paydate + +CARD only, required + +=item bill_location -auto - save as an automatic payment type (CARD/CHEK if true, DCRD/DCHK if false) +CARD only, required, FS::cust_location object -payinfo - required +=item paystart_month + +CARD only, optional, will be preserved when replacing -paymask - optional, but should be specified for anything that might be tokenized, will be preserved when replacing +=item paystart_year -payname - required +CARD only, optional, will be preserved when replacing -payip - optional, will be preserved when replacing +=item payissue -paydate - CARD only, required +CARD only, optional, will be preserved when replacing -bill_location - CARD only, required, FS::cust_location object +=item paycvv -paystart_month - CARD only, optional, will be preserved when replacing +CARD only, only used if conf cvv-save is set appropriately -paystart_year - CARD only, optional, will be preserved when replacing +=item paytype -payissue - CARD only, optional, will be preserved when replacing +CHEK only -paycvv - CARD only, only used if conf cvv-save is set appropriately +=item paystate -paytype - CHEK only +CHEK only -paystate - CHEK only +=back =cut #The code for this option is in place, but it's not currently used # -# replace - existing cust_payby object to be replaced (must match custnum) +# =item replace +# +# existing cust_payby object to be replaced (must match custnum) # stateid/stateid_state/ss are not currently supported in cust_payby, # might not even work properly in 4.x, but will need to work here if ever added @@ -4511,8 +4551,7 @@ sub save_cust_payby { @check_existing = qw( CHEK DCHK ); } - # every automatic payment type added here will be marked primary - $new->set( 'weight' => $opt{'auto'} ? 1 : '' ); + $new->set( 'weight' => $opt{'auto'} ? $opt{'weight'} : '' ); # basic fields $new->payinfo($opt{'payinfo'}); # sets default paymask, but not if it's already tokenized @@ -4606,7 +4645,7 @@ PAYBYLOOP: # if we got this far, we're definitely replacing $old = $cust_payby; last PAYBYLOOP; - } + } #PAYBYLOOP } if ($old) { @@ -4649,7 +4688,8 @@ PAYBYLOOP: last unless $cust_payby->payby !~ /^D/; last if $cust_payby->weight > 1; next if $new->custpaybynum eq $cust_payby->custpaybynum; - $cust_payby->set( 'weight' => 2 ); + next if $cust_payby->weight < ($opt{'weight'} || 1); + $cust_payby->weight( $cust_payby->weight + 1 ); my $error = $cust_payby->replace; if ( $error ) { $dbh->rollback if $oldAutoCommit; diff --git a/FS/FS/cust_payby.pm b/FS/FS/cust_payby.pm index 9111fdff1..a68624229 100644 --- a/FS/FS/cust_payby.pm +++ b/FS/FS/cust_payby.pm @@ -560,6 +560,39 @@ sub paydate_mon_year { } +=item label + +Returns a one line text label for this payment type. + +=cut + +my %weight = ( + 1 => 'Primary', + 2 => 'Secondary', + 3 => 'Tertiary', + 4 => 'Fourth', + 5 => 'Fifth', + 6 => 'Sixth', + 7 => 'Seventh', +); + +sub label { + my $self = shift; + + my $name = $self->payby =~ /^(CARD|DCRD)$/ + && cardtype($self->paymask) || FS::payby->shortname($self->payby); + + ( $self->payby =~ /^(CARD|CHEK)$/ ? $weight{$self->weight}. ' automatic ' + : 'Manual ' + ). + "$name: ". $self->paymask. + ( $self->payby =~ /^(CARD|DCRD)$/ + ? ' Exp '. join('/', $self->paydate_mon_year) + : '' + ); + +} + =item realtime_bop =cut |