diff options
author | Mark Wells <mark@freeside.biz> | 2013-01-29 16:28:26 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2013-01-30 12:09:29 -0800 |
commit | 61097b876e692dbf5571a17b9aa415949607085f (patch) | |
tree | aead5bab2124ce0aaca391a15de3deeaa383f867 /FS/FS | |
parent | 6bd91fa5feb41ea3294bdaee5fe1c1134f19c330 (diff) |
record and show batch payment status info, #21117
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/Schema.pm | 1 | ||||
-rw-r--r-- | FS/FS/cust_pay_batch.pm | 19 | ||||
-rw-r--r-- | FS/FS/pay_batch.pm | 26 | ||||
-rw-r--r-- | FS/FS/pay_batch/paymentech.pm | 23 |
4 files changed, 48 insertions, 21 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 70928a8..de3659a 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1695,6 +1695,7 @@ sub tables_hashref { 'payname', 'varchar', 'NULL', $char_d, '', '', 'amount', @money_type, '', '', 'status', 'varchar', 'NULL', $char_d, '', '', + 'error_message', 'varchar', 'NULL', $char_d, '', '', ], 'primary_key' => 'paybatchnum', 'unique' => [], diff --git a/FS/FS/cust_pay_batch.pm b/FS/FS/cust_pay_batch.pm index 9f2e9dd..4138436 100644 --- a/FS/FS/cust_pay_batch.pm +++ b/FS/FS/cust_pay_batch.pm @@ -9,7 +9,7 @@ use FS::payinfo_Mixin; use FS::cust_main; use FS::cust_bill; -@ISA = qw( FS::payinfo_Mixin FS::Record ); +@ISA = qw( FS::payinfo_Mixin FS::cust_main_Mixin FS::Record ); # 1 is mostly method/subroutine entry and options # 2 traces progress of some operations @@ -80,7 +80,9 @@ following fields are currently supported: =item country -=item status +=item status - 'Approved' or 'Declined' + +=item error_message - the error returned by the gateway if any =back @@ -289,19 +291,21 @@ sub retriable { ''; } -=item approve PAYBATCH +=item approve OPTIONS Approve this payment. This will replace the existing record with the same paybatchnum, set its status to 'Approved', and generate a payment record (L<FS::cust_pay>). This should only be called from the batch import process. +OPTIONS may contain "gatewaynum", "processor", "auth", and "order_number". + =cut sub approve { # to break up the Big Wall of Code that is import_results my $new = shift; - my $paybatch = shift; + my %opt = @_; my $paybatchnum = $new->paybatchnum; my $old = qsearchs('cust_pay_batch', { paybatchnum => $paybatchnum }) or return "paybatchnum $paybatchnum not found"; @@ -317,13 +321,17 @@ sub approve { my $cust_pay = new FS::cust_pay ( { 'custnum' => $new->custnum, 'payby' => $new->payby, - 'paybatch' => $paybatch, 'payinfo' => $new->payinfo || $old->payinfo, 'paid' => $new->paid, '_date' => $new->_date, 'usernum' => $new->usernum, 'batchnum' => $new->batchnum, + 'gatewaynum' => $opt{'gatewaynum'}, + 'processor' => $opt{'processor'}, + 'auth' => $opt{'auth'}, + 'order_number' => $opt{'order_number'} } ); + $error = $cust_pay->insert; if ( $error ) { return "error inserting payment for paybatchnum $paybatchnum: $error\n"; @@ -375,6 +383,7 @@ sub decline { } } # !$old->status $new->status('Declined'); + $new->error_message($reason); my $error = $new->replace($old); if ( $error ) { return "error updating status of paybatchnum $paybatchnum: $error\n"; diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm index 0274914..2a048a1 100644 --- a/FS/FS/pay_batch.pm +++ b/FS/FS/pay_batch.pm @@ -401,12 +401,12 @@ sub import_results { foreach ('paid', '_date', 'payinfo') { $new_cust_pay_batch->$_($hash{$_}) if $hash{$_}; } - $error = $new_cust_pay_batch->approve($hash{'paybatch'} || $self->batchnum); + $error = $new_cust_pay_batch->approve(%hash); $total += $hash{'paid'}; } elsif ( &{$declined_condition}(\%hash) ) { - $error = $new_cust_pay_batch->decline; + $error = $new_cust_pay_batch->decline($hash{'error_message'});; } @@ -572,8 +572,6 @@ sub import_from_gateway { my $payby; # CARD or CHEK my $error; - # follow realtime gateway practice here - # though eventually this stuff should go into separate fields... my $paybatch = $gateway->gatewaynum . '-' . $gateway->gateway_module . ':' . $item->authorization . ':' . $item->order_number; @@ -644,8 +642,11 @@ sub import_from_gateway { payby => $payby, invnum => $item->invoice_number, batchnum => $pay_batch->batchnum, - paybatch => $paybatch, payinfo => $payinfo, + gatewaynum => $gateway->gatewaynum, + processor => $gateway->gateway_module, + auth => $item->authorization, + order_number => $item->order_number, } ); $error ||= $cust_pay->insert; @@ -725,7 +726,12 @@ sub import_from_gateway { # approval status if ( $item->approved ) { # follow Billing_Realtime format for paybatch - $error = $cust_pay_batch->approve($paybatch); + $error = $cust_pay_batch->approve( + 'gatewaynum' => $gateway->gatewaynum, + 'processor' => $gateway->gateway_module, + 'auth' => $item->authorization, + 'order_number' => $item->order_number, + ); $total += $cust_pay_batch->paid; } else { @@ -829,6 +835,9 @@ sub try_to_resolve { } return $error if $error; } + } elsif ( @unresolved ) { + # auto resolve is not enabled, and we're not ready to resolve + return; } $self->set_status('R'); @@ -1028,7 +1037,6 @@ sub manual_approve { my $self = shift; my $date = time; my %opt = @_; - my $paybatch = $opt{'paybatch'} || $self->batchnum; my $usernum = $opt{'usernum'} || die "manual approval requires a usernum"; my $conf = FS::Conf->new; return 'manual batch approval disabled' @@ -1058,7 +1066,9 @@ sub manual_approve { '_date' => $date, 'usernum' => $usernum, }; - my $error = $new_cust_pay_batch->approve($paybatch); + my $error = $new_cust_pay_batch->approve(); + # there are no approval options here (authorization, order_number, etc.) + # because the transaction wasn't really approved if ( $error ) { $dbh->rollback; return 'paybatchnum '.$cust_pay_batch->paybatchnum.": $error"; diff --git a/FS/FS/pay_batch/paymentech.pm b/FS/FS/pay_batch/paymentech.pm index c75903d..47be4eb 100644 --- a/FS/FS/pay_batch/paymentech.pm +++ b/FS/FS/pay_batch/paymentech.pm @@ -23,7 +23,10 @@ my $gateway; '_date', 'approvalStatus', 'order_number', - 'authorization', + 'auth', + 'procStatus', + 'procStatusMessage', + 'respCodeMessage', ], xmlkeys => [ 'orderID', @@ -31,6 +34,9 @@ my $gateway; 'approvalStatus', 'txRefNum', 'authorizationCode', + 'procStatus', + 'procStatusMessage', + 'respCodeMessage', ], 'hook' => sub { if ( !$gateway ) { @@ -38,7 +44,7 @@ my $gateway; # as the batch config, if there is one. If not, leave # gateway out entirely. my $merchant = (FS::Conf->new->config('batchconfig-paymentech'))[2]; - my $g = qsearchs({ + $gateway = qsearchs({ 'table' => 'payment_gateway', 'addl_from' => ' JOIN payment_gateway_option USING (gatewaynum) ', 'hashref' => { disabled => '', @@ -46,18 +52,19 @@ my $gateway; optionvalue => $merchant, }, }); - $gateway = ($g ? $g->gatewaynum . '-' : '') . 'PaymenTech'; } my ($hash, $oldhash) = @_; + $hash->{'gatewaynum'} = $gateway->gatewaynum if $gateway; + $hash->{'processor'} = 'PaymenTech'; my ($mon, $day, $year, $hour, $min, $sec) = $hash->{'_date'} =~ /^(..)(..)(....)(..)(..)(..)$/; $hash->{'_date'} = timelocal($sec, $min, $hour, $day, $mon-1, $year); $hash->{'paid'} = $oldhash->{'amount'}; - $hash->{'paybatch'} = join(':', - $gateway, - $hash->{'authorization'}, - $hash->{'order_number'}, - ); + if ( $hash->{'procStatus'} == 0 ) { + $hash->{'error_message'} = $hash->{'respCodeMessage'}; + } else { + $hash->{'error_message'} = $hash->{'procStatusMessage'}; + } }, 'approved' => sub { my $hash = shift; $hash->{'approvalStatus'} |