From 347dcab290bf68a8f9796484a28809e721e79493 Mon Sep 17 00:00:00 2001 From: senator Date: Fri, 11 Jun 2010 16:18:35 +0000 Subject: [PATCH] Improve the way information from payment card processors bubbles up to callers of open-ils.circ.money.payment This is done by replacing unneeded, weird data structures with ilsevents and filling those events' payloads with result data from the processor. git-svn-id: svn://svn.open-ils.org/ILS/trunk@16680 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/extras/ils_events.xml | 3 ++ .../OpenILS/Application/Circ/CreditCard.pm | 60 +++++++++------------- .../src/perlmods/OpenILS/Application/Circ/Money.pm | 29 +++++------ 3 files changed, 38 insertions(+), 54 deletions(-) diff --git a/Open-ILS/src/extras/ils_events.xml b/Open-ILS/src/extras/ils_events.xml index c26a6fc823..44dcdd7f63 100644 --- a/Open-ILS/src/extras/ils_events.xml +++ b/Open-ILS/src/extras/ils_events.xml @@ -768,6 +768,9 @@ No default credit processor is selected + + An invalid credit card number has been supplied. + The credit card processor has declined the transaction. diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm index 1475fc64c4..d2e4c0a43d 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm @@ -100,7 +100,7 @@ sub get_processor_settings { # description: optional # /, type => 'hash' } # ], -# return => { desc => 'Hash of status information', type =>'hash' } +# return => { desc => 'an ilsevent' } # } sub process_payment { @@ -221,15 +221,9 @@ sub dispatch { if (!validate($argshash->{cc})) { # Although it might help a troubleshooter, it's probably not a good # idea to put the credit card number in the log file. - $logger->warn("Credit card number invalid"); - - # The idea of returning a hashref with statusText and statusCode - # comes from an older version handle_authorizenet(), but I'm not - # sure it's the best thing to do, really. - return { - statusText => "Credit card number invalid", - statusCode => 500 - }; + $logger->info("Credit card number invalid"); + + return new OpenILS::Event("CREDIT_PROCESSOR_INVALID_CC_NUMBER"); } # cardtype() also comes from Business::CreditCard. It is not certain that @@ -257,38 +251,30 @@ sub dispatch { $transaction->content(prepare_bop_content($argshash, $patron, $cardtype)); $transaction->submit(); - # The data structures that we return based on success or failure are still - # basically from earlier code. These might should be improved/reduced. - if ($transaction->is_success()) { - $logger->info($argshash->{processor} . " payment succeeded"); + my $payload = { + "processor" => $argshash->{"processor"}, + "card_type" => $cardtype, + "server_response" => $transaction->server_response + }; - my $retval = { - statusText => "Transaction approved: " . $transaction->authorization, - processor => $argshash->{processor}, - cardType => $cardtype, - statusCode => 200, - approvalCode => $transaction->authorization, - server_response => $transaction->server_response - }; - - # These result fields may be important in PayPal xactions? Not sure. - foreach (qw/correlationid avs_code cvv2_code/) { - if ($transaction->can($_)) { - $retval->{$_} = $transaction->$_; - } - } - return $retval; + foreach (qw/authorization correlationid avs_code cvv2_code error_message/) { + # authorization should always be present for successes, and + # error_message should always be present for failures. The remaining + # field may be important in PayPal transacations? Not sure. + $payload->{$_} = $transaction->$_ if $transaction->can($_); } - else { + + my $event_name; + + if ($transaction->is_success()) { + $logger->info($argshash->{processor} . " payment succeeded"); + $event_name = "SUCCESS"; + } else { $logger->info($argshash->{processor} . " payment failed"); - return { - statusText => "Transaction declined: " . $transaction->error_message, - statusCode => 500, - errorMessage => $transaction->error_message, - server_response => $transaction->server_response - }; + $event_name = "CREDIT_PROCESSOR_DECLINED_TRANSACTION"; } + return new OpenILS::Event($event_name, "payload" => $payload); } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm index b9f130582c..10f357f289 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm @@ -250,28 +250,23 @@ sub make_payments { "zip" => $cc_args->{billing_zip}, }); - if (exists $response->{ilsevent}) { + if ($U->event_code($response)) { # non-success $logger->info( - "event response from process_payment(): " . - $response->{"textcode"} + "Credit card payment for user $user_id failed: " . + $response->{"textcode"} . " " . + $response->{"payload"}->{"error_message"} ); + return $response; - } - if ($response->{statusCode} != 200) { - $logger->info("Credit card payment for user $user_id " . - "failed with message: " . $response->{statusText}); - return OpenILS::Event->new( - 'CREDIT_PROCESSOR_DECLINED_TRANSACTION', - note => $response->{statusText} + } else { + $approval_code = $response->{"payload"}->{"authorization"}; + $cc_type = $response->{"payload"}->{"card_type"}; + $cc_processor = $response->{"payload"}->{"processor"}; + $logger->info( + "Credit card payment for user $user_id succeeded" ); } - $approval_code = $response->{approvalCode}; - $cc_type = $response->{cardType}; - $cc_processor = $response->{processor}; - $logger->info("Credit card payment processing for " . - "user $user_id succeeded"); - } - else { + } else { return OpenILS::Event->new( 'BAD_PARAMS', note => 'Need approval code' ) if not $cc_args->{approval_code}; -- 2.11.0